CREATE OR REPLACE PROCEDURE SP_HSA_Get_Income0421_TEST (
DATA1 OUT SYS_REFCURSOR) IS
The BEGIN
DECLARE V_STR VARCHAR2 (4000);
TABLECOUNT NUMBER;
TEMP_COUNT NUMBER;
V_TEMP_TABLENAME_01 VARCHAR (20);
V_TEMP_TABLENAME_02 VARCHAR (20);
V_STR_CLOB clob.
V_STR_01 VARCHAR2 (4000);
The BEGIN
V_TEMP_TABLENAME_01:='CT_' | | SUBSTR (SYS_GUID (), 1, 8).
SELECT COUNT (1) INTO TABLECOUNT FROM USER_TABLES WHERE TABLE_NAME=V_TEMP_TABLENAME_01;
IF TABLECOUNT> 0 THEN
V_STR:='TRUNCATE TABLE' | | V_TEMP_TABLENAME_01;
The EXECUTE IMMEDIATE V_STR;
V_STR:='DROP TABLE' | | V_TEMP_TABLENAME_01;
The EXECUTE IMMEDIATE V_STR;
END the IF;
The EXECUTE IMMEDIATE '
The CREATE GLOBAL TEMPORARY TABLE '| | V_TEMP_TABLENAME_01 | |' ON the COMMIT PRESERVE ROWS AS
SELECT 1 AS AA, 2 AS BB FROM DUAL ';
V_STR_01:='SELECT * FROM' | | V_TEMP_TABLENAME_01;
The OPEN DATA1 FOR V_STR_01;
SELECT COUNT (1) INTO TABLECOUNT FROM USER_TABLES WHERE TABLE_NAME=V_TEMP_TABLENAME_01;
IF TABLECOUNT> 0 THEN
V_STR:='TRUNCATE TABLE' | | V_TEMP_TABLENAME_01;
The EXECUTE IMMEDIATE V_STR;
V_STR:='DROP TABLE' | | V_TEMP_TABLENAME_01;
The EXECUTE IMMEDIATE V_STR;
END the IF;
END;
END SP_HSA_Get_Income0421_TEST;
DATA1 can not get data, warrior please help, see if they write wrong, or the temporary table is PLSQL by has a problem!
CodePudding user response:
Session the temporary table, after the end of the session will automatically clean up data, do not need to program control truncate,When you use the cursor to the examination of the semantic, found the table object does not exist, would be an error,
CodePudding user response:
I now the wording, DATA1 get less than the corresponding values, this is what reason!CodePudding user response:
A warrior provide train of thoughtCodePudding user response:
To add a process used to drop the temporary table, you will now process the table name used as the temporary table, after using the cursor data, and then drop off processCodePudding user response:
Because you delete this table, the cursor to get the data, is you turn on when he will get the data, and views about the same, will not save the data, the fault is can't find the tableCodePudding user response:
SYS_REFCURSOR type of cursor belongs to the weak type, in the OPEN, to carry out the actual statement, that is to do a grammar check,Behind you deleted references, certainly won't find it, and at a table does not exist error,
In fact, the use of temporary table standards should be like this: to build a temporary table in the database first, rather than to dynamic to create it in the storage,
Suggestion of the 1 # and 5 # reply,
CodePudding user response: