PL/SQL 存储过程怎么使用临时表
包括定义和使用。
因为我定义临时表以后,使用的过程中,始终报错说表没定义。
[解决办法]
CREATE GLOBAL TEMPORARY TABLE temp_1 (a INT);
CREATE OR REPLACE PROCEDURE p_test IS
l_i INT;
BEGIN
INSERT INTO temp_1 VALUES(2);
SELECT COUNT(*) INTO l_i FROM temp_1;
dbms_output.put_line(l_i);
END;
/
BEGIN
p_test;
END;
/
输出:
1
/--给个例子,试一下:create table SSS( ID NUMBER, VALUE1 NUMBER)insert into sss values(1,2);CREATE OR REPLACE PROCEDURE BBBB(PO_RESULT OUT SYS_REFCURSOR) ISBEGIN execute immediate 'CREATE GLOBAL TEMPORARY TABLE AAA (NUM VARCHAR2(10),QTY INTEGER) ON COMMIT DELETE ROWS '; execute immediate 'insert into AAA SELECT * FROM sss'; OPEN PO_RESULT FOR 'select * from AAA';END BBBB;
[解决办法]