mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
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:
39
samples/SQLPL/check_reorg.sql
Normal file
39
samples/SQLPL/check_reorg.sql
Normal 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!
|
||||
30
samples/SQLPL/comm_amount.db2
Normal file
30
samples/SQLPL/comm_amount.db2
Normal 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;
|
||||
13
samples/SQLPL/drop_table.db2
Normal file
13
samples/SQLPL/drop_table.db2
Normal 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@
|
||||
18
samples/SQLPL/runstats.sql
Normal file
18
samples/SQLPL/runstats.sql
Normal 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!
|
||||
9
samples/SQLPL/trigger.sql
Normal file
9
samples/SQLPL/trigger.sql
Normal 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!
|
||||
Reference in New Issue
Block a user