PL/SQL 开发人员:多条语句?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6919653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PL/SQL Developer: Multiple statements?
提问by IVR Avenger
I have a script that generates a text file containing several SQL UPDATE statements:
我有一个脚本,它生成一个包含几个 SQL UPDATE 语句的文本文件:
UPDATE TableX SET Field1 = 'New value 1' WHERE Field2='1';
UPDATE TableX SET Field1 = 'New value 2' WHERE Field2='2';
UPDATE TableX SET Field1 = 'New value 3' WHERE Field2='3';
etc.
When I paste the above block of text into an SQL Window in PL/SQL Developer, it tells me that the semicolon is an invalid character. When I remove it, it informs me that my first statement was not terminated properly.
当我将上述文本块粘贴到 PL/SQL Developer 的 SQL 窗口中时,它告诉我分号是一个无效字符。当我删除它时,它通知我我的第一条语句没有正确终止。
How do I run these statements in a single execution?
如何在一次执行中运行这些语句?
回答by GolezTrol
I think you're using the Test window. This can only execute a single statement. The SQL Window and the Command Window are able to run multiple statements.
我认为您正在使用“测试”窗口。这只能执行单个语句。SQL 窗口和命令窗口能够运行多个语句。
If you need to run this in a Test window, you can embed it in a begin..end
block to make it a PL/SQL statement block.
如果您需要在测试窗口中运行它,您可以将它嵌入到一个begin..end
块中,使其成为一个 PL/SQL 语句块。
回答by Priyanka
I also faced this error. You need to go to tools->preferences. In window types go to SQL window and select "Auto select statement". This should remove the error.
我也遇到了这个错误。您需要转到工具-> 首选项。在窗口类型中,转到 SQL 窗口并选择“自动选择语句”。这应该消除错误。
回答by dursun
try this way;
试试这个方法;
UPDATE TableX SET Field1 = 'New value 1' WHERE Field2='1'
/
UPDATE TableX SET Field1 = 'New value 2' WHERE Field2='2'
/
UPDATE TableX SET Field1 = 'New value 3' WHERE Field2='3'
/
回答by jay gohel
Hi,
你好,
you can try this.
你可以试试这个。
Declare
Begin
UPDATE TableX SET Field1 = 'New value 1' WHERE Field2='1';
UPDATE TableX SET Field1 = 'New value 2' WHERE Field2='2';
UPDATE TableX SET Field1 = 'New value 3' WHERE Field2='3';
End;
in sql developer to execute multiple queries you need to create anonymous block.
在 sql developer 中执行多个查询需要创建匿名块。
hope this make your work easy.
希望这能让你的工作变得轻松。