Oracel SQL Note - decode / case when / distinct clob / RAC flow

select case when c1 = 0 then c2 else c1 end col from
( select 1 c1  from dual ) t1
,  ( select 2 c2 from dual ) t2;

 

--Sample2
select * from
(
 select case when cnt > alert_threshold then 1 else 0 end td_alert from
 ( SELECT COUNT(1) as cnt FROM link_ctrl where link_id like 'PR_' ) t1
 ,  ( select alert_threshold from monitor_ctrl ) t2
),
(
 select case when cnt > alert_threshold then 1 else 0 end ts_alert from
 ( SELECT COUNT(1) as cnt FROM link_ctrl where link_id like 'PR_' ) t1
 ,  ( select alert_threshold from monitor_ctrl ) t2
);

--Sample3
select
      case
           when
HOUR = '09' then 'A1'
           when HOUR='11' then 'A2'
           when HOUR='13' then 'A3'
           when HOUR='15' then 'A4'
           when HOUR='17' then 'A5'
           when HOUR is null then msg_stas
           else 'Unknown'
      end DAY,
      msg_stas,
      cnt
from
(
select msg_stas, to_char(msg_tsm_dt, 'HH24') as HOUR, count(1) as cnt
from xxxua2.in_msg
where msg_cap_dt > to_date('04SEP 17:40','DDMON HH24:MI')
group by msg_stas,to_char(msg_tsm_dt, 'HH24')
order by msg_stas,to_char(msg_tsm_dt, 'HH24')
);


-- Alternative solution
select ctry_cde "Ctry code", msg_type "Message Type",
  decode(msg_stas,
    'AT', 'Accepted',
    'CL', 'Cancelled',
    'ER', 'Error',
    'HD', 'Hold',
    'PC', 'Pending approval - Cancel',
    'PR', 'Pending approval - Repair',
    'PT', 'Pending Transmit',
    'RD', 'Repaired',
    'TD', 'Transmitted',
    'WT', 'Waiting') "Status",
  count(*) "Count", to_char(sysdate,'yyyy-mm-dd HH24:MI:ss') "Fetched Datetime"
from xxx01pa1.out_msg
where 1 = 1
and last_udt_dt > to_date('2012-06-10 10:00:00','yyyy-mm-dd hh24:mi:ss')
and ctry_cde in ('SG','HK','TH','MY','BD','NZ')
group by ctry_cde,msg_type,msg_stas
order by ctry_cde,msg_type,msg_stas asc;


http://www.cnblogs.com/eshizhan/archive/2012/04/06/2435493.html 


? cannot distinct or unique on CLOB column type!!!
select unique (abc) from (
select substr(full_msg_txt , instr(full_msg_txt, '<d:FinInstrmId>') + length('<d:FinInstrmId>'), (instr(full_msg_txt,'</d:FinInstrmId>') - instr(full_msg_txt, '<d:FinInstrmId>')) - length('</d:FinInstrmId>') ) as abc from gdijpua2.in_msg_LISA
where  msg_cap_dt > (trunc(sysdate) -3) and msg_stas <> 'TD' and full_msg_txt not like '%JP3203500008%' /*and msg_id >= 5975112*/ order by msg_id desc
);

alternatively, you can use TO_CHAR() to resolve!

 


==


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值