PL / SQL数字或值错误:字符到数字转换错误

时间:2016-11-28 18:01:15

标签: sql oracle plsql

程序代码:

CREATE OR REPLACE PROCEDURE GetOrder(
p_Order IN NUMBER, 
p_OrderDate OUT DATE, 
p_CusNbr OUT NUMBER, 
p_OrderOut OUT NUMBER, 
p_Name OUT VARCHAR2, 
p_Address OUT VARCHAR2,
p_City OUT VARCHAR2, 
p_State OUT CHAR,
p_Zip OUT NUMBER,
p_Itm OUT NUMBER,
p_Desc OUT VARCHAR2,
p_Qty OUT NUMBER,
p_Price OUT NUMBER) 
AS
v_OrderDate ord.ord_date%type;
v_CusNbr ord.Cus_nbr%type;
v_Order ord.Ord_nbr%type;
v_Name cus.cus_nme%type;
v_Address cus.str_adr%type;
v_City zip.city%type;
v_state zip.st%type;
v_Zip zip.zip%type;
v_Itm itm.itm_nbr%type;
v_Desc itm.ITM_DSC%TYPE;
v_Qty ord_itm.ord_Qty%type;
v_Price itm.ord_itm_price%type;
BEGIN
SELECT O.ORD_NBR, C.CUS_NBR, O.ORD_DATE, C.CUS_NME, C.STR_ADR, Z.CITY, Z.ST, I.ITM_NBR, I.ITM_DSC, OI.ORD_QTY, I.ORD_ITM_PRICE
       INTO
       v_Order, v_CusNbr, v_OrderDate, v_Name, v_Address, v_Zip, v_state, v_Itm, v_Desc, v_Qty, v_Price
FROM ITM I JOIN ORD_ITM OI ON (I.ITM_NBR = OI.ITM_NBR) 
           JOIN ORD O ON (OI.ORD_NBR = O.ORD_NBR)
           JOIN CUS C ON (O.CUS_NBR = C.CUS_NBR)
           JOIN ZIP Z ON (C.ZIP_ADR = Z.ZIP)
WHERE O.ORD_NBR = p_Order;
DBMS_OUTPUT.PUT_LINE('ILLINOIS COMPUTERS');
DBMS_OUTPUT.PUT_LINE('CUSTOMER ORDER FORM');
DBMS_OUTPUT.PUT_LINE(v_Order || v_OrderDate || v_CusNbr);
DBMS_OUTPUT.PUT_LINE('Name: ' || v_Name);
DBMS_OUTPUT.PUT_LINE('Address: ' || v_Address);
DBMS_OUTPUT.PUT_LINE('City: ' || v_City || ' State : ' || v_state || ' Zip: ' || v_Zip);
DBMS_OUTPUT.PUT_LINE('Item No.' || 'Description' || 'Quantity' || 'Price');
DBMS_OUTPUT.PUT_LINE(v_Itm || v_Desc || v_Qty || v_Price);
END GetOrder;
/

当我打电话给程序时:

DECLARE
    p_OrderNbr NUMBER := &ordernumber;
    p_OrderDateOutput   DATE;
    p_CusNbrOutput      NUMBER;
    p_OrderNbrOutput    NUMBER;
    p_NameOutput        cus.cus_nme%type; 
    p_AddressOutput     cus.str_adr%type;
    p_CityOutput        zip.city%type; 
    p_StateOutput       CHAR;
    p_ZipOutput         NUMBER;
    p_ItmOutput         NUMBER;
    p_DescOutput        itm.itm_dsc%type;
    p_QtyOutput         NUMBER;
    p_PriceOutput       NUMBER;
begin
    GetOrder(p_OrderNbr, 
    p_OrderDateOutput, 
    p_CusNbrOutput, 
    p_OrderNbrOutput,
    p_NameOutput,
    p_AddressOutput,
    p_CityOutput,
    p_StateOutput, 
    p_ZipOutput,
    p_ItmOutput,
    p_DescOutput,  
    p_QtyOutput, 
    p_PriceOutput);
END;
/

我正在

  

ORA-06502错误:数字或值错误:字符到数字   转换错误。

我相信我的所有参数都是有序的,所以我没有得到冲突的变量赋值。

我单独运行此查询以确保我获得正确的输出并且工作正常。

SELECT O.ORD_NBR, C.CUS_NBR, O.ORD_DATE, C.CUS_NME, C.STR_ADR, Z.CITY, Z.ST, I.ITM_NBR, I.ITM_DSC, OI.ORD_QTY, I.ORD_ITM_PRICE
       --INTO
       --v_Order, v_CusNbr, v_OrderDate, v_Name, v_Address, v_Zip, v_state, v_Itm, v_Desc, v_Qty, v_Price
FROM ITM I JOIN ORD_ITM OI ON (I.ITM_NBR = OI.ITM_NBR) 
           JOIN ORD O ON (OI.ORD_NBR = O.ORD_NBR)
           JOIN CUS C ON (O.CUS_NBR = C.CUS_NBR)
           JOIN ZIP Z ON (C.ZIP_ADR = Z.ZIP)
WHERE O.ORD_NBR = 100;

1 个答案:

答案 0 :(得分:0)

选择列表说

 ... C.STR_ADR, Z.CITY, Z.ST, ...

进入列表说

 ... v_Address, v_Zip, v_state ...

似乎你在Z表中得到了错误的字段。

除非Z.CITY是数字邮政编码?