P/L SQL 中 CASE 内的 IF 语句
Posted
技术标签:
【中文标题】P/L SQL 中 CASE 内的 IF 语句【英文标题】:IF statement inside the CASE in P/L SQL 【发布时间】:2013-01-06 11:26:27 【问题描述】:我试图在 CASE 中编写 IF 语句,但这给了我编译错误。这是我的代码的样子
(CASE
IF (acc_type_id_ = 'ENDU') THEN
WHEN PRODUCT_ID != product_id_ AND AVAIL_TO_SELL = 'YES' AND Enable_Add_To_Cart(PRODUCT_ID)='YES' AND PROD_ITEM_PKG.Get_Allow_Endu_Purch(PRODUCT_ID)='YES' THEN '&ACTION_ADD_TO_CART'
WHEN PRODUCT_ID = product_id_ AND AVAIL_TO_SELL = 'YES' AND Enable_Add_To_Cart(PRODUCT_ID)='YES' AND SELL_ONLY_LINKED != 'YES' AND PROD_ITEM_PKG.Get_Allow_Endu_Purch(PRODUCT_ID)='YES' THEN '&ACTION_ADD_TO_CART'
ELSE
WHEN PRODUCT_ID != product_id_ AND AVAIL_TO_SELL = 'YES' AND Enable_Add_To_Cart(PRODUCT_ID)='YES' THEN '&ACTION_ADD_TO_CART'
WHEN PRODUCT_ID = product_id_ AND AVAIL_TO_SELL = 'YES' AND Enable_Add_To_Cart(PRODUCT_ID)='YES' AND SELL_ONLY_LINKED != 'YES' THEN '&ACTION_ADD_TO_CART'
END IF;
ELSE '&ACTION_NO_ACTION'
END) ACTION2,
SQLPLUS 中的错误
( begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge
【问题讨论】:
这是程序的一部分吗? 【参考方案1】:这个呢?您可以使用acc_type_id_ = 'ENDU'
作为WHEN
条件的一部分来获得相同的结果。
(CASE
WHEN acc_type_id_ = 'ENDU' AND PRODUCT_ID != product_id_ AND AVAIL_TO_SELL = 'YES' AND Enable_Add_To_Cart(PRODUCT_ID)='YES' AND PROD_ITEM_PKG.Get_Allow_Endu_Purch(PRODUCT_ID)='YES' THEN '&ACTION_ADD_TO_CART'
WHEN acc_type_id_ = 'ENDU' AND PRODUCT_ID = product_id_ AND AVAIL_TO_SELL = 'YES' AND Enable_Add_To_Cart(PRODUCT_ID)='YES' AND SELL_ONLY_LINKED != 'YES' AND PROD_ITEM_PKG.Get_Allow_Endu_Purch(PRODUCT_ID)='YES' THEN '&ACTION_ADD_TO_CART'
WHEN acc_type_id_ != 'ENDU' AND PRODUCT_ID != product_id_ AND AVAIL_TO_SELL = 'YES' AND Enable_Add_To_Cart(PRODUCT_ID)='YES' THEN '&ACTION_ADD_TO_CART'
WHEN acc_type_id_ != 'ENDU' AND PRODUCT_ID = product_id_ AND AVAIL_TO_SELL = 'YES' AND Enable_Add_To_Cart(PRODUCT_ID)='YES' AND SELL_ONLY_LINKED != 'YES' THEN '&ACTION_ADD_TO_CART'
ELSE '&ACTION_NO_ACTION'
END) ACTION2,
【讨论】:
以上是关于P/L SQL 中 CASE 内的 IF 语句的主要内容,如果未能解决你的问题,请参考以下文章
SQL里if语句和case语句有啥区别吗?哪个使用更高效?就是查询更优化?