复杂oracle示例

select t.s_info_windcode,
    REPLACE(t.s_info_windcode,'.','') as pilot_product_id ,
    'BOND' as instrument_class ,
     (select s_info_industrycode from CBondIndustryWind where s_info_windcode= t.s_info_windcode) as instrument_subclass ,
     b_info_act as accrual_basis,
     b_info_term_year_ as b_info_term_year,
     b_issue_announcement as  announce_date,
     b_info_fullname as security_full_name,
     s_info_name as security_short_name,
     (select distinct b_tender_tenderdate from CBondTender where s_info_windcode=t.s_info_windcode) as auction_date,
     (select case count(1) when 0 then 'N' else 'Y' end from CBondCall where s_info_windcode= t.s_info_windcode) as callable,
     (select min(CBondCall.b_info_redemptiondate-b_info_callannouncementdate) from CBondCall where s_info_windcode= t.s_info_windcode 
      and b_info_callannouncementdate is not null and b_info_redemptiondate is not null  group by s_info_windcode ) as call_notify_days,
    'Calendar day' as call_notify_days_type,
    '' as call_schedule_date,
    (select listagg(b_info_redemptiondate) within group (order by b_info_redemptiondate) 
               from CBondCall  where s_info_windcode = t.s_info_windcode) as call_schedule_date_actual,
    (select listagg(b_info_redemptionprice,',') within group (order by b_info_redemptionprice) 
               from CBondCall  where s_info_windcode = t.s_info_windcode) as call_schedule_strike,
    (select listagg(b_info_paymentdate,',') within group (order by b_info_paymentdate) 
               from CBondPayment  where s_info_windcode = t.s_info_windcode) as coupon_schedule_date,
    (select listagg(b_info_interestperthousands/10,',') within group (order by b_info_interestperthousands) 
               from CBondPayment  where s_info_windcode = t.s_info_windcode) as coupon_schedule_interest,                      
    b_info_interestfrequency as coupon_frequency,
    crncy_code as currency  ,
    nvl(b_info_couponrate,0) as coupon ,
    (case t.b_info_interesttype when 501001000 then nvl(t2.rate, 0)  when 501002000 then  nvl(t.b_info_couponrate, 0) when 501003000 then nvl(t3.rate, 0) else 0 end) as current_coupon,
    '' as cusip ,
    (select s_info_min_price_chg_unit from WindCustomCode where s_info_windcode= t.s_info_windcode) as min_price_tick ,
    b_info_carrydate as dated_date ,
    s_info_exchmarket as ecn ,
    b_info_listdate as first_trade_date,
    b_info_delistdate as last_trade_date,
    (select case count(1) when 0 then 'N' else 'Y' end from Cbondfloatingrate where b_info_interestfloor is not null and s_info_windcode= t.s_info_windcode) as inflation_protected ,
    (select case count(1) when 0 then 'N' else 'Y' end  from CBondDescription x where x.s_info_formerwindcode=t.s_info_windcode) as is_reopen,
    (case when to_char(sysdate,'yyyymmdd') between b_issue_firstissue and b_issue_lastissue then 'Y' else 'N' end) as is_wi ,
    (case when b_info_coupon='505003000' and b_info_interesttype is null and b_info_couponrate is null then 'Y' else 'N' end ) as is_zero_coupon ,
    (select s_info_isincode from WindCustomCode where s_info_windcode= t.s_info_windcode) as isin ,
     b_issue_firstissue as  issue_date ,
     b_info_issuer as issuer ,
     b_info_maturitydate as maturity_date ,
     t.b_issue_amountact+(select nvl(sum(nvl(b_issue_amountact,0)),0) from  CBondDescription x 
      where x.s_info_formerwindcode=t.s_info_windcode and x.s_info_windcode not in (select s_info_ralatedcode from RalatedSecuritiesCode)) as original_qty ,
     b_info_coupondatetxt as payment_date_adjustment ,
     (select case count(1) when 0 then 'N' else 'Y' end from CBondPut where s_info_windcode= t.s_info_windcode) as putable,
     (select min(b_info_putannouncementdate-b_info_repurchasedate) from CBondPut where s_info_windcode= t.s_info_windcode 
      and b_info_putannouncementdate is not null and b_info_repurchasedate is not null  group by s_info_windcode ) as put_notify_days,
    'Calendar day'  as put_notify_days_type ,
    '' as put_schedule_date,
    
    (select listagg(b_info_repurchasedate,',') within group (order by b_info_repurchasedate) 
               from CBondPut  where s_info_windcode = t.s_info_windcode) as put_schedule_date_actual, 
    (select listagg(b_info_repurchaseprice,',') within group (order by b_info_repurchaseprice) 
               from CBondPut  where s_info_windcode = t.s_info_windcode) as put_schedule_strike, 
    'WIND' as source_system ,
    (select B_INFO_OUTSTANDINGBALANCE from(
    select b.S_INFO_WINDCODE, b.B_INFO_OUTSTANDINGBALANCE from CBondAmount b ,
    (select c.S_INFO_WINDCODE,MAX(c.S_INFO_ENDDATE) S_INFO_ENDDATE from CBondAmount c group by c.S_INFO_WINDCODE) a
    where b.S_INFO_WINDCODE=a.S_INFO_WINDCODE and b.S_INFO_ENDDATE=a.S_INFO_ENDDATE
    ) d where d.S_INFO_WINDCODE=t.S_INFO_WINDCODE) as remaining_qty 
from CBondDescription t,
(select x.s_info_windcode, x.rate
          from FloatingCouponsRate x,
               (select s_info_windcode, max(CHANGE_DT) rq
                  from FloatingCouponsRate
                 where CHANGE_DT < to_char(sysdate, 'yyyymmdd')
                 group by s_info_windcode) y
         where x.s_info_windcode = y.s_info_windcode) t2,
(select x.s_info_windcode, x.rate
          from OptionEmbeddedBondRate x,
               (select s_info_windcode, max(START_DT) rq
                  from OptionEmbeddedBondRate
                 where START_DT < to_char(sysdate, 'yyyymmdd')
                 group by s_info_windcode) y
         where x.s_info_windcode = y.s_info_windcode) t3
where t.s_info_windcode not in (select s_info_ralatedcode from RalatedSecuritiesCode) and t.S_INFO_FORMERWINDCODE is  null
 and substr(t.S_INFO_WINDCODE,instr(t.S_INFO_WINDCODE,'.',1)+1,length(t.S_INFO_WINDCODE)) in ('IB','SH','BC','SZ') and t.B_ISSUE_LASTISSUE<=to_char(sysdate,'yyyymmdd') 
 and t.s_info_windcode = t2.s_info_windcode(+) 
 and t.s_info_windcode = t3.s_info_windcode(+)
--and t.s_info_windcode = '150003.IB'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PL/SQL编程 pl/sql(procedural language/sql)是Oracle在标准的sql语言上的扩展。pl/sql不仅允许嵌入式sql语言,还可以定义变量和常量,允许使用条件语句和循环语句,允许使用例外处理各种错误。这样使得他的功能变的更强大。缺点是移植性不好。 编写一个存储过程,向表中添加数据。 1. create table mytest (name varchar2(30),passwd varchar2(30)); 2. create or replace procedure xxc_pro1 is begin insert into mytest values ('小红','m123'); end; 3. 调用过程 exec 过程名(参数1,参数2…)或call 过程名参数1,参数2…) ① exec xxc_pro1; 或者是 ② call xxc_pro1; pl/sql可以做什么? 块:包括过程、函数、触发器、包。 编写规范: 1. 注释 --:单行注释 eg:select * from emp where empno=7788;--取得员工信息 /*……*/多行注释 2. 表示符号(变量)的命名规范: ① 当定义变量时,建议用v_作为前缀:v_ename ② 当定义常量时,建议用c_作为前缀:c_rate ③ 当定义游标时,建议用_cursor作为后缀:emp_cursor ④ 当定义例外时,建议用e_作为前缀:e_error 块(block)是pl/sql的今本程序单元,编写pl/sql程序实际上就是在编写pl/sql块;pl/sql块由三部分组成:定义部分,执行部分,例外处理部分。 declare --可选部分 /*定义部分:定义常量,变量,游标,例外,复杂数据类型*/ begin --必选部分 /*执行部分:要执行的pl/sql语句和sql语句*/ exception --可选部分 /*例外处理部分:处理运行的各种错误*/ 实例1:只包含执行部分的pl/sql块 SQL> set serveroutput on --打开输出 SQL> begin 2 dbms_output.put_line('hello'); 3 end; 4 / 说明:dbms_output是oracle提供的包,该包包含一些过程,put_line就是其中之一。 实例2:包含定义部分和执行部分 SQL> declare 2 v_ename varchar2(5); 3 begin 4 select ename into v_ename from emp where empno = &no; 5 dbms_output.put_line('雇员名'||v_ename); 6 end; 7 / 说明:&:从控制台输入变量,会弹出一个对话框。 实例3.同时输出雇员名和工资 SQL> declare 2 v_ename varchar2(20); 3 v_sal number(10,2); 4 begin 5 select ename,sal into v_ename,v_sal from emp where empno=&no; 6 dbms_output.put_line('雇员名:'||v_ename||' 工资:'||v_sal); 7 end; 8 / 包含定义,执行,和例外处理的pl/sql块。 实例4.当输入的员工号不存在时 SQL> declare 2 v_ename varchar2(20); 3 v_sal number(10,2); 4 begin 5 select ename,sal into v_ename,v_sal from emp where empno =&no; 6 dbms_output.put_line('雇员名:'||v_ename||' 工资:'||v_sal); 7 exception --异常处理部分 8 when no_data_found then 9 dbms_output.put_line('请输入正确的员工号!'); 10 end; 11 / 以上为块的基础,下面来介绍块的各个组成:过程,函数,触发器,包。 过程 过程用于执行特定的操作,当执行过程的时候,可以指定输入参数(in),也可以指定输出参数(out)。通过在过程中使用输入参数,可以讲数据输入到执行部分,通过使用输出参数,可以将执行部分的数据输出到应用环境,在pl/sql中可以使用create procedure命令来创建过程。 编写一个存储过程,可以输入雇员名和新工资来改变员工工资。 --案例 create or replace procedure xxc_pro3(newname in varchar2,newsal in number) is begin update emp set sal=newsal where ename=newname; end;

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值