case语句在sql, pl/sql的异同点。我犯错了,希望不要误导大家。散分100

codearts 2008-10-28 05:48:07
原来一直以为case 只是在sql中而不是pl/sql的,今天发现自已错了。

标准sql中case的写法:
select case
when 1=1 then ..
when 2=2 then
else ..
end
from dual;

pl/sql中case的写法:
case
when 1=1 then...
when 2=2 then ...
else ...
end case;

关键是pl/sql中的case 在end时要多写个case.

散分100
...全文
495 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
YY_MM_DD 2008-10-29
  • 打赏
  • 举报
回复
估计递减到我这没有分了,还是支持楼主
buffon1260 2008-10-29
  • 打赏
  • 举报
回复
LZ是大大大好人,learn and get point
范佩西_11 2008-10-29
  • 打赏
  • 举报
回复
jf
rexyudl 2008-10-29
  • 打赏
  • 举报
回复
接分
behrman 2008-10-29
  • 打赏
  • 举报
回复
CASE比decode的结构更清晰,而且更适合情况较多时用。
zymhdboy 2008-10-29
  • 打赏
  • 举报
回复
楼主好人,mantisxf也是好人,学习了接分
hongqi162 2008-10-29
  • 打赏
  • 举报
回复
jf
wufuming1 2008-10-29
  • 打赏
  • 举报
回复
学习了,接分~!
Andy__Huang 2008-10-29
  • 打赏
  • 举报
回复
楼主好人啊!

接分
ruihuahan 2008-10-29
  • 打赏
  • 举报
回复
sql 与 pl/sql
sjq521521 2008-10-29
  • 打赏
  • 举报
回复
LZ好人啊,学习并接分。
hong1987 2008-10-28
  • 打赏
  • 举报
回复
学习
jdsnhan 2008-10-28
  • 打赏
  • 举报
回复
两者是不一样的
select case
when 1=1 then ..
when 2=2 then
else ..
end
from dual;
此时的case是作为函数使用,对应的case when then end; 作为函数,可以与decode互换


case
when 1=1 then...
when 2=2 then ...
else ...
end case;
是作为语句控制体使用 对应的是case ...end case; 作为控制语句,可以与if elsif else end if 互换
DongloveRen 2008-10-28
  • 打赏
  • 举报
回复
学习,多谢楼主的帖子!
sleepzzzzz 2008-10-28
  • 打赏
  • 举报
回复
pl/sql过程中,喜欢这一段:

text := case n when 1 then one
   when 2 then two
   when 3 then three
   else other
end case;
sleepzzzzz 2008-10-28
  • 打赏
  • 举报
回复
学习兼接分
ab5669 2008-10-28
  • 打赏
  • 举报
回复
up
yf520gn 2008-10-28
  • 打赏
  • 举报
回复
友情帮顶!
icss_zhen 2008-10-28
  • 打赏
  • 举报
回复
呵~~这个我也知道。支撑下!!!!
leiru 2008-10-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 mantisXF 的回复:]
SQL codePL/SQL 中 CASE 语句的使用
虽然 CASE 结构基本上没有给出任何新的语义,但它们的确接受一种更简洁的表示法,并且相对于 IF 结构表示法而言消除了一些重复。看下面的判定表的执行情况,是依据特殊表达式的值来决定执行情况。程序段…

case n when 1 then Action1;
when 2 then Action2;
when 3 then Action3;
else ActionOther;end case;
…和…

if
n = 1 then Action1; elsif n = 2 then Actio…
[/Quote]

学习了,接分~!
加载更多回复(3)

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧