读书人

pb中sql语言的select语句中的表名不能

发布时间: 2012-02-12 17:16:33 作者: rapoo

pb中sql语言的select语句中的表名不能用变量
这个问题我在以前的帖子中 找到了,可是答案有些模糊
string cursor_class[13]
/////cursor_class[13],已经赋值,是13个表名
datetime ls_time2
string ls_sql
for i = 1 to 13
ls_sql="select max(datime) :into ls_time2 from " + cursor_class[i] + " USING sourcetrans" ;
execute immediate :ls_sql ;// USING sourcetrans;
update b
set d_to=:ls_time2 using destinationtrans where d_table=:cursor_class[i];//这个变量放的是表名
commit;
next


这个红色代码部分有问题,其中有一个变量ls_time2。不知道 怎么处理了

[解决办法]
看来楼主是一定要做了,那就帮写个

int i
string cursor_class[13]

datetime ls_time2
string ls_sql
for i = 1 to 13
DECLARE my_cursor DYNAMIC CURSOR FOR SQLSA ;
ls_sql="select max(datime) from " + cursor_class[i]
PREPARE SQLSA FROM :ls_sql;
OPEN DYNAMIC my_cursor ;
FETCH my_cursor INTO :ls_time2 ;
CLOSE my_cursor ;

update b set d_to=:ls_time2 where d_table=:cursor_class[i] using destinationtrans;
commit;
next

读书人网 >PB

热点推荐