其中表名和字段名都是变量,updatefield是字段名变量tablename是表名变量
一定要用游标吗?
9 个解决方案
#1
不一定要用游标取值的,取出来的值,如果是唯一的,可以直接用select into ,如果返回的值不是唯一的,可以使用游标。
#2
我的语句这样写的:
String sqltxt,updatefield,tablename,bh_read
Real olddata
updatefield = "aac817"
tablename = "agzk"
bh_read = "1300981625549"
sqltxt="Select "+ updatefield+" from "+tablename+" where "+tablename+".aac001='"+bh_read+"' into :olddata";
EXECUTE IMMEDIATE :sqltxt;
messagebox("aa",string(olddata))
得到的值却是0
String sqltxt,updatefield,tablename,bh_read
Real olddata
updatefield = "aac817"
tablename = "agzk"
bh_read = "1300981625549"
sqltxt="Select "+ updatefield+" from "+tablename+" where "+tablename+".aac001='"+bh_read+"' into :olddata";
EXECUTE IMMEDIATE :sqltxt;
messagebox("aa",string(olddata))
得到的值却是0
#3
你不要用EXECUTE IMMEDIATE :sqltxt;
PB中可以直接select into 赋值给变量的,这个地方没必要用EXECUTE IMMEDIATE .
PB中可以直接select into 赋值给变量的,这个地方没必要用EXECUTE IMMEDIATE .
#4
只能使用游标,或者syntaxfromsql
#5
游标:
string ls_sql
string ls_data //假设要获取数据的列的类型为char,其他类型则定义相应的变量类型
ls_sql = "select " + ls_updatefield + " from " + ls_tablename + " where aac001 = " + string(bh_read)
declare lc dynamic cursor for sqlsa;
prepare sqlsa from :ls_sql using sqlca;
open dynamic lc;
if sqlca.sqlcode = -1 then
messagebox('', '出错了')
return
end if
fetch lc into :ls_data; //获取数据
if sqlca.sqlcode = -1 then
messagebox('', '出错了')
return
end if
close lc;
#6
syntaxfromsql:
string ls_sql
string error_syntaxfromSQL, error_create
string ls_syntax
datastore lds
long i
ls_sql = "select " + ls_updatefield + " from " + ls_tablename + " where aac001 = " + string(bh_read)
ls_syntax = sqlca.SyntaxFromSQL(ls_sql, 'Style(Type=Grid)', error_syntaxfromSQL)
IF Len(error_syntaxfromSQL) > 0 THEN
messagebox("",'生成数据存储语法发生错误!~r~n错误原因:' + error_syntaxfromSQL)
return -1
ELSE
lds = create datastore
lds.Create(ls_syntax, error_create) //dw_1就是你要显示数据的数据窗口
IF Len(error_create) > 0 THEN
destroy lds
messagebox('', '建立数据存储时发生错误!~r~n错误原因:' + error_create)
return -1
END IF
END IF
lds.settransobject(sqlca)
lds.retrieve()
//接下来就是从lds中取数据了,假设ls_sql = "select a from" 则lds包含1个列,列名为a
...
...
destroy lds
#7
dynamicsql 4
#8
dynamicsql 4
#9
dynamicsql 4
#1
不一定要用游标取值的,取出来的值,如果是唯一的,可以直接用select into ,如果返回的值不是唯一的,可以使用游标。
#2
我的语句这样写的:
String sqltxt,updatefield,tablename,bh_read
Real olddata
updatefield = "aac817"
tablename = "agzk"
bh_read = "1300981625549"
sqltxt="Select "+ updatefield+" from "+tablename+" where "+tablename+".aac001='"+bh_read+"' into :olddata";
EXECUTE IMMEDIATE :sqltxt;
messagebox("aa",string(olddata))
得到的值却是0
String sqltxt,updatefield,tablename,bh_read
Real olddata
updatefield = "aac817"
tablename = "agzk"
bh_read = "1300981625549"
sqltxt="Select "+ updatefield+" from "+tablename+" where "+tablename+".aac001='"+bh_read+"' into :olddata";
EXECUTE IMMEDIATE :sqltxt;
messagebox("aa",string(olddata))
得到的值却是0
#3
你不要用EXECUTE IMMEDIATE :sqltxt;
PB中可以直接select into 赋值给变量的,这个地方没必要用EXECUTE IMMEDIATE .
PB中可以直接select into 赋值给变量的,这个地方没必要用EXECUTE IMMEDIATE .
#4
只能使用游标,或者syntaxfromsql
#5
游标:
string ls_sql
string ls_data //假设要获取数据的列的类型为char,其他类型则定义相应的变量类型
ls_sql = "select " + ls_updatefield + " from " + ls_tablename + " where aac001 = " + string(bh_read)
declare lc dynamic cursor for sqlsa;
prepare sqlsa from :ls_sql using sqlca;
open dynamic lc;
if sqlca.sqlcode = -1 then
messagebox('', '出错了')
return
end if
fetch lc into :ls_data; //获取数据
if sqlca.sqlcode = -1 then
messagebox('', '出错了')
return
end if
close lc;
#6
syntaxfromsql:
string ls_sql
string error_syntaxfromSQL, error_create
string ls_syntax
datastore lds
long i
ls_sql = "select " + ls_updatefield + " from " + ls_tablename + " where aac001 = " + string(bh_read)
ls_syntax = sqlca.SyntaxFromSQL(ls_sql, 'Style(Type=Grid)', error_syntaxfromSQL)
IF Len(error_syntaxfromSQL) > 0 THEN
messagebox("",'生成数据存储语法发生错误!~r~n错误原因:' + error_syntaxfromSQL)
return -1
ELSE
lds = create datastore
lds.Create(ls_syntax, error_create) //dw_1就是你要显示数据的数据窗口
IF Len(error_create) > 0 THEN
destroy lds
messagebox('', '建立数据存储时发生错误!~r~n错误原因:' + error_create)
return -1
END IF
END IF
lds.settransobject(sqlca)
lds.retrieve()
//接下来就是从lds中取数据了,假设ls_sql = "select a from" 则lds包含1个列,列名为a
...
...
destroy lds
#7
dynamicsql 4
#8
dynamicsql 4
#9
dynamicsql 4