Oracle預存程序寫法

來源:互聯網
上載者:User

標籤:des   os   ar   for   資料   sp   on   c   ef   

create or replace procedure QIANFEIGL_JIAOKUANDY(

cebenh varchar2, kehuh varchar2, hetongh varchar2, v_cur  out query_pkg.Query_cur

)

is

SQLSTR VARCHAR2(3000);

begin  

  SQLSTR:=‘   select a.s_ch,a.s_cid,c.s_hetongh,a.d_caozuosj from zw_yingyez a left join kg_biaokaxx b on a.s_cid=b.s_cid   left join kg_zhanghuxx c on c.s_zhanghubh=b.s_zhanghubh   where i_xiaozhang=0‘ ;  

  if cebenh is not null and length(cebenh)>0 then    

    SQLSTR:=SQLSTR||‘ and a.s_ch=‘‘‘||cebenh||‘‘‘‘;    

   end if;  

   if hetongh is not null and length(hetongh)>0 then   

       SQLSTR:=SQLSTR||‘ and c.s_hetongh=‘‘‘||hetongh||‘‘‘‘;    

  end if;  

  if kehuh is not null and length(kehuh)>0 then    

     SQLSTR:=SQLSTR||‘ and a.s_cid=‘‘‘||kehuh||‘‘‘‘;    

  end if;    

   SQLSTR:=SQLSTR||‘ order by a.d_caozuosj desc‘;

OPEN V_CUR FOR SQLSTR;

end QIANFEIGL_JIAOKUANDY;

1、在Oracle中寫有返回資料集的預存程序要用遊標(CURSOR),在查詢語句前加 OPEN V_CUR FOR

2、沒有if...else...,可以用if...end if ; 形式進行判斷

3、可以在Oracle中聲明一個varchar2類型的變數,用它來存放SQL語句,中間可以進行字串拼接(用"||")

Oracle預存程序寫法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.