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

Home -> Community -> Usenet -> c.d.o.misc -> Re: Embedded dynamic SQL

Re: Embedded dynamic SQL

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Tue, 17 Aug 1999 17:28:00 GMT
Message-ID: <37c19b60.109787255@newshost.us.oracle.com>


A copy of this was sent to kejohnson_at_yahoo.com (if that email address didn't require changing) On Tue, 17 Aug 1999 16:02:32 GMT, you wrote:

>
>>
>> lets see the code. without that we won't be able to get very far...
>>
>
>This is the code that I'm currently testing. Output is below.
>
>static int qporg
>{
>char sql_string[1024];
>
>EXEC SQL BEGIN DECLARE SECTION;
> varchar sql_statement[1024];
>EXEC SQL END DECLARE SECTION;
>
>sprintf( sql_string,
> "SELECT ORGANIZATION_CODE FROM ORG_ORGANIZATION_DEFINITIONS");
>
>strcpy( sql_statement.arr, sql_string);
>sql_statement.len= strlen( sql_statement.arr);
>
>fprintf(efp, "Preparing...\n");
>EXEC SQL AT ora_db PREPARE qporg_s from :sql_statement;
>if ( ! check_sqlcode( &sqlca, 1) )
>{
> return 0;
>}
>
>fprintf(efp, "Declaring...\n");
>EXEC SQL AT ora_db DECLARE qporg CURSOR FOR qporg_s;
>if ( ! check_sqlcode( &sqlca, 1) )
>{
> return 0;
>}
>
>fprintf(efp, "Opening...\n");
>EXEC SQL OPEN qporg;

EXEC SQL AT ora_db OPEN ....

You used an explicit connection for all of the other code but forgot to use it for the OPEN. The open therefore takes place on the default connection, not the ora_db connection and fails....

>if ( ! check_sqlcode( &sqlca, 1) )
>{
> return 0;
>}
> 275,2-16
>}
>
>
>
>The output I see when I run this is:
>Preparing...
>Declaring...
>Opening...
>SQL-02122: Invalid OPEN or PREPARE for this database connection (errno
>-2122)
>
>
>Thanks.
>
>
>Sent via Deja.com http://www.deja.com/
>Share what you know. Learn what you don't.

--
See http://govt.us.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'... Current article is "Part I of V, Autonomous Transactions" updated June 21'st  

Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Tue Aug 17 1999 - 12:28:00 CDT

Original text of this message

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