加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle中select中的序列和大小写

发布时间:2020-12-12 16:25:45 所属栏目:百科 来源:网络整理
导读:我正在尝试执行此查询(在oracle中),但我遇到了一些问题: SELECT CASE WHEN deptno = '10' THEN scott.seq.nextval || 'next10' WHEN deptno = '20' THEN scott.seqnextval || 'next20' WHEN deptno = '30' THEN scott.seq.currval || 'curr' END col_1 FROM
我正在尝试执行此查询(在oracle中),但我遇到了一些问题:
SELECT CASE 
         WHEN deptno = '10' THEN scott.seq.nextval 
                                  || 'next10' 
         WHEN deptno = '20' THEN scott.seqnextval 
                                  || 'next20' 
         WHEN deptno = '30' THEN scott.seq.currval 
                                  || 'curr' 
       END col_1 
FROM   scott.emp;

我得到了这个结果:

COL_1
----------------------------------------------
191next20
192curr
193curr
194next20
195curr
196curr
197next10
198next20
199next10
200curr
201next20
202curr
203next20
204next10
205next20
206next10
207next10

这就是我认为它们应该是:

COL_1
----------------------------------------------
191next20
192curr
193curr
194next20
194curr
194curr
197next10
198next20
199next10
199curr
201next20
201curr
203next20
204next10
205next20
206next10
207next10

那么,为什么我在得到当前值时获得序列的下一个值,而不仅仅是当案例选择下一个值时?
是的,这可以用plsql脚本完成,但我不能.

谢谢!

有趣.根据Oracle docs:

The statements in a WHEN clause can modify the database and call
non-deterministic functions. There is no fall-through mechanism as in
the C switch statement

请注意,它没有说明“true”WHEN子句中的语句.因此,即使when语句为false,nextval也会触发:

select
case when 1=0 then 'next ' || seq_id.nextval
     when 1=1 then 'curr ' || seq_id.currval
end col1
from dual;

我必须承认这与我的预期不同.

编辑:请参阅ShannonSeverance的回答

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读