Oracle Stored procedure notation

Source: Internet
Author: User
Tags joins

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 joins Kg_biaokaxx B on A.s_cid=b.s_cid Left joins 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. A stored procedure with a return data set written in Oracle is to be used with a cursor, and an OPEN v_cur for in front of the query statement

2, no if...else ..., can be used if...end if; form to judge

3, you can declare a variable of type VARCHAR2 in Oracle, use it to hold SQL statement, the middle can be string concatenation (with "| |" )

Oracle Stored procedure notation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.