I have created the function below by typing into the "Enter SQL Statement" box in the SQL Developer tool and running. I see the message "create or REPLACE FUNCTION Statement Processed". I see the Function in the tree view, but it has a red cross icon next to it, so I guess somethings wrong with it. When I try to run it I get the message "The selected program is in an invalid state for running. Recompile the program and try again." If I right-click the function and compile then I get no errors but the red cross remains and I still can't run it.
What am I doing wrong?
Also, I am planning on supplying a SQL script to customers that will have this function at the top of the script, and then I will use the function throughout the rest of the script to decide whether or not to drop a table before re-creating it. Will that be ok? i.e. will the function be available to the rest of the script, or would the function creation need to be followed by a commit/grant/other?
CREATE OR REPLACE FUNCTION CHECK_TABLE_EXISTS(tableName VARCHAR2)
RETURN BOOLEAN IS
tableExists NUMBER(1,0);
BEGIN
SELECT COUNT(*) INTO tableExists FROM user_tables WHERE table_name=tableName;
IF tableExists = 1 THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
END CHECK_TABLE_EXISTS;
Thanks,
Paul