我从关闭处复制了代码。说明文件:
&sql(SELECT *,%ID INTO :tflds()
FROM Sample.Person )
IF SQLCODE=0 {
SET firstflds=14
FOR i=0:1:firstflds {
IF $DATA(tflds(i)) {
WRITE "field ",i," = ",tflds(i),! }
} }
ELSE {WRITE "SQLCODE error=",SQLCODE,! }
但是由于某种原因,它只返回第一行的所有字段,而没有返回其他任何内容。是一个错误,还是我做错了?
最佳答案
您需要使用游标在SQL查询结果的行中循环。
&sql(declare c1 cursor for SELECT *,%ID INTO :tflds()
FROM Sample.Person)
&sql(open c1)
for {
&sql(fetch c1)
quit:SQLCODE'=0
set firstflds=14
for i=0:1:firstflds {
if $Data(tflds(i)) {
write "field ",i," = ",tflds(i),!
}
}
write "===NEXT ROW===",!
}
&sql(close c1)
有关更多信息,请参见http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GSQL_esql#GSQL_esql_cursor