FAQ

[Oracle-l] need execute immediate and script help

Rgaffuri_at_cox.net
Jul 21, 2003 at 8:02 pm
Im calling a script that uses dynamic sql. Im passing in a value as well. I keep getting

SP2-0552: Bind variable "2" not declared.

Here is a code snipped

declare
v_var1 Varchar2(30) := 'TEST';
v_var2 VARCHAR2(30) := '&1';
total number;
begin

execute immediate ' Select * ' ||
' from user_objects '||
' where object_name = :1 '||
' or object_name = :2 '||
using v_var1,v_var2
into total;

end;
/

I call it as follows:
reply

Search Discussions

2 responses

  • Jamadagni, Rajendra at Jul 21, 2003 at 8:08 pm
    This message is in MIME format. Since your mail reader does not understand
    this format, some or all of this message may not be legible.

    ------=_NextPartTM-000-71d2afd5-74aa-4e93-a9e8-71ee7bca8140
    Content-Type: multipart/alternative;

    boundary="----_=_NextPart_001_01C34FC3.D260B5DA"

    ------_=_NextPart_001_01C34FC3.D260B5DA
    Content-Type: text/plain;

    charset="iso-8859-1"

    you want 'select count(*)' ... right?

    Raj

    Rajendra dot Jamadagni at nospamespn dot com
    All Views expressed in this email are strictly personal.
    QOTD: Any clod can have facts, having an opinion is an art !

    -----Original Message-----
    From: rgaffuri_at_cox.net
    Sent: Monday, July 21, 2003 5:00 PM
    To: Multiple recipients of list ORACLE-L
    Subject: need execute immediate and script help

    Im calling a script that uses dynamic sql. Im passing in a value as well. I
    keep getting

    SP2-0552: Bind variable "2" not declared.

    Here is a code snipped

    declare
    v_var1 Varchar2(30) := 'TEST';
    v_var2 VARCHAR2(30) := '&1';
    total number;
    begin

    execute immediate ' Select * ' ||
    ' from user_objects '||
    ' where object_name = :1 '||
    ' or object_name = :2 '||
    using v_var1,v_var2

    into total;

    end;
    /

    I call it as follows:

    @script HELLO

    --
    Please see the official ORACLE-L FAQ: http://www.orafaq.net
    --
    Author: http://www.fatcity.com
    San Diego, California -- Mailing list and web hosting services
    ---------------------------------------------------------------------
    To REMOVE yourself from this mailing list, send an E-Mail message
    to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
    the message BODY, include a line containing: UNSUB ORACLE-L
    (or the name of mailing list you want to be removed from). You may
    also send the HELP command for other information (like subscribing).

    ------_=_NextPart_001_01C34FC3.D260B5DA
    Content-Type: text/html;
    charset="iso-8859-1"
    Content-Transfer-Encoding: quoted-printable

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">

    RE: need execute immediate and script help

    you want 'select count(*)' ... right?

    Raj
    ---------------------------------------------------------------=
    -----------------
    Rajendra dot Jamadagni at nospamespn dot com
    All Views expressed in this email are strictly =
    personal.
    QOTD: Any clod can have facts, having an opinion is =
    an art !

    -----Original Message-----
    From: rgaffuri_at_cox.net [mailto:rgaffuri_at_cox.net]
    Sent: Monday, July 21, 2003 5:00 PM
    To: Multiple recipients of list ORACLE-L
    Subject: need execute immediate and script =
    help

    Im calling a script that uses dynamic sql. Im passing =
    in a value as well. I keep getting

    SP2-0552: Bind variable &quot;2&quot; not =
    declared.

    Here is a code snipped

    declare
    &nbsp; v_var1 Varchar2(30) :=3D 'TEST';
    &nbsp; v_var2 VARCHAR2(30) :=3D '&amp;1';
    &nbsp; total number;
    begin

    execute immediate ' Select * ' ||
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
    sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' from user_objects '||
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
    sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' where object_name =3D :1 =
    '||
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
    sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' or object_name =3D :2 =
    '||
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
    sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using v_var1,v_var2
    &nbsp; into total;

    end;
    /

    I call it as follows:

    @script HELLO

    --
    Please see the official ORACLE-L FAQ: http://www.orafaq.net" =
    TARGET=3D"_blank">http://www.orafaq.net
    --
    Author: &lt;rgaffuri_at_cox.net
    &nbsp; INET: rgaffuri_at_cox.net

    Fat City Network Services&nbsp;&nbsp;&nbsp; -- =
    858-538-5051 http://www.fatcity.com" =
    TARGET=3D"_blank">http://www.fatcity.com
    San Diego, =
    California&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Mailing list =
    and web hosting services
    ---------------------------------------------------------------=
    ------
    To REMOVE yourself from this mailing list, send an =
    E-Mail message
    to: ListGuru_at_fatcity.com (note EXACT spelling of =
    'ListGuru') and in
    the message BODY, include a line containing: UNSUB =
    ORACLE-L
    (or the name of mailing list you want to be removed =
    from).&nbsp; You may
    also send the HELP command for other information =
    (like subscribing).

    ------_=_NextPart_001_01C34FC3.D260B5DA--

    ------=_NextPartTM-000-71d2afd5-74aa-4e93-a9e8-71ee7bca8140
    Content-Type: text/plain;
    name="ESPN_Disclaimer.txt"
    Content-Transfer-Encoding: 7bit
    Content-Disposition: attachment;
    filename="ESPN_Disclaimer.txt"

    ********************************************************************This e-mail message is confidential, intended only for the named recipient(s) above and may contain information that is privileged, attorney work product or exempt from disclosure under applicable law. If you have received this message in error, or are not the named recipient(s), please immediately notify corporate MIS at (860) 766-2000 and delete this e-mail message from your computer, Thank you.*********************************************************************2
  • Rudy Zung at Jul 21, 2003 at 8:22 pm
    Your "using v_var1,v_var2" shouldn't be appended to the
    string that represents the dynamic SQL to execute;
    the "using..." is part of the syntac for execute immediate.
    An Oracle error message being what they are, they don't
    always highlight the correct cause of fault, but will
    identify some other error located close to where the real
    fault lies.

    For your solution, remove the "||" that occurs after
    ":2"

    It is also unlikely that you can select "*" into
    TOTAL, which has been declared as a NUMBER. Consider
    "count(*)" perhaps?

    -----Original Message-----
    From: rgaffuri_at_cox.net
    Sent: Monday, July 21, 2003 5:00 PM
    To: Multiple recipients of list ORACLE-L
    Subject: need execute immediate and script help

    Im calling a script that uses dynamic sql. Im passing in a value as well. I
    keep getting

    SP2-0552: Bind variable "2" not declared.

    Here is a code snipped

    declare
    v_var1 Varchar2(30) := 'TEST';
    v_var2 VARCHAR2(30) := '&1';
    total number;
    begin

    execute immediate ' Select * ' ||
    ' from user_objects '||
    ' where object_name = :1 '||
    ' or object_name = :2 '||
    using v_var1,v_var2
    into total;

    end;
    /

    I call it as follows:

    @script HELLO

    --
    Please see the official ORACLE-L FAQ: http://www.orafaq.net
    --
    Author: http://www.fatcity.com
    San Diego, California -- Mailing list and web hosting services
    ---------------------------------------------------------------------
    To REMOVE yourself from this mailing list, send an E-Mail message
    to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
    the message BODY, include a line containing: UNSUB ORACLE-L
    (or the name of mailing list you want to be removed from). You may
    also send the HELP command for other information (like subscribing).

Related Discussions

Discussion Navigation
viewthread | post