2015-07-13 68 views
1

這裏執行過載存儲過程是我的程序:問題在PL/SQL

CREATE OR REPLACE PACKAGE shop_query_pkg IS 
    PROCEDURE shop_info_pp 
    (p_id IN bb_shopper.idshopper%TYPE, 
    p_firstname OUT bb_shopper.firstname%TYPE, 
    p_city OUT bb_shopper.city%TYPE, 
    p_state OUT bb_shopper.state%TYPE, 
    p_phone OUT bb_shopper.phone%TYPE, 
    p_email OUT bb_shopper.email%TYPE); 
    PROCEDURE shop_info_pp 
    (p_id IN bb_shopper.lastname%TYPE, 
    p_firstname OUT bb_shopper.firstname%TYPE, 
    p_city OUT bb_shopper.city%TYPE, 
    p_state OUT bb_shopper.state%TYPE, 
    p_phone OUT bb_shopper.phone%TYPE, 
    p_email OUT bb_shopper.email%TYPE); 
END; 
/
CREATE OR REPLACE PACKAGE BODY shop_query_pkg IS 
    PROCEDURE shop_info_pp 
    (p_id IN bb_shopper.idshopper%TYPE, 
    p_firstname OUT bb_shopper.firstname%TYPE, 
    p_city OUT bb_shopper.city%TYPE, 
    p_state OUT bb_shopper.state%TYPE, 
    p_phone OUT bb_shopper.phone%TYPE, 
    p_email OUT bb_shopper.email%TYPE) 
    IS 
    BEGIN 
     SELECT firstname, city, state, phone, email 
     INTO p_firstname, p_city, p_state, p_phone, p_email 
     FROM bb_shopper 
     WHERE idshopper = p_id; 
    EXCEPTION 
     WHEN NO_DATA_FOUND THEN 
     DBMS_OUTPUT.PUT_LINE('ID does not exist'); 
    END;  
    PROCEDURE shop_info_pp 
    (p_id IN bb_shopper.lastname%TYPE, 
    p_firstname OUT bb_shopper.firstname%TYPE, 
    p_city OUT bb_shopper.city%TYPE, 
    p_state OUT bb_shopper.state%TYPE, 
    p_phone OUT bb_shopper.phone%TYPE, 
    p_email OUT bb_shopper.email%TYPE) 
    IS 
    BEGIN 
     SELECT firstname, city, state, phone, email 
     INTO p_firstname, p_city, p_state, p_phone, p_email 
     FROM bb_shopper 
     WHERE lastname = p_id; 
    EXCEPTION 
     WHEN NO_DATA_FOUND THEN 
     DBMS_OUTPUT.PUT_LINE('Last name does not exist'); 
    END; 
END; 

然而,當我嘗試使用此代碼來執行我的程序:

VARIABLE g_fname VARCHAR2 
VARIABLE g_city VARCHAR2 
VARIABLE g_state VARCHAR2 
VARIABLE g_phone VARCHAR2 
VARIABLE g_email VARCHAR2 

EXECUTE shop_query_pkg.shop_info_pp(23, :g_fname, :g_city, :g_state, :g_phone, :g_email); 

PRINT :g_fname 
PRINT :g_city 
PRINT :g_state 
PRINT :g_phone 
PRINT :g_email 

我收到此錯誤信息:

BEGIN shop_query_pkg.shop_info_pp(23, :g_fname, :g_city, :g_state, :g_phone, :g_email); END; 

* 
ERROR at line 1: 
ORA-06502: PL/SQL: numeric or value error 
ORA-06512: at "S36.SHOP_QUERY_PKG", line 11 
ORA-06512: at line 1 

我覺得我的select語句有些問題,但我一直在檢查它,我無法弄清楚wha這是錯的。

這裏是DESC bb_shopper:

Name Null? Type 
IDSHOPPER NOT NULL NUMBER(4) 
FIRSTNAME  VARCHAR2(15) 
LASTNAME  VARCHAR2(20) 
ADDRESS  VARCHAR2(40) 
CITY  VARCHAR2(20) 
STATE  CHAR(2) 
ZIPCODE  VARCHAR2(15) 
PHONE  VARCHAR2(10) 
FAX  VARCHAR2(10) 
EMAIL  VARCHAR2(25) 
USERNAME  VARCHAR2(8) 
PASSWORD  VARCHAR2(8) 
COOKIE  NUMBER(4) 
DTENTERED  DATE 
PROVINCE  VARCHAR2(15) 
COUNTRY  VARCHAR2(15) 
PROMO  CHAR(1) 

是的,我已經嘗試改變狀態爲CHAR,我也得到了同樣的信息。

+0

你需要充分地描述你的'bb_shopper'表。列,數據類型等 – sstan

+0

想想我想通了,我不明白爲什麼,但我不得不使用匿名塊來執行它。 –

+0

程序的第一個和第二個版本之間有什麼區別?重載的過程需要有不同的簽名 - 至少有一個參數需要不同的類型/名稱。 – Rusty

回答

0

您必須完全指定VARIABLE類型並添加最大的varchar2大小。

如果您使用以下塊,它按預期工作:

VARIABLE g_fname VARCHAR2(60) 
VARIABLE g_city VARCHAR2(60) 
VARIABLE g_state VARCHAR2(60) 
VARIABLE g_phone VARCHAR2(60) 
VARIABLE g_email VARCHAR2(60) 

EXECUTE shop_query_pkg.shop_info_pp(23, :g_fname, :g_city, :g_state, :g_phone, :g_email); 

PRINT :g_fname 
PRINT :g_city 
PRINT :g_state 
PRINT :g_phone 
PRINT :g_email