使用查询的START WITH创建序列 [英] Create a Sequence with START WITH from Query
问题描述
如何创建一个序列,其中我的START WITH值来自查询?
How can I create a Sequence where my START WITH value comes from a query?
我正在尝试这种方式:
CREATE SEQUENCE "Seq" INCREMENT BY 1 START WITH (SELECT MAX("ID") FROM "Table");
I'm trying this way:
CREATE SEQUENCE "Seq" INCREMENT BY 1 START WITH (SELECT MAX("ID") FROM "Table");
但是,我收到了ORA-01722错误
But, I get the ORA-01722 error
推荐答案
START WITH CLAUSE接受一个整数.您可以动态形成创建序列"语句,然后使用立即执行来执行该语句.
The START WITH CLAUSE accepts an integer. You can form the "Create sequence " statement dynamically and then execute it using execute immediate to achieve this.
declare
l_new_seq INTEGER;
begin
select max(id) + 1
into l_new_seq
from test_table;
execute immediate 'Create sequence test_seq_2
start with ' || l_new_seq ||
' increment by 1';
end;
/
查看这些链接.
http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_6014.htm
http://download.oracle.com/docs/cd /B19306_01/appdev.102/b14261/executeimmediate_statement.htm
这篇关于使用查询的START WITH创建序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!