Create a Sequence with START WITH from Query(使用 START WITH 从查询创建序列)
问题描述
如何创建 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");
但是,我收到了 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 从查询创建序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 START WITH 从查询创建序列


基础教程推荐
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01