update of old PL/SQL PLpgSQL and SQLPL patch based on current version

see [linguist] add support for oracle PLSQL (#1003)
This commit is contained in:
David Pyke Le Brun
2015-02-06 13:36:40 +00:00
parent 6d770ab68f
commit 3e54d6651c
22 changed files with 1213 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
create procedure check_reorg_tables (in v_schema varchar(128), out v_reorg_counter integer)
begin
declare loc result_set_locator varying;
declare schema_out varchar(128);
declare table_out varchar(128);
declare card_out integer;
declare overflow_out integer;
declare npages_out integer;
declare fpages_out integer;
declare active_blocks_out integer;
declare tsize_out integer;
declare f1_out integer;
declare f2_out integer;
declare f3_out integer;
declare reorg_out varchar(3);
declare cursor_end smallint default 0;
declare continue handler for NOT FOUND
set cursor_end = 1;
set v_reorg_counter = 0;
call reorgchk_tb_stats('S', v_schema);
associate result set locator(loc) with procedure reorgchk_tb_stats;
allocate mycursor cursor for result set loc;
open mycursor;
repeat
fetch from mycursor into schema_out, table_out, card_out, overflow_out, npages_out, fpages_out, active_blocks_out, tsize_out, f1_out, f2_out, f3_out, reorg_out;
if reorg_out <> '---' then
set v_reorg_counter = v_reorg_counter + 1;
end if;
until cursor_end = 1
end repeat;
close mycursor;
end!

View File

@@ -0,0 +1,30 @@
DROP FUNCTION COMM_AMOUNT;
CREATE FUNCTION COMM_AMOUNT(SALARY DEC(9,2))
RETURNS DEC(9,2)
LANGUAGE SQL READS SQL DATA
BEGIN ATOMIC
DECLARE REMAINDER DEC(9,2) DEFAULT 0.0;--
DECLARE COMM_PAID DEC(9,2) DEFAULT 0.0;--
DECLARE COMM_INCR INT DEFAULT 1;--
DECLARE MAX_COMM DEC(9,2) DEFAULT 0.0;--
IF (SALARY <= 0) THEN
SIGNAL SQLSTATE '75000'
SET MESSAGE_TEXT = 'Bad Salary';--
END IF;--
SET REMAINDER = SALARY;--
L1: WHILE REMAINDER > 0.0 DO
SET COMM_PAID = COMM_PAID + (COMM_INCR * 500.00);--
SET REMAINDER = REMAINDER-(COMM_INCR * 5000.00);--
SET COMM_INCR = COMM_INCR + 1;--
END WHILE L1;--
SET MAX_COMM =
(SELECT SUM(SALARY)/100.00 FROM EMPLOYEE);--
IF (COMM_PAID > MAX_COMM) THEN
SET COMM_PAID = MAX_COMM;--
END IF;--
RETURN COMM_PAID;--
END;

View File

@@ -0,0 +1,13 @@
DROP TABLE TDEPT;
CREATE TABLE TDEPT (DEPTNO CHAR(4));
--#SET TERMINATOR @
BEGIN ATOMIC
DECLARE COUNT INT DEFAULT 5;
WHILE COUNT > 0 DO
INSERT INTO TDEPT VALUES 'F'||
RTRIM(CHAR(COUNT));
SET COUNT = COUNT - 1;
END WHILE;
END@

View File

@@ -0,0 +1,18 @@
create procedure runstats (out nr_tables integer, out nr_ok integer)
begin
declare SQLCODE integer;
declare stmt varchar(100);
set nr_tables = 0;
set nr_ok = 0;
for line as select tabschema, tabname from syscat.tables where type='T' and tabschema='SPODEN'
do
set nr_tables = nr_tables + 1;
set stmt = 'CALL SYSPROC.ADMIN_CMD (RUNSTATS ON TABLE ' concat rtrim(line.tabschema) concat '.' concat line.tabname concat ')';
execute immediate stmt;
if SQLCODE = 0 then
set nr_ok = nr_ok + 1;
end if;
end for;
end!

View File

@@ -0,0 +1,9 @@
create trigger CHECK_HIREDATE
no cascade before insert on EMPLOYEE
referencing new as N
for each row mode db2sql
if n.hiredate > current date
then
signal SQLSTATE '75000'
set MESSAGE_TEXT = 'Hire date must be in the past';
end if!