Re: Dynamic SQL - PREPARE

From: Tim Smith <tssmith_at_netcom.com>
Date: Thu, 12 Nov 1992 03:45:41 GMT
Message-ID: <1992Nov12.034541.22098_at_netcom.com>


In article <1992Nov11.191651.1_at_vax1.tcd.ie> nafallon_at_vax1.tcd.ie writes:
>Hi, anybody like to help a struggling Oracler?.
>One of our tables has a column listing the other tables to be accessed.
>I want to read a table name into a variable and then query that table for some
> more data, therefore I have to use Dynamic SQL, but I cannot seem to get past
> the PREPARE stage.
>
>The statement: EXEC SQL PREPARE subcat_stmt FROM :select_stmt;
>
>gives the error: ORA-00911: invalid character
>
>select_stmt is created as follows..
>
>EXEC SQL BEGIN DECLARE SECTION;
> VARCHAR select_stmt[200];
>EXEC SQL END DECLARE SECTION;
>
>sprintf(select_stmt.arr,"SELECT song FROM rush WHERE album = 'Presto'");
>
>I have tried all sorts of combinations of VARCHARs and char's as well as using
> variables for column names but the same error always results.
>Any pointers as to why this is happening would be greatly appreciated.
>
>Niall Fallon

Looks like you're not setting the length component of the VARCHAR. Your sprintf should be:

select_stmt.len = sprintf(select_stmt.arr, "SELECT ....

--Tim (tssmith_at_netcom.com) Received on Thu Nov 12 1992 - 04:45:41 CET

Original text of this message