I am a SQL Server user, and I have a small project to work with Oracle, so I'm trying to understand some of the features of Oracle, and I believe that I need help to better understand the following situation:
I want to check if a temporary table exists before creating it, so I had this code here:
DECLARE
table_count INTEGER;
var_sql VARCHAR2(1000) := 'create GLOBAL TEMPORARY table TEST (
hello varchar(1000) NOT NULL)';
BEGIN
SELECT COUNT(*) INTO table_count FROM all_tables WHERE table_name = 'TEST';
IF table_count = 0 THEN
EXECUTE IMMEDIATE var_sql;
END IF;
END;
It works fine, so after I executed it once, I added an else statement to my IF:
ELSE
insert into test (hello) values ('hi');
I executed it again, and a row was added to the test table.
Ok, my code was ready and working, so I reset the temporary table and tried to run the whole statement again, but when I do this, I get the following error:
ORA-06550: line 11, column 19:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 11, column 7:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Then I replaced this expression with another, and now it works again:
ELSE
EXECUTE IMMEDIATE 'insert into test (hello) values (''hi'')';
, , EXECUTE IMMEDIATE, SELECT , BEGIN - , , , EXECUTE IMMEDIATE ?