Josh Josh - 5 days ago 5
SQL Question

PL/SQL Numeric or value error: character to number conversion error

Procedure Code:

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;
/


And when I call the procedure:

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;
/


I'm getting


ORA-06502 error: numeric or value error: character to number
conversion error.


I believe all my parameters are in order so I'm not getting conflicting variable assignments.

I ran this query seperately to make sure I'm getting the right output and it works fine.

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;

Answer

Select list says

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

Into list says

 ... v_Address, v_Zip, v_state ...

Seems you got the wrong field in Z table.

Unless Z.CITY is the numeric zip code?

Comments