Here is the procedure and the error the value I am sending the exactly the value which is already existing in the table(have no dependencies).Not sure why the it is throwing the error.
create or replace PROCEDURE TEST (email_address in VARCHAR2,
CatItype in VARCHAR2, opt_status in CHAR,userIns in VARCHAR2,
editstat out VARCHAR2)
AS
eid EMAILDATA.EMAIL_ID%TYPE;
eid1 EMAILDATA.EMAIL_ID%TYPE;
cid EMAILDATA.category_id%TYPE;
cname EMAILDATA.CATEGORY_NAME%TYPE;
pref EMAILDATA.PREFERENCE%TYPE;
Email_val EMAILDATA.EMAIL_ADDRESS%TYPE := email_address;
CatIntType EMAILDATA.INTER_CONTACTTYPE%TYPE := CatItype;
usrins EMAILDATA.USER_INSERTING%TYPE := userIns;
ostat EMAILDATA.PREFERENCE%TYPE := opt_status;
error_flag BOOLEAN ;
Error
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at "TEST", line 19
ORA-06512: at line 13
I suppose the problem is here: usrins EMAILDATA.USER_INSERTING%TYPE := userIns;
The max length of VARCHAR2 in SQL (table type) = 4000 characters
The max length in PL/SQL IS 32767
USER_INSERTING is a column in the table EMAILDATA. I suppose it has VARCHAR2 type. In this case the max. number of characters for this variable is limited to 4000 (depending on your DDL).
userIns is a PL/SQL VARCHAR2 variable which can contain up to 32767 characters.
Related
I have a table T1 and I want to insert multiple rows at a time through a procedure using collection. I have written the code but when I'm trying to execute it throws an error. Please advise.
create table t1 ( id number , name varchar2(10));
/
create or replace PACKAGE PKG1 AS
TYPE TAB_LIST IS TABLE OF T1%ROWTYPE;
PROCEDURE PROC1 (p_val IN TAB_LIST);
END PKG1;
/
create or replace PACKAGE BODY PKG1 AS
PROCEDURE PROC1 (P_VAL IN TAB_LIST
)
IS
BEGIN
FOR i IN p_val.FIRST..p_val.LAST
LOOP
insert INTO T1
(
id, name
)
VALUES
(
p_val(i).id,
p_val(i).name
);
END LOOP;
END;
END;
error after executing
DECLARE
p_val PKG1.TAB_LIST;
BEGIN
p_val := PKG1.TAB_LIST(123,'XYZ');
END;
Error report -
ORA-06550: line 5, column 11:
PLS-00306: wrong number or types of arguments in call to 'TAB_LIST'
ORA-06550: line 5, column 11:
PLS-00306: wrong number or types of arguments in call to 'TAB_LIST'
ORA-06550: line 5, column 2:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
DECLARE
P_VAL PKG1.TAB_LIST := PKG1.TAB_LIST();
BEGIN
P_VAL.extend;
P_VAL(1).id := 123;
P_VAL(1).name := 'XYZ';
PKG1.PROC1( P_VAL );
END;
example for multiple records:
DECLARE
P_VAL PKG1.TAB_LIST := PKG1.TAB_LIST();
BEGIN
for i in 1 .. 10
loop
P_VAL.extend;
P_VAL(P_VAL.LAST).id := i;
P_VAL(P_VAL.LAST).name := 'XYZ' || i;
end loop;
PKG1.PROC1( P_VAL );
END;
#hekko": its not a string .sorry about formatting . The multiple values (n) can be passed from application like this and all should be inserted into table at once.
123 'XYZ'
456 'DFK'
866 'HKK'
#Kaushik :it is not a string but formatting issue.. the question remains the same "I have a table T1 and I want to insert multiple rows at a time through a procedure using collection.
PROBLEM IS HOW TO INSERT INTO VARRAY-
I HAVE A PROCEDURE WHERE I AM DECLARE IN PARAMETER AS TABLE DATATYPE
IN PROCEDURE I USE INSERT STATEMENT TO INSERT INTO TABLE.
I AM FACING PROBLEM TO INSERT INTO VARRAY ALREADY I AM A DECLARING A VARY TYPE IN PACKAGE SPECIFICATION AND USING IN BODY BT ERROR SHOWS:-Error(61,17): PL/SQL: ORA-00932: inconsistent datatypes: expected NUMBER got 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;
The error you encounter occurs because a SQL type is not the same as a PL/SQL type.
The type of LOAN_PROD_TAB.RESIDENT column which is of a type you declared at schema level, is not recognized as the same as the type called RESIDENT_VARRAY you declared in the CBIS_LOAN_PROD_PACKAGE package spec.
To make it work, when you declare (and instantiate) the variable V_T, you have to use the same type you used when you declared the LOAN_PROD_TAB.RESIDENT column.
Below is a full example to verify my solution:
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;
Hope it helps!
Getting this error when ever I tried to execute the entire procedure. Below is the piece of code from the procedure.
SELECT
DISTINCT SUBSTRING (a.GL06001,19,10) as ProjectNo,
--PR01040 UD_10,
SUBSTRING (a.GL06001,1,8) as AccountNo,
a.GL06002 as TransNo,
a.GL06004 as TransAmount,
a.GL06003 as TransDate,
a.GL06005 as TransDesc,
'GL' as SourceType,
' ' as ResourceCode,
' ' as TransLine,
0 as CostPR,
'000000' as PRTransNo,
a.GL06027 as SubprojNo,
a.GL06028 as ActiLineNo,
a.GL06012 as TransType,
a.GL06016 as Counter
from ScalaMX.dbo.GL06PA17 a where a.GL06003 between '2017-02-21 00:00:00.000' and '2017-03-01 00:00:00.000'
There are actually 18000+ rows and 15 columns. Any hint on how to track which column has B value?
I downloaded the result in Excel and ctrl+f 'B' But still no clue and I couldn't find it.
convert into stored procedure, see below sample
declare
n integer;
m integer;
begin
for i in ( select primarykeycolumn, a,b from table )
loop
begin
n := i.a;
m := i.b;
exception
when others then
dbms_output.put_line(i.primarykeycolumn);
end
end loop;
end;
When conversion error happens it will catch the exception hence find the primary key.
i need to convert a varchar to an array using pl/sql, but when i use the SUBSTR function, i get this error:
Error report -
ORA-06550: line 12, column 3:
PLS-00330: invalid use of type name or subtype name
ORA-06550: line 12, column 3:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
this is my code:
SET SERVEROUTPUT ON;
DECLARE
v_string varchar2(20) := 'hello';
type array_string is varray(5) of varchar2(10);
v_length number;
cnt number;
v_char char(1);
BEGIN
v_length := length(v_string);
while (cnt < v_length)
loop
v_char := SUBSTR(v_string, cnt, 1);
array_string(cnt) := v_char;
cnt := cnt + 1;
end loop;
END;
when i (partially) type 'SUBSTR' it autocompletes to SUBSTR(SQLERRM, 1, 64) so it should know the command, right?
what am i doing wrong? im pretty new at pl/sql
regards,
You must initialize variable cnt before using it in substr.
You must use variable name instead of type name in array_string(cnt).
You must extend your varray before writing new value to it.
In oracle environment, the starting index for varrays is always 1.
Your cnt is starting from 0. So the during the first time execution of the loop, the
a_string(cnt) := v_char;
cnt is 0.
Initialize cnt as 1, and run the loop for
while (cnt < 5)
This will remove the error you are getting
This question already has an answer here:
Unable to call an Oracle Function
(1 answer)
Closed 9 years ago.
Can any one help me to execute the below procedure in PL/SQL. I am getting error as
declare
TYPE c_charge_code_arra IS TABLE OF VARCHAR2(20) INDEX BY PLS_INTEGER;
myarray c_charge_code_arra;
out_val number := 12;
begin
myarray(0) := 'hg';
BRANCH_BKK.air_pkg.airinvoice_pd('01','13070410012','4610032','A','IN','bkkrp_bkk','Asia/Bangkok','56YUSEN',null,myarray,null,'B',out_val);
end;
Error at line 1
ORA-06550: line 7, column 2:
PLS-00306: wrong number or types of arguments in call to 'AIRINVOICE_PD'
ORA-06550: line 7, column 2:
PL/SQL: Statement ignored
Below is the package declaration. When I try to execute the below procedure I get the above error. Thanks in Advance
CREATE OR REPLACE PACKAGE BRANCH_BKK.air_pkg AS
TYPE c_charge_code_arra IS TABLE OF VARCHAR2(20) INDEX BY PLS_INTEGER;
PROCEDURE airinvoice_pd (in_company IN varchar2,
in_file_no IN varchar2,
c_reference IN varchar2,
in_run_option IN varchar2,
in_invoice_type IN varchar2,
in_user IN varchar2,
c_time_zone in varchar2,
in_payor_code IN varchar2,
in_payor_reference IN varchar2,
i_charge_code IN c_charge_code_arra,
in_invoice_number IN varchar2,
in_invoice_against IN varchar2,
out_message OUT varchar2);
The problem is with your declaration of myarray. You are attempting to re-declare the table type in the calling script, when instead, you need to declare the variable of the table type defined in the package spec:
DECLARE
myarray BRANCH_BKK.air_pkg.c_charge_code_arra;
out_val NUMBER := 12;
BEGIN
myarray (0) := 'hg';
BRANCH_BKK.air_pkg.airinvoice_pd ('01',
'13070410012',
'4610032',
'A',
'IN',
'bkkrp_bkk',
'Asia/Bangkok',
'56YUSEN',
NULL,
myarray,
NULL,
'B',
out_val
);
END;