【问题标题】:Insert seq.nextval and other distinct values插入 seq.nextval 和其他不同的值
【发布时间】:2012-10-04 10:56:10
【问题描述】:

我想对现有的存储过程进行一些更改;在表中插入值,第一个值将来自序列,其他值必须是不同的。

create SP_Emp()
.......
insert into table_emp(primary_key,name,dept,sal,id)
select distict
seq_emp.nextval,
first_value(name) over partition by(id),
id as id,
.....
.....
END;

它给出的错误是这里不允许使用序列号。

我想插入值,保持 seq.nextval 和行中的所有其他值不同

以前的程序是:

create SP_Emp()
.......
insert into table_emp(name,dept,sal,id)

select distict

first_value(name) over partition by(id),
id as id,
.....
.....

END;

【问题讨论】:

    标签: oracle plsql


    【解决方案1】:

    将您的 SQL 语句包装在括号中作为内联视图,然后添加序列:

    create SP_Emp()
    .......
    insert into table_emp(primary_key,name,dept,sal,id)
    select seq_emp.nextval, s.*
    from (
        select distinct
        first_value(name) over partition by(id),
        id as id,       
    .....
            ) s
    .....
    END;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-09
      • 1970-01-01
      • 2018-12-02
      • 1970-01-01
      • 1970-01-01
      • 2021-05-21
      • 1970-01-01
      相关资源
      最近更新 更多