oracle过程的多值

时间:2018-07-11 12:07:28

标签: sql oracle plsql oracle11g

我想在Oracle 11g的p_so_code中用SO in (A,B,C)添加多值。

    PROCEDURE get_one_so (
         p_SO_CODE in String,
         RES OUT SYS_REFCURSOR
    )
        AS
    BEGIN
        OPEN RES FOR 

       SELECT
            so.so_code as SOCODE,
            cus.customer_code as CUSTOMERCODE,            
            cus.customer_name as CUSTOMERNAME,
            cus.email as EMAIL,            
            so.receiver_name as RECEIVERNAME,
            so.receiver_phone as RECEIVERPHONE,
            so.receiver_address as RECEIVERADDRESS,
            so.commment as COMMMENT,
            s.name as STAFFCREATE,     
                        to_char( so.CREATED_DATE,'dd/mm/yyyy') as CREATEDDATE,
            st.name as STAFFUPDATE,
            to_char(so.updated_date,'dd/mm/yyyy') as UPDATEDATE,
            sapp.name as STAFFAPPROVE,
           status,            
                so.reason_reject as REASONREJECT,
            so.payment as PAYMENY,
            to_char(so.send_date,'dd/mm/yyyy')   as SENDDATE,
            to_char(so.sended_date,'dd/mm/yyyy')   as SENDEDATE,
            so.staff_comment as STAFFCOMMENT

                     FROM

            saleorders so join customer cus on so.customer_code = cus.customer_code
            left join saleorderDetail sod on so.so_code = sod.so_code
            left join staff s on so.staff_create = s.staff_code
            left join staff st on so.staff_update = st.staff_code
            left join staff sapp on so.STAFF_APPROVE = sapp.staff_code
        WHERE
            so.SO_CODE in p_SO_CODE 
    END;

END package_saleoders;

我尝试了replace (p_so_code,(','),(''',''')),但这没用。

1 个答案:

答案 0 :(得分:1)

在p_so_code中断开逗号分隔的值以返回多行值,然后在您的in子句中使用它

PROCEDURE get_one_so (
     p_SO_CODE in String,
     RES OUT SYS_REFCURSOR
)
    AS
BEGIN
    OPEN RES FOR 

   SELECT
        so.so_code as SOCODE,
        cus.customer_code as CUSTOMERCODE,            
        cus.customer_name as CUSTOMERNAME,
        cus.email as EMAIL,            
        so.receiver_name as RECEIVERNAME,
        so.receiver_phone as RECEIVERPHONE,
        so.receiver_address as RECEIVERADDRESS,
        so.commment as COMMMENT,
        s.name as STAFFCREATE,     
                    to_char( so.CREATED_DATE,'dd/mm/yyyy') as CREATEDDATE,
        st.name as STAFFUPDATE,
        to_char(so.updated_date,'dd/mm/yyyy') as UPDATEDATE,
        sapp.name as STAFFAPPROVE,
       status,            
            so.reason_reject as REASONREJECT,
        so.payment as PAYMENY,
        to_char(so.send_date,'dd/mm/yyyy')   as SENDDATE,
        to_char(so.sended_date,'dd/mm/yyyy')   as SENDEDATE,
        so.staff_comment as STAFFCOMMENT
    FROM
        saleorders so join customer cus on so.customer_code = cus.customer_code
        left join saleorderDetail sod on so.so_code = sod.so_code
        left join staff s on so.staff_create = s.staff_code
        left join staff st on so.staff_update = st.staff_code
        left join staff sapp on so.STAFF_APPROVE = sapp.staff_code
    WHERE
        so.so_code IN (SELECT regexp_substr(p_so_code, '[^,]+', 1, LEVEL) 
                         FROM dual 
                      connect by regexp_substr(p_SO_CODE, '[^,]+', 1, level) is not null);

END;