如何使用with...as...构造SQL语句

如何使用with...as...构造SQL语句

WITH num AS (SELECT rownum rn FROM cat WHERE rownum <= 31),
         rec AS (SELECT decode(on_duty,'0','','1','√')||decode(rest_type,'0','','1','○')||
                        decode(absent_work,'0','','1','旷')||
                        decode(vacation_type_code,null,'', ( SELECT vacation_mark
                                                               FROM hr_c_vacationtype
                                                              WHERE vacation_type_code = wt.vacation_type_code ) )||
                        decode(overtime_type_code,null,'', ( SELECT overtime_mark
                                                               FROM hr_c_overtime
                                                              WHERE overtime_type_code = wt.overtime_type_code ) )  attend_state,
                        to_number(to_char(attendance_date,'dd')) attend_day
                   FROM hr_j_workattendance  wt
                  WHERE to_char(attendance_date,'yyyy-mm') = v_year||'-'||v_month AND
                        worker_code = v_worker_code
               ORDER BY attendance_date )
  SELECT rec.attend_state FROM num, rec
   WHERE (num.rn = rec.attend_day(+))
ORDER BY num.rn;
 
要注意,当需要with 多个临时结果时,必需写在一个with r_name as 。。。语句中,
不能写成 with a as (select * from table1)
with b as (select * from table2)
select a.*,b.*
from a,b
where a.id = b.id;
这样写是错误的。
 
正确的是:
with a as (select * from table1),
b as (select * from table2)
select a.*,b.*
from a,b
where a.id = b.id;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值