The following stored procedure is meant to take in a parameter my_seconds, create a date variable my_date which is the current date plus (or minus) the number in my_seconds, and print the date.
CREATE OR REPLACE PROCEDURE test (my_seconds NUMBER)
IS
my_date DATE;
BEGIN
execute immediate 'select sysdate + interval '':1'' second from dual' into my_date USING &my_seconds;
DBMS_OUTPUT.PUT_LINE('DATE:' || my_date);
END
But what happens is that when compiling the procedure (using Oracle SQL developer), it prompts for the value of my_seconds, and the procedure is not created correctly.
How should this line:
execute immediate 'select sysdate + interval '':1'' second from dual' into my_date USING &my_seconds ;
be re-written?
Thanks
&frommy_seconds.interval ':1' secondis an interval string literal. As such you can't put a variable inside the quotation marks, it needs to be a constant value. instead you'll need to use either theNUMTODSINTERVALorNUMTOYMINTERVALfunction to convert a numeric value to an interval.