资源描述:
《如何才能实现proc执行动态的sql》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、如何才能实现proc执行动态的SQLPROC动态SQL的有四种方式方式-:直接执行SQL语句,SQL语句中不带绑定的变量,而且SQL语句不是查询语句方式二:执行SQL语句,带绑定变量,不是查询语句。方法三:执行SQL语句,带绑定变量,可以是查询语句,需要使用游标。方法四:利用SQLDA结构体,实现动态字段,动态参数等,该方法最为灵活。方法-:EXECSQLEXECUTEIMMEDIATECREATETABLEtest(test_colVARCHAR2(4));方法二:strcpy(sqlstring,"DELETEFROMtestWHEREtest_col=:?");EXECSQLdivPAR
2、EsqlprocFROM:sqlstring;EXECSQLEXECUTEsqlprocUSING:emp_number;方法三:if(strcmp(tsospa1.event_table,"TSOSP26")==0){strcpy(sqlstr,"selectcount(*)ascountfrom");strcat(sqlstr,tsospa1.event_table);strcat(sqlstr,"wherePRICE_SYS=:price_sys");strcat(sqlstr,"andPERIOD_NUM=:period_num");}else{strcpy(sqlstr,"selec
3、tcount(*)ascountfrom");strcat(sqlstr,tsospa1.event_table);strcat(sqlstr,"wherePROD_CODE=:prode_code");strcat(sqlstr,"andPRICE_SYS=:price_sys");strcat(sqlstr,"andPERIOD_NUM=:period_num");}EDLog(1,1,"sqlstr=%s",sqlstr);EXECSQLPREPARESFROM:sqlstr;EXECSQLDECLARECCURSORFORS;if(strcmp(tsospa1.event_table,
4、"TSOSP26")==0){EXECSQLOPENCUSING:tsospa1.price_sys,est_PERIOD_NUM;}/*elseif(strcmp(tsospa1.event_table,"TSOSP25")==0){EXECSQLOPENCUSING:tsospa1.price_sys,dest_PERIOD_NUM;}*/else{EXECSQLOPENCUSING:tsospa1.prod_code,:tsospa1.price_sys,dest_PERIOD_NUM;}for(fetchRowCount=0;;){EXECSQLFETCHCINTO:count;if(
5、sqlca.sqlcode==1403)break;fetchRowCount++;EDLog(1,1,"Do");EDLog(1,1,"count=%d",max_version_num);}第四种:#include#include#include#include#include#include/*Maximumnumberofselect-listitemsorbindvariables.*/#defineMAX_ITEMS40/*Maximumlengthsofthe_na
6、mes_oftheselect-listitemsorindicatorvariables.*/#defineMAX_VNAME_LEN30#defineMAX_INAME_LEN30#ifndefNULL#defineNULL0#endif/*Prototypes*/#ifdefined(__STDC__)voidsql_error(void);intoracle_connect(void);intalloc_descriptors(int,int,int);intget_dyn_statement(void);voidset_bind_variables(void);voidprocess
7、_select_list(void);voidhelp(void);#elsevoidsql_error(/*_void_*/);intoracle_connect(/*_void_*/);intalloc_descriptors(/*_int,int,int_*/);intget_dyn_statement(/*void_*/);voidset_bind_variables(/*_void-*/