问题是如何插入VARRAY- 我有一个程序,我在参数表中声明为DATATYPE 在程序中,我使用插入语句插入表中。 我面临插入变量的问题我已经在包装规格中声明了一种变化类型并使用了身体BT错误显示:-Error(61,17):PL / SQL:ORA-00932:不一致的数据类型:预期NUMBER得到了SCOTT .SYS_PLSQL_75329_19_1
create or replace PACKAGE BODY CBIS_LOAN_PROD_PACKAGE AS
PROCEDURE LOAN_PRODUCT_INSERT_PROCEDURE
(P_PRODUCT_TITLE LOAN_PROD_TAB.PRODUCT_TITLE%TYPE,
P_PRODUCT_SUMMERY LOAN_PROD_TAB.PRODUCT_SUMMERY%TYPE,
P_INTEREST_TYPE LOAN_PROD_TAB.INTEREST_TYPE%TYPE,
P_INTEREST_RATE LOAN_PROD_TAB.INTEREST_RATE%TYPE,
P_SECURITY_REQD LOAN_PROD_TAB.SECURITY_REQD%TYPE,
P_MIN_LOAN_AMT LOAN_PROD_TAB.MIN_LOAN_AMT%TYPE,
P_MAX_LOAN_AMT LOAN_PROD_TAB.PRODUCT_TITLE%TYPE,
P_TERM_MIN LOAN_PROD_TAB.TERM_MIN%TYPE,
P_TERM_MAX LOAN_PROD_TAB.TERM_MAX%TYPE,
P_REPAYMENT_FREQUENCY LOAN_PROD_TAB.REPAYMENT_FREQUENCY%TYPE,
P_REPAYMENT_AMT LOAN_PROD_TAB.REPAYMENT_AMT%TYPE,
P_EARLY_REPAY_ALLOWED LOAN_PROD_TAB.EARLY_REPAY_ALLOWED%TYPE,
P_MIN_AGE_LIMIT LOAN_PROD_TAB.MIN_AGE_LIMIT%TYPE,
P_MAX_AGE_LIMIT LOAN_PROD_TAB.MAX_AGE_LIMIT%TYPE,
V_1 VARCHAR2,
V_2 VARCHAR2,
V_3 VARCHAR2,
V_4 VARCHAR2,
V_5 VARCHAR2,
P_PROD_START_DT LOAN_PROD_TAB.PROD_START_DT%TYPE,
P_PROD_END_DT LOAN_PROD_TAB.PROD_END_DT%TYPE,
P_PROD_STATUS LOAN_PROD_TAB.PROD_STATUS%TYPE)
IS
V_T RESIDENT_VARRAY:=RESIDENT_VARRAY('V_1','V_2','V_3','V_4','V_5');
BEGIN
INSERT INTO LOAN_PROD_TAB
(
PRODUCT_TITLE,
PRODUCT_SUMMERY,
INTEREST_TYPE,
INTEREST_RATE,
SECURITY_REQD,
MIN_LOAN_AMT,
MAX_LOAN_AMT,
TERM_MIN,
TERM_MAX,
REPAYMENT_FREQUENCY,
REPAYMENT_AMT,
EARLY_REPAY_ALLOWED,
MIN_AGE_LIMIT,
MAX_AGE_LIMIT,
RESIDENT,
PROD_START_DT,
PROD_END_DT,
PROD_STATUS)
VALUES(P_PRODUCT_TITLE,
P_PRODUCT_SUMMERY,
P_INTEREST_TYPE,
P_INTEREST_RATE,
P_SECURITY_REQD,
P_MIN_LOAN_AMT,
P_MAX_LOAN_AMT,
P_TERM_MIN,
P_TERM_MAX,
P_REPAYMENT_FREQUENCY,
P_REPAYMENT_AMT,
P_EARLY_REPAY_ALLOWED,
P_MIN_AGE_LIMIT,
P_MAX_AGE_LIMIT,
V_T,/*PROBLEM IS HERE-Error(61,17): PL/SQL: ORA-00932: inconsistent
datatypes: expected NUMBER got SCOTT.SYS_PLSQL_75329_19_1*/
P_PROD_START_DT,
P_PROD_END_DT,
P_PROD_STATUS
);
END LOAN_PRODUCT_INSERT_PROCEDURE;
END;
答案 0 :(得分:0)
您遇到的错误是因为SQL类型与PL / SQL类型不同。
您在架构级别声明的类型的LOAN_PROD_TAB.RESIDENT列的类型不会被识别为您在CBIS_LOAN_PROD_PACKAGE包规范中声明的名为RESIDENT_VARRAY的类型。
要使其工作,当您声明(并实例化)变量V_T时,必须使用与声明LOAN_PROD_TAB.RESIDENT列时使用的相同类型。
以下是验证我的解决方案的完整示例:
CREATE OR REPLACE TYPE mem_type IS VARRAY(5) of VARCHAR2(15);
CREATE TABLE test_va (
va_Name VARCHAR2(10),
va_Address VARCHAR2(20),
va_City VARCHAR2(20),
va_Phone VARCHAR2(8),
va_Members mem_type);
create or replace package test_va_pkg as
TYPE p_mem_type IS VARRAY(5) of VARCHAR2(15); -- cannot be used to insert into test_va.va_Members column!!!!
procedure p_test_va(
p_name VARCHAR2,
p_Address VARCHAR2,
p_City VARCHAR2,
p_Phone VARCHAR2
);
end test_va_pkg;
/
create or replace package body test_va_pkg as
procedure p_test_va(
p_name VARCHAR2,
p_Address VARCHAR2,
p_City VARCHAR2,
p_Phone VARCHAR2
) is
-- v_members_va p_mem_type := p_mem_type('V_1','V_2','V_3','V_4','V_5'); -- doesn't work!
v_members_va mem_type := mem_type('V_1','V_2','V_3','V_4','V_5');
begin
insert into test_va
values (
p_name,
p_Address,
p_City,
p_Phone,
v_members_va
);
commit;
exception
when others then
rollback;
raise;
end p_test_va;
end test_va_pkg;
/
begin
test_va_pkg.p_test_va('Eric Smith', 'N/A', 'London', '12345679');
end;
/
select * from test_va;
希望它有所帮助!