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 -> Dynamic SWQ

Dynamic SWQ

From: Marty Frongillo <mfrongillo_at_onwardtech.com>
Date: 1997/01/08
Message-ID: <32D3E811.6225@onwardtech.com>#1/1

I'm trying to use dynamic sql for the first time. I want to have a general
purpose routine, where I pass in the table-name and field-name and it will query the database and return the number of rows selected (and eventually an array of field-names). I can't seem to get this to work.

The table is simply,

SQL> describe language

 Name                            Null?    Type
 ------------------------------- -------- ----
 LANGID                          NOT NULL NUMBER(38)
 NAME                            NOT NULL CHAR(32)

The fetch returns ora-1403 (no data) and I don't know what's wrong. I've
tried various combinations, but to no-avail. Hopefully, someone can point out
my mistake.

Is there better documentation than in the Pro*C manual (chapter 11)?

int select_table_dyn (char *tablename, char *fieldname, char *data_ptr[])
{

     int                i, j; 
     int                l, n;
     int                langid;
     int                num_rows = 0;
     int                rows_to_fetch=20;
     VARCHAR            select_stmt[80];

     static char        fields [10] [32];


/* begin */
oraca.orastxtf = ORASTFERR; strcpy(select_stmt.arr, "SELECT "); strcat (select_stmt.arr, fieldname); strcat (select_stmt.arr, " FROM "); strcat (select_stmt.arr, "user."); strcat (select_stmt.arr, tablename); select_stmt.len = strlen(select_stmt.arr);
/* Register sql_error() as the error handler */
EXEC SQL WHENEVER SQLERROR DO dyn_error ("sqlerror\n"); EXEC SQL WHENEVER NOT FOUND do break; EXEC SQL PREPARE S FROM :select_stmt; EXEC SQL DECLARE C CURSOR FOR S; EXEC SQL OPEN C; for(;;) { EXEC SQL FETCH C INTO :fields; num_rows = sqlca.sqlerrd[2]; }
/* always return the number of rows found */
return (num_rows); notfound: return (-UPA_DB_NO_REGS_FOUND);

} Received on Wed Jan 08 1997 - 00:00:00 CST

Original text of this message

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