Re: Pro*C -- How to pass a value into a Dynamic SQL (Method 3).
From: John Blackburn <jb2_at_avalon>
Date: 29 Mar 1995 03:52:51 GMT
Message-ID: <3lalij$1rj_at_camelot.qdot.qld.gov.au>
Date: 29 Mar 1995 03:52:51 GMT
Message-ID: <3lalij$1rj_at_camelot.qdot.qld.gov.au>
Yih-feng Hwang (CS 688) (yhwang) wrote:
> Hi there,
> I got a problem about how to pass a value (NAME of table or column) into
> a dynamic SQL (method 3).
> The following problem is a sample.
> ============================================
> ....
> strcpy((char *) sqlstmt.arr,
> "SELECT distinct :col FROM :tab");
try creating the string like this:
sprintf((char *) sqlstmt.arr,
"SELECT distinct %s FROM %s",col_name.arr,tab_name.arr);
> sqlstmt.len = strlen((char *) sqlstmt.arr);
> ....
> EXEC SQL PREPARE S FROM :sqlstmt;
> EXEC SQL DECLARE C CURSOR FOR S;
> EXEC SQL OPEN C USING :col_namei, :tab_name;
this statement would then need to be changed to
EXEC SQL OPEN C;
-- John Blackburn Phone: +61 7 2534634 jb2_at_qdot.qld.gov.au Fax: +61 7 8541194Received on Wed Mar 29 1995 - 05:52:51 CEST