【发布时间】:2012-10-12 18:52:48
【问题描述】:
我是 PL/SQL 的新手,但有很多其他 SQL 经验,包括 Oracle(只是没有那么多脚本)。我想声明一个数字(整数)变量,将其设置为行数,并将其显示在句子换行的字符串中。本练习的最终目标是创建一个 SQL*Plus 脚本来打印字符串“有 1 行”。
在 Unix 上的 SQL*Plus 中,我这样做:
SQL> variable v_dCnt number;
SQL> select count(*) into :v_dCnt from dual;
COUNT(*)
----------
1
SQL> select 'There are ' || :v_dCnt || ' rows' as MESSAGE from dual;
MESSAGE
-------------------------------------------------------
There are rows
注意它如何显示v_dCnt 的空白而不是值 1
在 Win7 上的 Rapid SQL 中,我会这样做
variable v_dCnt number;
select count(*) into :v_dCnt from dual;
select 'There are ' || :v_dCnt || ' rows' from dual;
并得到 ORA-01008: 并非所有变量都绑定
我做错了什么?
【问题讨论】:
-
您确定 Rapid SQL 支持用于声明替换变量的 SQL*Plus 语法吗?
-
不确定。但是 sqlplus 也不返回它应该返回的内容...
-
所以 IOW,问题出在代码中,而不是客户端。最终,我的脚本将在 Unix 上用完 sqlplus。我包含 Rapid SQL 示例只是因为它实际上返回了一个有意义的错误消息,不像 sqlplus
标签: oracle plsql oracle11g sqlplus