Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: execute immediate 'insert into ...'

Re: execute immediate 'insert into ...'

From: <scott.hutchinson_at_interact-analysis.com>
Date: Fri, 9 Sep 2005 16:33:55 +0100
Message-ID: <1126280035.4321ab63cff40@mopp.namemagic.com>


Joe,

Here are a few suggestion:

  1. Where-ever possible you should use bind variables so you don't shoot your shared pool to pieces, so do it like this:

execute immediate 'insert into test values (:1, :2, :3)' USING 2, 'joe', TO_DATE ('07-JUN-2005','DD-MON-YYYY') 2. To simplify your SQL and improve error handling, always put your dymanic SQL into a variable, then run the variable:

DECLARE
  w_sql VARCHAR2(100) := 'insert into test values (:1, :2, :3)'; BEGIN
  execute immediate w_sql USING 2, 'joe', TO_DATE('07-JUN-2005','DD-MON-YYYY'); EXCEPTION
  WHEN OTHERS THEN
    dbms_output.put_line('Error running sql: '||w_sql);     RAISE;
END; Scott Hutchinson
Interact Analysis Ltd.

Quoting Joe Smith <joe_dba_at_hotmail.com>:

> I am trying to insert records into a table through execute immediate. The
> number datatypes go in with no problem. It is the varchar2 and date formats
>
> that are giving me a problem.
>
>
> examples:
>
> desc tables test
> col1 number,
> col2 varchar2(30)
> col3 date
>
> execute immediate 'insert into test values ('|| 2 ||', '|| joe ||', '||
> 07-JUN-05 ||')';
>
>
> I have tried different ways to format the varchar2 and date datatype, but
> keeps giving me an error.
>
> How do I format these datatypes within an execute immediate?
>
> thanks.
>
> _________________________________________________________________
> Express yourself instantly with MSN Messenger! Download today - it's FREE!
> http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>
> --
> http://www.freelists.org/webpage/oracle-l
>

::This message sent using the free Web Mail service from http://TheName.co.uk

--
http://www.freelists.org/webpage/oracle-l
Received on Fri Sep 09 2005 - 10:35:18 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US