pb5中select语句into后接两个变量名是什么意思

ggxx 2008-11-26 08:55:38
很不幸最近用到古老的pb5,读程序时发现类似下面的sql语句

integer i=100;
integer l_c1,v_c1,l_c2,v_c2,l_c3,v_c3

SELECT c1,c2,c3
INTO :l_c1:v_c1,:l_c2:v_c2,:l_c3:v_c3
FROM tb
WHERE ...
USING ...

而且下面有这样的语句

IF l_c1=0 AND l_c2=0 THEN
i=(i*v_c1)/v_c2
END IF

分母为0 ???
完全看不懂什么意思,请高手解答一下。不胜感激。
...全文
450 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ggxx 2008-11-26
  • 打赏
  • 举报
回复
明白了。多谢大家,特别是2楼的sdhylj。
程序中的SQL语句少写了空格,但是依然能运行。汗……
指示变量的规范写法应该是
INTO :abc :iabc

这么说来程序或者数据库中还应该有其他约束条件,可以保证分母不为零。
我再看看吧。

再次感谢!
青锋-SS 2008-11-26
  • 打赏
  • 举报
回复
正常情况下v_c2应该是0的.
xiaoyehua 2008-11-26
  • 打赏
  • 举报
回复
而且下面有这样的语句

IF l_c1=0 AND l_c2=0 THEN
i=(i*v_c1)/v_c2
END IF
分母为0 ???

分母是V_C2,没有为0啊,为0的是l_c1和l_c2????
青锋-SS 2008-11-26
  • 打赏
  • 举报
回复
以上是PB8的帮助,楼主看看,应该可以明白,至于代码中为什么用v_c2做除数,这确实让人纳闷.
青锋-SS 2008-11-26
  • 打赏
  • 举报
回复
Error reporting   Not all DBMSs return a conversion error when the data type of a column does not match the data type of the associated variable.
The following statement uses the indicator variable IndVar2 to see if Address contains a NULL value:

if IndVar2 = -1 then...

You could also use the PowerScript IsNull function to accomplish the same result without using indicator variables:

if IsNull( Address ) then ...

This statement uses the indicator variable IndVar3 to set City to NULL:

IndVar3 = -1

You could also use the PowerScript SetNull function to accomplish the same result without using indicator variables:

SetNull( City )
青锋-SS 2008-11-26
  • 打赏
  • 举报
回复

Using indicator variables

PowerBuilder supports indicator variables, which are used to identify NULL values or conversion errors after a database retrieval. Indicator variables are integers that are specified in the HostVariableList of a FETCH or SELECT statement.
Each indicator variable is separated from the variable it is indicating by a space (but no comma). For example, this statement is a HostVariableList without indicator variables:

:Name, :Address, :City

The same HostVariableList with indicator variables might look like this:

:Name :IndVar1, :Address :IndVar2, :City :IndVar3

Indicator variables have one of these values:

Numerical value Meaning
0 Valid, non-NULL value
-1 NULL value
-2 Conversion error
jy00114015 2008-11-26
  • 打赏
  • 举报
回复
应该是将查询出来的数据赋给变量吧

754

社区成员

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

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