SQLPLUS 正在让我的脚本提示:输入行的值
Posted
技术标签:
【中文标题】SQLPLUS 正在让我的脚本提示:输入行的值【英文标题】:SQLPLUS is making my script to prompt: Enter value for row 【发布时间】:2018-02-07 21:34:12 【问题描述】:我正在运行最基本的 oracle sql 脚本并在 sqlplus 中运行它。 我不明白为什么我的脚本会停止提示我输入“输入行的值”。 FOR LOOP 不是应该在循环之前打开光标吗?
代码是:
/*
File: myTest.sql
*/
SET SERVEROUTPUT ON SIZE UNLIMITED
SET LINESIZE 140
SET PAGESIZE 60
SET ECHO OFF
SET TERM ON
SET FEEDBACK OFF
SET SHOW ON
SET VERIFY OFF
SPOOL &1
/* Run Parameters & Variables */
DECLARE
text_line VARCHAR2(4000);
/* Cursors & Row Types */
CURSOR myCursor IS
select spriden_pidm, spriden_id, spriden_first_name, spriden_last_name from spriden where spriden_id = '1234';
myCursorRec myCursor%ROWTYPE;
/* Main Logic */
BEGIN
/* Read through all the entries form our data sources. */
FOR myCursorRec IN myCursor LOOP
text_line := text_line + myCursorRec.spriden_last_name;
END LOOP;
DBMS_OUTPUT.PUT_LINE('This is the output: ' || text_line || ', ');
END;
/
SPOOL OFF
/* EXIT is needed for Windows environments. */
EXIT
我用这个命令运行它:
sqlplus dbuser/userpass@dbserver @myTest MYSPOOL
输出如下:
SQL*Plus: Release 11.1.0.7.0 - Production on Wed Feb 7 13:06:51 2018
Copyright (c) 1982, 2008, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
new: showmode BOTH
old: verify ON
new: verify OFF
Enter value for row: gggggg
DECLARE
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at line 14
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
为什么我会收到“输入行的值:”提示???
【问题讨论】:
ORA-06502 - 数值或数值错误是针对 text_line := text_line + myCursorRec.spriden_last_name;将 + 替换为 || 【参考方案1】:因为与号,这里:
/* Cursors & Row Types */
将SET DEFINE OFF
包含到您的 SET 命令集中,然后重试。
或者,或者,使用 AND :)
/* Cursors and Row Types */
【讨论】:
成功了,谢谢!我认为 cmets 是无害的:/ @SalvadorValencia 这是 SQL*Plus 的一个怪癖,如果你问我,一个 bug :)以上是关于SQLPLUS 正在让我的脚本提示:输入行的值的主要内容,如果未能解决你的问题,请参考以下文章