SQLPlus执行含CREATE命令脚本异常:首COMMIT后停止并打印剩余代码
First off, this issue is almost always tied to SQLPlus statement termination rules or script structure rather than database-level settings. Let’s break down the most common fixes and checks:
1. Fix PL/SQL CREATE Block Termination
If your CREATE commands are for stored procedures, functions, triggers, or packages (any multi-line PL/SQL block), you must terminate the block with a slash (/) on its own line before running COMMIT. SQLPlus uses this slash to execute the entire PL/SQL block—without it, it may not fully process the CREATE statement before moving to COMMIT, leading to unexpected execution stops.
Example of correct structure:
CREATE PROCEDURE sample_proc AS BEGIN -- Procedure logic here NULL; END; / -- Critical: Slash on a new line to execute the PL/SQL block COMMIT; CREATE TABLE sample_table (id NUMBER); COMMIT; -- For table creation, a semicolon is sufficient
2. Execute the Script Properly
Avoid pasting the script content interactively into SQLPlus—terminal input buffering can cause premature execution stops. Instead, run the script using SQLPlus’s built-in commands:
sqlplus username/password@database @your_script.sql
3. Check for Hidden Control Characters
Scripts saved from some editors (like Windows Notepad) may have hidden carriage returns (\r) that confuse SQLPlus. Use a text editor that shows invisible characters, or run cat -v your_script.sql on Linux/macOS to spot these.
4. Rule Out Edge Case SQLPlus Settings
While less likely, a few settings could interfere with script execution:
SET STOPONERROR ON: This halts execution on errors, but since your first COMMIT completes, this is probably not the issue.SET SQLTERMINATOR: If someone changed the default terminator from;to another character, it could break statement parsing. Check withSHOW SQLTERMINATORand reset to default withSET SQLTERMINATOR ;if needed.
If none of these work, simplify your script to a minimal version (two CREATE commands + COMMITs) to isolate the problem, then add back sections until you find the line causing the stop.
内容的提问来源于stack exchange,提问作者KRod

