預存程序使用動態資料指標一例

來源:互聯網
上載者:User

標籤:ref cursor   動態資料指標   

資料表結構如下;

SQL> desc record;
Name        Type         Nullable Default Comments
----------- ------------ -------- ------- --------
RECORD_GUID VARCHAR2(50) Y                        
DNIS        VARCHAR2(15) Y                        
ANI         VARCHAR2(15) Y                        
STARTTIME   DATE         Y                        
ENDTIME     DATE         Y                        
STAFFID     VARCHAR2(10) Y                        
AGENTID     VARCHAR2(10) Y                        
EXTENSION   VARCHAR2(20) Y

 

嘗試顯示指定電話和某年月份的電話記錄,採用預存程序實現

create or replace procedure proc_getrecord(i_dnis in varchar2,                                           i_time in varchar2)/*功能:尋找某月電話記錄參數說明:i_dnis為主叫號碼,i_time為某年月份(例如201401)編寫日期:2014.06.26*/assqlstr varchar2(5000);begin  declare    type rc is ref cursor;    c_rc rc;    r_record record%rowtype;  begin   sqlstr:=‘select * from king.record where dnis =:1’||           ‘ and replace(substr(starttime, 1, 7), ‘‘-‘‘, ‘‘‘‘)=:2‘;   open c_rc for sqlstr using i_dnis,i_time;   fetch c_rc into r_record;   while c_rc%found loop       dbms_output.put_line(       ‘開始時間:‘||r_record.starttime||‘  ‘||       ‘結束時間:‘||r_record.endtime||‘  ‘||       ‘主叫號碼:‘||r_record.dnis||‘  ‘||       ‘被叫號碼:‘||r_record.ani);    fetch c_rc into r_record;    end loop;    close c_rc;  end;end;

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.