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 ???
完全看不懂什么意思,请高手解答一下。不胜感激。
...全文
215 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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
应该是将查询出来的数据赋给变量吧
回复
相关推荐
发帖
数据库相关
创建于2007-09-28

734

社区成员

PowerBuilder 数据库相关
申请成为版主
帖子事件
创建了帖子
2008-11-26 08:55
社区公告
暂无公告