Sal*_*cia 0 sql oracle plsql sqlplus
我正在运行最基本的 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
Run Code Online (Sandbox Code Playgroud)
我用这个命令运行它:
sqlplus dbuser/userpass@dbserver @myTest MYSPOOL
Run Code Online (Sandbox Code Playgroud)
输出如下所示:
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
Run Code Online (Sandbox Code Playgroud)
为什么我会收到“为行输入值:”提示???
由于&符号,这里:
/* Cursors & Row Types */
Run Code Online (Sandbox Code Playgroud)
包括SET DEFINE OFF到您的 SET 命令集中,然后再试一次。
或者,或者,使用 AND :)
/* Cursors and Row Types */
Run Code Online (Sandbox Code Playgroud)