我正在尝试在一个sql文件中运行一些语句,但它不起作用。
declare
new_sequence INTEGER;
begin
select LAST_NUMBER + 1
into new_sequence
from user_sequences
where SEQUENCE_NAME = 'MLTS_SEQUENCE';
execute immediate 'Create sequence Table_SEQ start with '
|| new_sequence ||' increment by 1';
end;
如果我在eclipse数据库插件中运行带有'execute as one statement'选项的块,它可以工作。
我如何将sqlscript标记为将这些块作为一个语句运行,稍后使用sqlplus或不同于eclipse的内容执行脚本?
我在前面和/或最后尝试了GO,但这也没有用。
答案 0 :(得分:1)
只要它在自己的行上并且左对齐,它在sql * plus中应该没问题:
SQL> create sequence MLTS_SEQUENCE start with 1 cache 20;
Sequence created.
SQL> select MLTS_SEQUENCE.nextval from dual;
NEXTVAL
----------
1
SQL> declare
2 new_sequence INTEGER;
3 begin
4 select LAST_NUMBER + 1
5 into new_sequence
6 from user_sequences
7 where SEQUENCE_NAME = 'MLTS_SEQUENCE';
8
9 execute immediate 'Create sequence Table_SEQ start with '
10 || new_sequence ||' increment by 1';
11 end;
12 /
PL/SQL procedure successfully completed.
SQL> select Table_SEQ.nextval from dual;
NEXTVAL
----------
22
答案 1 :(得分:0)
sqlplus的正确格式如下:
declare
...
begin
...
end;
/