存储过程中的 ORA-06502
ORA-06502 in a stored procedure
你好,我有一个简单的程序,可以很好地编译,但是在我初始化变量之后,错误是这样的。
table是这样创建的
Create table vcelar_pomocky
(
cislo_nakupu Number(5,0) NOT NULL ,
cislo_ula Number(5,0) NOT NULL ,
rodne_cislo Varchar2 (30) NOT NULL ,
datum_nakupu Date NOT NULL ,
nazov Varchar2 (20) NOT NULL ,
typ_polozky Varchar2 (20) NOT NULL ,
cena_polozky Number(5,2) NOT NULL ,
primary key (cislo_nakupu)
)
/
程序如下所示:
CREATE OR REPLACE PROCEDURE quera_pomocky
(
v_cislo_nakupu IN VCELAR_POMOCKY.cislo_nakupu%TYPE,
v_nazov OUT VCELAR_POMOCKY.nazov%TYPE,
v_cena_polozky OUT VCELAR_POMOCKY.cena_polozky%TYPE
)
IS
BEGIN
SELECT nazov || ' ' || typ_polozky,cena_polozky
INTO v_nazov,v_cena_polozky
FROM VCELAR_POMOCKY
WHERE v_cislo_nakupu = cislo_nakupu AND rodne_cislo = '750927/3913';
END quera_pomocky;
/
VARIABLE p_nazov VARCHAR2(20);
VARIABLE p_cena_polozky VARCHAR2(20);
EXECUTE quera_pomocky(24, :p_nazov , :p_cena_polozky);
PRINT p_nazov p_cena_polozky;
错误是
Error starting at line : 65 in command -
BEGIN quera_pomocky(24, :p_nazov , :p_cena_polozky); END;
Error report:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "DOMA.QUERA_POMOCKY", line 9
ORA-06512: at line 1
06502. 00000 - "PL/SQL: numeric or value error%s"
*Cause: An arithmetic, numeric, string, conversion, or constraint error occurred. For example, this error occurs if an attempt is made to assign the value NULL to a variable declared NOT NULL, or if an attempt is made to assign an integer larger than 99 to a variable
declared NUMBER(2).
*Action: Change the data, how it is manipulated, or how it is declared so that values do not violate constraints.
您正在输入:
nazov || ' ' || typ_polozky
进入一个参数
v_nazov OUT VCELAR_POMOCKY.nazov%TYPE
这是 - 在 table 中 - 声明为
nazov Varchar2 (20)
所以:如果 nazov || ' ' || typ_polozky
的长度超过 20
个字符(请注意:两者都 - 在 table 中 - 声明为 varchar2(20)
这使得连接的 MAX
长度41
),你有麻烦了。
我建议您将 OUT
参数设置为例如
v_nazov OUT varchar2(50)
你好,我有一个简单的程序,可以很好地编译,但是在我初始化变量之后,错误是这样的。
table是这样创建的
Create table vcelar_pomocky
(
cislo_nakupu Number(5,0) NOT NULL ,
cislo_ula Number(5,0) NOT NULL ,
rodne_cislo Varchar2 (30) NOT NULL ,
datum_nakupu Date NOT NULL ,
nazov Varchar2 (20) NOT NULL ,
typ_polozky Varchar2 (20) NOT NULL ,
cena_polozky Number(5,2) NOT NULL ,
primary key (cislo_nakupu)
)
/
程序如下所示:
CREATE OR REPLACE PROCEDURE quera_pomocky
(
v_cislo_nakupu IN VCELAR_POMOCKY.cislo_nakupu%TYPE,
v_nazov OUT VCELAR_POMOCKY.nazov%TYPE,
v_cena_polozky OUT VCELAR_POMOCKY.cena_polozky%TYPE
)
IS
BEGIN
SELECT nazov || ' ' || typ_polozky,cena_polozky
INTO v_nazov,v_cena_polozky
FROM VCELAR_POMOCKY
WHERE v_cislo_nakupu = cislo_nakupu AND rodne_cislo = '750927/3913';
END quera_pomocky;
/
VARIABLE p_nazov VARCHAR2(20);
VARIABLE p_cena_polozky VARCHAR2(20);
EXECUTE quera_pomocky(24, :p_nazov , :p_cena_polozky);
PRINT p_nazov p_cena_polozky;
错误是
Error starting at line : 65 in command -
BEGIN quera_pomocky(24, :p_nazov , :p_cena_polozky); END;Error report:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "DOMA.QUERA_POMOCKY", line 9
ORA-06512: at line 1
06502. 00000 - "PL/SQL: numeric or value error%s"
*Cause: An arithmetic, numeric, string, conversion, or constraint error occurred. For example, this error occurs if an attempt is made to assign the value NULL to a variable declared NOT NULL, or if an attempt is made to assign an integer larger than 99 to a variable
declared NUMBER(2).*Action: Change the data, how it is manipulated, or how it is declared so that values do not violate constraints.
您正在输入:
nazov || ' ' || typ_polozky
进入一个参数
v_nazov OUT VCELAR_POMOCKY.nazov%TYPE
这是 - 在 table 中 - 声明为
nazov Varchar2 (20)
所以:如果 nazov || ' ' || typ_polozky
的长度超过 20
个字符(请注意:两者都 - 在 table 中 - 声明为 varchar2(20)
这使得连接的 MAX
长度41
),你有麻烦了。
我建议您将 OUT
参数设置为例如
v_nazov OUT varchar2(50)