plsql 开发手记 游标,动态sql ,自定义集合

 

CREATE OR REPLACE PROCEDURE applypeople (v_planid IN  NUMBER,v_p_cur out types.cursorType) is
        
    xm split_type;
    v_count NUMBER;
    v_app_apply app_apply%ROWTYPE;
    CURSOR  my_cur IS  SELECT  person.ID AS ID, 
		person.sfz as sfz ,
		
		person.khxm  as ksxm
     
		FROM app_apply person ,app_plan p ,pla_tenant t

		WHERE person.zt=3 
		AND person.plan_id = v_planid
		AND person.plan_id = p.ID AND person.tenant_id = t.ID ORDER BY person.Id;
begin
     
      EXECUTE IMMEDIATE'CREATE  table cellBusyHour_temp as 
       SELECT person.id as pid, person.plan_id as bcid,p.name as bcname, person.NAME as xm ,
		   person.sfz as sfz ,
		   t.tenantname  as tenant,
		   person.khxm  as ksxm
     
		   FROM app_apply person ,app_plan p ,pla_tenant t

		    WHERE person.zt=3 
		    AND person.plan_id = '||v_planid||'
		    AND person.plan_id = p.ID AND person.tenant_id = t.ID order by person.id';   
     
     
       --init the xm 
     xm:=split_type();
    
    
     -- fetch the id of  the appliers
     FOR v_app_apply IN my_cur LOOP
          --dynamic  init the xm
         
          SELECT split(khxm,',') INTO xm FROM app_apply WHERE app_apply.ID = v_app_apply.ID;
         --  to deal with the v_str
          FOR i IN 1..xm.COUNT LOOP
              IF xm(i) IS NOT NULL THEN 
                       --judege the column if exists
                      select count(*) into v_count from User_Tab_Columns where table_name=upper('cellBusyHour_temp') and column_name=upper('khxm'||i);
                      IF v_count=0 THEN 
                      --add the  column 
                    EXECUTE IMMEDIATE'alter table cellBusyHour_temp add (khxm'||i||'  varchar(50))';
                    END IF;
              EXECUTE IMMEDIATE'update cellBusyHour_temp set khxm'||i||'='||''''||xm(i)||''''||'  where cellBusyHour_temp.pid='||v_app_apply.ID;
             
         
              END IF;
              END LOOP;
     
   
  
     
     END LOOP;
     
     -- open the cur
    OPEN v_p_cur FOR 'SELECT * FROM cellBusyHour_temp';
    EXECUTE IMMEDIATE 'drop TABLE cellBusyHour_temp';
    
   
		
end ;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值