zoukankan      html  css  js  c++  java
  • 动态语句创建游标的问题

    游标不支持用动态语句打开,使用游标变量可以,但动态语句中的表名本身不确定的情况下无法确定行变量,
    最终使用原始表作为行变量模板,问题解决。

    curdatestr varchar2(50):=to_char(sysdate,'yyyy-mm-dd hh24:mi:ss');
            isexists number:=0;
        s_sql varchar2(30000);
        type t_cursor is ref cursor;
             c_job t_cursor;
             c_row TB_TRADE_EX%rowtype;   --这里tb_trade_ex作为行模板,这个表是确定的,字段跟动态生成的表完全一样
             begin
               s_sql:='select * from TB_TRADE_EX_'||sid||'  where TE_SELLER_NICK=''cntaobao'||sellerNick||''' and datachangedate > to_date('''||curdatestr||''',''yyyy-mm-dd hh24:mi:ss'')-1';  
                  open c_job for s_sql;
                  loop
                       fetch c_job into  c_row;
                       exit when c_job%notfound;
                       s_sql:='
                       select count(1)  from TB_TRADE_EX_'||sid||' @dblink183 
                           where  TE_NICK=:TE_NICK AND TE_BUYER_NICK = :TE_BUYER_NICK AND TE_TID= :TE_TID AND TE_STATUS=:TE_STATUS and te_date=:te_date';
                       execute immediate s_sql into isexists 
                        using c_row.TE_NICK,c_row.TE_BUYER_NICK,c_row.TE_TID,c_row.TE_STATUS,c_row.TE_DATE;  
                           if(isexists=0) then
                           s_sql:='
                             INSERT INTO TB_TRADE_EX_'||sid||' @dblink183 ( 
                              TE_SELLER_NICK ,
                              TE_NICK ,
                              TE_BUYER_NICK ,
                              TE_TID ,
                              TE_STATUS ,
                              TE_CHATLOG_BEGIN_TIME ,
                              TE_CHATLOG_END_TIME ,
                              TE_DATE ,
                              TE_ORDER_SUCCESS_TIME ,
                              TE_CREATED 
                               ) 
                              VALUES (:TE_SELLER_NICK,:TE_NICK,:TE_BUYER_NICK,:TE_TID,:TE_STATUS,
                              :TE_CHATLOG_BEGIN_TIME,:TE_CHATLOG_END_TIME,:TE_DATE,:TE_ORDER_SUCCESS_TIME,:TE_CREATED)'
                              ;
                             execute immediate s_sql 
                             using c_row.TE_SELLER_NICK,c_row.TE_NICK,c_row.TE_BUYER_NICK,c_row.TE_TID,c_row.TE_STATUS,
                              c_row.TE_CHATLOG_BEGIN_TIME,c_row.TE_CHATLOG_END_TIME,c_row.TE_DATE,c_row.TE_ORDER_SUCCESS_TIME,c_row.TE_CREATED;
                              commit;
                            end if;
                       
                    end loop;
                   close c_job;
  • 相关阅读:
    mojo 接口示例
    MojoliciousLite: 实时的web框架 概述
    接口返回json
    centos 6.7 perl 版本 This is perl 5, version 22 安装DBI DBD
    centos 6.7 perl 5.22 安装DBD 需要使用老的perl版本
    商业智能改变汽车行业
    商业智能改变汽车行业
    读MBA经历回顾(上)目的决定手段——北漂18年(48)
    perl 升级到5.20版本
    Group Commit of Binary Log
  • 原文地址:https://www.cnblogs.com/terrorpig/p/2534978.html
Copyright © 2011-2022 走看看