Execute Immediate String
I am trying to run the following pl/sql code:
declare
j varchar2(5);
i varchar2(2);
dt date;
begin
select &n1,&n2,&n3 into j,i,dt from dual;
execute immediate 'create table jovtranst as (select * from jovtrans where jovid=' || j || ' and institcod=' || i ||
' and indate=' || dt || ')';
end;
following is the version information:
Oracle Database 10g Enterprise Edition Release 10.
2.0.2.0 - 64bi
PL/SQL Release 10.2.0.2.0 - Production
CORE 10.2.0.2.0 Production
TNS for IBM/AIX RISC System/6000: Version 10.2.0.2
.0 - Productio
NLSRTL Version 10.2.0.2.0 - Production
and table structure for jovtrans:
Name Null? Type
----------------------- -------- ----------------
INSTITCOD NOT NULL VARCHAR2(3)
JOVID NOT NULL NUMBER(6)
SERNO NOT NULL NUMBER(3)
TRANSDT DATE
TRANSTYPE NUMBER(2)
RETURNBY NUMBER(1)
RLSCODE VARCHAR2(2)
USERID VARCHAR2(5)
ENTRYDATE DATE
ACTION VARCHAR2(100)
VACRSN NUMBER(1)
ADDINVAC VARCHAR2(100)
VACTIME NUMBER(2)
INDATE NOT NULL DATE
TRFDT DATE
TRFINSTITCOD VARCHAR2(3)
when I run the above "execute immediate" (within the pl/sql block) as follows:
execute immediate 'create table jovtranst as (select * from jovtrans where jovid=' || j || ' and institcod=' || i ||
' and indate=''14-8-2010''' || ')';
the procedure executes successfully.
When I replace the date above with the variable dt as follows:
execute immediate 'create table jovtranst as (select * from jovtrans where jovid=' || j || ' and institcod=' || i ||
' and indate='' || dt || ''' || ')';
I get an error (non-numeric character was found where a numeric was expected)
I tried a lot of variations but none worked as expected.
Any help much appreciated.