无法将值传递给oracle中的游标?

时间:2015-03-13 11:13:01

标签: sql oracle plsql oracle11g

CREATE OR REPLACE PROCEDURE OM_TEST AS 
 CURSOR lcu_cust_site_ship (
                                p_cust_account_id  IN  NUMBER
                              , p_location_ship    IN  VARCHAR2
                              )
    IS
        SELECT HCSU.site_use_id
        FROM   hz_cust_site_uses_all HCSU, hz_cust_acct_sites_all CAS
        WHERE  HCSU.location   = p_location_ship
        AND    HCSU.SITE_USE_CODE = 'SHIP_TO'
        AND    HCSU.cust_acct_site_id = CAS.cust_acct_site_id
        AND    CAS.cust_account_id = p_cust_account_id;


ln_cust_site_ship   NUMBER:=0;

BEGIN
 OPEN lcu_cust_site_ship (217162, lr_om_order_index.ship_to_location);
 FETCH lcu_cust_site_ship INTO ln_cust_site_ship;

 CLOSE lcu_cust_site_ship;
 DBMS_OUTPUT.PUT_LINE  ('lr_om_order_index.ship_to_location: '||lr_om_order_index.ship_to_location);
 DBMS_OUTPUT.PUT_LINE  ('ln_cust_site_ship: '||ln_cust_site_ship);
 EXCEPTION
            WHEN OTHERS THEN
                DBMS_OUTPUT.PUT_LINE ('ERROR IN SHIP TO LOCATION ');
 END;

此处lr_om_order_index是一个记录索引,其中包含出货地价值。

现在得到的输出是

  

lr_om_order_index.ship_to_location:6698

     

ln_cust_site_ship:

     

船舶错误到位置。

请帮助并指导我。我无法找出错误。

  

如果我在

中传递值6698而不是lr_om_order_index.ship_to_location      

光标,然后它正常工作。

2 个答案:

答案 0 :(得分:0)

在DBMS_OUT之后关闭光标应该有帮助

答案 1 :(得分:0)

以下代码有效,因此您的问题很可能是位置列数据类型与lr_om_order_index记录类型不匹配。你应该检查两个声明。可能ship_to_location是CHAR或类似问题

cREATE OR REPLACE PROCEDURE OM_TEST AS 
CURSOR lcu_cust_site_ship (
                            p_cust_account_id  IN  NUMBER
                          , p_location_ship    IN  VARCHAR2
                          )
IS
    SELECT 1 as site_use_id
    FROM   dual
    WHERE  6698   = p_location_ship;

 ln_cust_site_ship   NUMBER:=0;

  BEGIN
    for lr_om_order_index in (select to_char(6698) ship_to_location from     dual) loop

 OPEN lcu_cust_site_ship (217162, lr_om_order_index.ship_to_location);
 FETCH lcu_cust_site_ship INTO ln_cust_site_ship;

 CLOSE lcu_cust_site_ship;
 DBMS_OUTPUT.PUT_LINE  ('lr_om_order_index.ship_to_location:    '||lr_om_order_index.ship_to_location);
DBMS_OUTPUT.PUT_LINE  ('ln_cust_site_ship: '||ln_cust_site_ship);
end loop;

EXCEPTION
        WHEN OTHERS THEN
            DBMS_OUTPUT.PUT_LINE ('ERROR IN SHIP TO LOCATION ');
END;