Home » Developer & Programmer » Precompilers, OCI & OCCI » Select into
Select into [message #247804] Wed, 27 June 2007 04:59 Go to next message
ataufique
Messages: 79
Registered: November 2006
Member
hi..
I am having a problem as below while coding in PRO*C

int vcount;
.....
....
EXEC SQL select count(*) into :vcount from tab ;
output comes vcount=250

now if i change the table name as dynamic.
int vcount;
char qrystmt[500];
char vtname[30];
...
...
qrystmt[0] = '\0';
vtname[0] = '\0';
strcpy(vtname,"tab");
sprintf(qrystmt,"select count(*) into :vcount from %s ",vtname);
EXEC SQL EXECUTE IMMEDIATE :qrystmt;
output comes vcount=0;

does anyone have idea why this is returning 0(zero)
Re: Select into from dynamic table name [message #248730 is a reply to message #247804] Sun, 01 July 2007 02:03 Go to previous messageGo to next message
ataufique
Messages: 79
Registered: November 2006
Member
Anyone who have faced similar problem..
Re: Select into from dynamic table name [message #254471 is a reply to message #248730] Thu, 26 July 2007 18:25 Go to previous messageGo to next message
linlasj
Messages: 98
Registered: August 2005
Location: Linköping
Member
Hi,
I do not recall but does strcpy add the null character in C?


Best Regards,
Lars
Re: Select into from dynamic table name [message #254541 is a reply to message #254471] Fri, 27 July 2007 01:31 Go to previous messageGo to next message
Michel Cadot
Messages: 64140
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
It copies until and including '\0' character.

Btw, vtname[30] should be of char[31] (30 characters plus '\0').
I prefer to use VARCHAR Oracle datatype.

Are you sure you can use "EXEC SQL EXECUTE IMMEDIATE" for a SELECT?

Regards
Michel

[Updated on: Fri, 27 July 2007 01:38]

Report message to a moderator

Re: Select into from dynamic table name [message #254574 is a reply to message #254541] Fri, 27 July 2007 02:50 Go to previous message
linlasj
Messages: 98
Registered: August 2005
Location: Linköping
Member
Hi,
OK. That is good. Me too, by the way and for what it is worth, prefer the VARCHAR2 type.


Best Regards,
Lars
Previous Topic: How do I call OCIAttrGet from C#?
Next Topic: illegal variable name/number
Goto Forum:
  


Current Time: Fri Dec 09 05:58:33 CST 2016

Total time taken to generate the page: 0.25821 seconds