在oracle中创建序列 [英] sequence creation in oracle

查看:70
本文介绍了在oracle中创建序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在oracle中创建一个序列,其中列字段的最大值(Empid)必须是该序列的最小值.

I want to create a sequence in oracle where the max value of the column field (Empid) must be the min value of the sequence.

以下是我在同一stackexchange中找到的那个

The below was the one i found in our same stackexchange

create sequence mytemp_seq start with &v_Startval;

此命令提示我输入必须输入的列名的最大值.

This command prompts me to enter the max value of teh column name which i have to enter.

如何在不提示的情况下固定& v_startval的值,而直接从下面的语句中设置值

How can I fix the value of &v_startval with out it prompting ,but directly setting the values from the below statement

select max(empid) from mytemp..

我在下面尝试这样

create sequence mytemp_seq start with (SELECT MAX(empid) from mytemp)

但这不起作用.

推荐答案

您可以使用一些PL/SQL来做到这一点:

You could do it with some PL/SQL:

declare
  v_startval integer;
begin
  select max(empid)+1 into v_startval from mytemp;
  execute immediate 'create sequence mytemp_seq start with ' || v_startval;
end;

这篇关于在oracle中创建序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆