动态游标不能正确执行 + 不能检测数据库中是否已经存在了某个表????

shizi_mhy 2002-01-29 11:53:51
一,动态检测某个数据库表的记录数是否为零(数据库表不确定)

string table_temp //动态的数据库表名
int count_temp //
string sql_temp //动态sql语句

sql_temp = "select count(*) from " + table_temp

declare get_count cursor for sql_temp;
open get_count;
fetch get_count into :count_temp;
close get_count;

if count_temp = 0 then
//...
end if

无论怎么样
最后提取的count_temp都是0

二,不能检测数据库中是否已经存在了某个表

select count(*)
into :count_temp
from sysobjects
where name = :table_temp;

最后得到也总是0
就是检测不到记录数

不知道为什么
我都一年没有摸pb了
请各位帮忙
:P

柿子

...全文
125 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ksmgbits 2002-01-29
  • 打赏
  • 举报
回复
你的SQL语句错误,应该为动态游标
string table_temp //动态的数据库表名
int count_temp //
string sql_temp //动态sql语句
sql_temp = "select count(*) from " + table_temp
declare get_count dynamic cursor for sqlsa;
prepare sqlsa from :sql_temp;
open dynmic get_count;
fetch get_count into :count_temp;
close get_count;

if count_temp = 0 then
//...
end if
chenxuqian 2002-01-29
  • 打赏
  • 举报
回复
select nrows into :count_temp
from systables
where tabname = :table_temp;

pbworm 2002-01-29
  • 打赏
  • 举报
回复
1、同意魔鬼
2、你的语句没有什么问题,看看变量的设置是不是有问题,或实际上无这个表。

柿子,好久不见,现在忙什么呢?主要用什么编程啊?
iamjjp 2002-01-29
  • 打赏
  • 举报
回复
检测数据库中是否已经存在了某个表
如果是Oracle 就
select count(*)
into :count_temp
from tab
where tname =:table_temp;
iamjjp 2002-01-29
  • 打赏
  • 举报
回复
fetch my_curs using descriptor SQLDA;
close my_curs;
iamjjp 2002-01-29
  • 打赏
  • 举报
回复
string table_temp //动态的数据库表名
int count_temp //
string sql_temp //动态sql语句
sql_temp = "select count(*) from " + table_temp


//定义动态游标
PREPARE SQLSA FROM :sql_temp;
DESCRIBE SQLSA INTO SQLDA ;
OPEN DYNAMIC my_curs USING DESCRIPTOR SQLDA ;
godblood 2002-01-29
  • 打赏
  • 举报
回复
SQLCA已经connect database了?
测试一下
messagebox("",string(SQLCA,SQLcode) + "~t"+ SQLCA.SQLErrText)
看看返回什么信息
qixin000 2002-01-29
  • 打赏
  • 举报
回复
ksmgbits(流浪) 完全正确
zealwjh 2002-01-29
  • 打赏
  • 举报
回复
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
//表达式为真则存在

754

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧