How to convert clob data into multiple columns in Oracle? - sql

In a Oracle table, I have a clob column (TEXT) which has data like below.
"Employee ID: 1
Hire Date: 24-Oct-2013
Name: XXXXX
Department: IT
Employee ID : 2
Name : YYYYY
Hire Date : 20-May-2014
Department: ITIS
Hire Date: 17-May-2017
Department:SMO
Name: ZZZZZ
Employee ID: 3"
The above CLOB data needs to be converted into multiple columns like below
Employee_ID Hire_Date Name Department
----------------------------------------------------
1 24-Oct-2013 XXXXX IT
2 20-May-2014 YYYYY ITIS
3 17-May-2017 ZZZZZ SMO
Please help me on this.

Code below is getting data from your string and insert column to temporary table, if you don't need temperory table you can use logic of getting data from string as you want
First create temperory table Employeeinfo like this
create global temporary table EmployeeInfo
(
EmployeeID varchar2(15),
HireDate varchar2(15),
Name varchar2(100),
Department varchar2(10)
)
on commit preserve rows;
Second use this code(this is pl/sql test script)
declare
lv_string varchar2(4000) := 'Employee ID: 1
Hire Date: 24-Oct-2013
Name: XXXXX
Department: IT
Employee ID : 2
Name : YYYYY
Hire Date : 20-May-2014
Department: ITIS
Hire Date: 17-May-2017
Department:SMO
Name: ZZZZZ
Employee ID: 3';
lv_Token varchar2(4000);
lv_Part varchar2(4000);
lv_FirstPart varchar2(4000);
lv_SecondPart varchar2(4000);
li pls_integer := 0;
lv_EmployeeID varchar2(15);
lv_HireDate varchar2(15);
lv_Name varchar2(100);
lv_Department varchar2(10);
function v_Partition(av_source long, av_separator varchar2,
ai_nth pls_integer) return varchar2 is
li_Sep pls_integer := length(av_Separator);
li_Begin pls_integer := 1 - li_Sep;
li_End pls_integer;
lv_Output long;
begin
li_End := instr(av_source, av_separator, 1, ai_nth);
if ai_Nth > 1 then
li_Begin := instr(av_source, av_separator, 1, ai_nth - 1);
if li_Begin = 0 then
return null;
end if;
end if;
if li_End > 0 then
lv_Output := substr(av_Source, li_Begin + li_Sep,
li_End - li_Begin - li_Sep);
elsif length(av_Source) >= li_Begin + li_Sep then
lv_Output := substr(av_Source, li_Begin + li_Sep,
length(av_Source) - li_Begin);
end if;
return lv_Output;
end;
function v_Token(av_source in out nocopy varchar2, av_separator varchar2)
return varchar2 is
lv_token varchar2(4000);
li_pos pls_integer;
begin
li_pos := instr(av_source, av_separator, 1, 1);
if li_pos > 0 then
lv_token := rtrim(substr(av_source, 1, li_pos - 1));
av_source := substr(av_source, li_pos + length(av_separator));
else
lv_token := rtrim(av_source);
av_source := '';
end if;
if av_Separator = ' ' then
av_Source := trim(av_Source);
end if;
return lv_token;
end;
begin
while lv_string is not null loop
lv_Token := v_Token(lv_string, chr(10));
if lv_Token is not null then
li := li + 1;
lv_FirstPart := trim(v_Partition(lv_Token, ':', 1));
put(lv_FirstPart);
lv_SecondPart := trim(v_Partition(lv_Token, ':', 2));
if lv_FirstPart like '%Employee ID%' then
lv_EmployeeID := lv_SecondPart;
elsif lv_FirstPart like '%Hire Date%' then
lv_HireDate := lv_SecondPart;
elsif lv_FirstPart like '%Name%' then
lv_Name := lv_SecondPart;
elsif lv_FirstPart like '%Department%' then
lv_Department := lv_SecondPart;
end if;
if li = 4 then
insert into EmployeeInfo
values
(lv_EmployeeID, lv_HireDate, lv_Name, lv_Department);
li := 0;
end if;
end if;
end loop;
--select * from EmployeeInfo; -- you can select from table
end;

Related

Error PLS-00103 encountered symbol - At output string fields

I'm getting the pls-00103 error on the output strings of my procedures.
In the field p_primeravalidacion
PROCEDURE ER_validacion_titulares (p_id_titularidad IN NUMBER,
p_primeravalidacion OUT VARCHAR2(1)) IS
And in this second procedure, at the varchar fields
PROCEDURE ER_validacion_simulacion (p_id_titularidad IN NUMBER,
p_familia IN VARCHAR2(2),
p_importe_producto IN NUMBER,
p_id_simulacion IN NUMBER,
p_id_rating IN NUMBER,
p_rating_cliente IN NUMBER,
> p_motivo OUT VARCHAR2(200),
p_cliente_simulacion OUT NUMBER,
p_cif OUT VARCHAR2(10),
p_razon_social OUT VARCHAR2(10),
p_producto_simulacion OUT VARCHAR2(2),
p_importe_simulacion OUT NUMBER,
p_fecha_simulacion OUT NUMBER,
p_raroc_primer_anyo OUT NUMBER,
p_raroc_anualizado OUT NUMBER,
p_rating OUT NUMBER,
p_indicador_raroc OUT NUMBER ) IS
create or replace package API_VALIDACION is
procedure ER_validacion_titulares;
procedure ER_validacion_simulacion;
end;
/
create or replace package body API_VALIDACION is
PROCEDURE ER_validacion_titulares (p_id_titularidad IN NUMBER,
p_primeravalidacion OUT VARCHAR2(1)) IS
cuenta NUMBER := 0;
BEGIN
select count(*)
INTO CUENTA
FROM DCRISK.RAROC_PERSONAS_BCORP where id_titularidad = p_id_titularidad and calc_raroc = 'S';
if(cuenta > 0) then
p_primeravalidacion := 'S';
else
p_primeravalidacion := 'N';
end if;
END;
PROCEDURE ER_validacion_simulacion (p_id_titularidad IN NUMBER,
p_familia IN VARCHAR2(2),
p_importe_producto IN NUMBER,
p_id_simulacion IN NUMBER,
p_id_rating IN NUMBER,
p_rating_cliente IN NUMBER,
p_motivo OUT VARCHAR2(200),
p_cliente_simulacion OUT NUMBER,
p_cif OUT VARCHAR2(10),
p_razon_social OUT VARCHAR2(10),
p_producto_simulacion OUT VARCHAR2(2),
p_importe_simulacion OUT NUMBER,
p_fecha_simulacion OUT NUMBER,
p_raroc_primer_anyo OUT NUMBER,
p_raroc_anualizado OUT NUMBER,
p_rating OUT NUMBER,
p_indicador_raroc OUT NUMBER ) IS
simulacion_no_existe EXCEPTION;
titular_no_vinculado EXCEPTION;
validacionSimulacion BOOLEAN := false;
validacionTitularidad BOOLEAN := false;
grupo VARCHAR2(20);
vAux NUMBER := 0;
vTitularidad NUMBER := 0;
grupo_mayor_exposicion VARCHAR2(20);
exposicion NUMBER := 0;
total NUMBER := 0;
exposicion_aux NUMBER := 0;
CURSOR grupos IS
select distinct o1 as grupo
from bdd_simroe.T_VROE_INF_POSICIONES_GRUPO
where o2 IN (
SELECT IDEPER
FROM BDD_SIMROE.TROE_SIMUL_CLIENTES
WHERE ID_SIMULACION = p_id_simulacion AND ID_TITULARIDAD = p_id_titularidad);
BEGIN
--Validacion simulacion existe
select count(*) into vAux
from bdd_simroe.troe_simulaciones
where id_simulacion = p_id_simulacion;
if (vAux < 1) then
RAISE simulacion_no_existe;
end if;
--Titular no vinculado a titularidad
select ID_TITULARIDAD into vTitularidad
from dcrisk.raroc_personas_bcorp
where id_numpersona IN (
select id_persona
from bdd_simroe.troe_simulaciones
where id_Simulacion = p_id_simulacion);
if ( vTitularidad != p_id_titularidad) then
RAISE titular_no_vinculado;
end if;
--Calculo campos salida
--
select ID_NUMPERSONA,
IDEPER,
NOMBRE,
RAT_GBL
INTO
p_cliente_simulacion,
p_cif,
p_razon_social,
p_rating
from bdd_simroe.TROE_SIMUL_CLIENTES
where id_simulacion = p_id_simulacion;
select
ID_PRODUCTO,
SALDO_MEDIO,
FECHA_ALTA,
RAROC_PRIMER_ANYO,
RAROC_ANUALIZADO
into
p_producto_simulacion,
p_importe_producto,
p_fecha_simulacion,
p_raroc_primer_anyo,
p_raroc_anualizado
from bdd_simroe.TROE_SIMULACIONES
where id_simulacion = p_id_simulacion;
SELECT P.RAROC_OBJ into p_indicador_raroc
FROM BDD_SIMROE.PARAMETROS_APP P
WHERE P.ID_PERFIL = 1;
FOR rec IN grupos
LOOP
select EXPOSICION INTO exposicion from table(bdd_simroe.API_INFORMES.informe_cart_y_sim_sit_irreg('es','J862312',rec.grupo,'P','0')) WHERE CONCEPTO = 'TOTAL CARTERA';
if (exposicion > exposicion_aux) then
grupo_mayor_exposicion := rec.grupo;
exposicion_aux := exposicion;
end if;
-- DBMS_OUTPUT.put_line('grupo: ' || rec.grupo || ' EXPOSICION: ' || exposicion || ' Grupo mayor expo: ' || grupo_mayor_exposicion || ' Expo aux: ' || exposicion_aux);
END LOOP;
select RAROC INTO total from table(bdd_simroe.API_INFORMES.informe_cart_y_sim_sit_irreg('es','J862312',grupo_mayor_exposicion,'P','0')) WHERE CONCEPTO = 'TOTAL CARTERA';
-- DBMS_OUTPUT.put_line('Total RAROC cliente: ' || total);
EXCEPTION
WHEN simulacion_no_existe THEN
p_motivo := "El número de simulación informado no existe";
WHEN titular_no_vinculado THEN
p_motivo := "El titular de la simulación no coincide con ninguno de los titulares del ER";
END;
end;
What is obvious, is that procedure's parameters can't have size:
SQL> create or replace procedure p_test(p_familia IN VARCHAR2(2)) is
2 begin
3 null;
4 end;
5 /
Warning: Procedure created with compilation errors.
SQL> show err
Errors for PROCEDURE P_TEST:
LINE/COL ERROR
-------- -----------------------------------------------------------------
1/39 PLS-00103: Encountered the symbol "(" when expecting one of the
following:
:= . ) , # % default character
The symbol ":=" was substituted for "(" to continue.
SQL> l1
1* create or replace procedure p_test(p_familia IN VARCHAR2(2)) is
SQL> c/(2)//
1* create or replace procedure p_test(p_familia IN VARCHAR2) is
SQL> /
Procedure created.
SQL>
Therefore, use only VARCHAR2 not e.g. VARCHAR2(2).

How to write "in" claus in select query when ever in_put param has some values..?

whenever users pass a list of values then we need to pause "in" condition.
the jin_son_doc will be like this "India,American Samoa"
create or replace PROCEDURE test_attendee (
out_chr_err_code OUT VARCHAR2,
out_chr_err_msg OUT VARCHAR2,
out_attendee_tab OUT return_attendee_arr_result,
in_json_doc IN VARCHAR2
) IS
l_chr_srcstage VARCHAR2(200);
l_chr_biqtab VARCHAR2(200);
l_chr_srctab VARCHAR2(200);
l_chr_bistagtab VARCHAR2(200);
l_chr_err_code VARCHAR2(255);
l_chr_err_msg VARCHAR2(255);
l_out_chr_errbuf VARCHAR2(2000);
lrec return_attendee_report;
l_num_counter NUMBER := 0;
json_doc CHAR_ARRAY(1000) := in_json_doc;
CURSOR cur_attendee_data IS
SELECT
*
FROM
(
SELECT
a.*,
ROWNUM rn
FROM
(SELECT * FROM (
SELECT
r.id request_id,
c.designation ext_att_title,
DECODE(c.attendee_type, 'externalattendees', 'External', 'Internal') attendee_type
FROM
bi_request r
LEFT JOIN bi_request_activity_day a ON a.request_id = r.id
LEFT JOIN bi_request_catering_activity b ON b.request_activity_day_id = a.id
LEFT JOIN bi_request_attendees c ON c.request_id = r.id
LEFT JOIN bi_request_act_day_room d ON d.request_activity_day_id = a.id
AND d.room = b.room
WHERE
r.state = 'CONFIRMED'
AND a.event_date BETWEEN l_start_date AND l_end_date
AND r.location_id = (
SELECT UNIQUE
( id )
FROM
bi_location
WHERE
unique_id = l_location_id
)
AND d.room_type = 'MAIN_ROOM'
AND country IN (
SELECT
column_value
FROM
TABLE ( json_doc )
)
)
WHERE
1=1
) a
WHERE
ROWNUM <= l_end_row
)
WHERE
rn >= l_start_row;
TYPE rec_attendee_data IS
TABLE OF cur_attendee_data%rowtype INDEX BY PLS_INTEGER;
l_cur_attendee_data rec_attendee_data;
BEGIN
dbms_output.put_line(l_country_array.count);
out_attendee_tab := return_attendee_arr_result();
OPEN cur_attendee_data;
LOOP
FETCH cur_attendee_data BULK COLLECT INTO l_cur_attendee_data;
EXIT WHEN l_cur_attendee_data.count = 0;
dbms_output.put_line('here in first insert');
lrec := return_attendee_report();
out_attendee_tab := return_attendee_arr_result(return_attendee_report());
out_attendee_tab.DELETE;
FOR i IN 1..l_cur_attendee_data.count LOOP
-- dbms_output.put_line('Inside cursor ' );
BEGIN
l_num_counter := l_num_counter + 1;
lrec := return_attendee_report();
lrec.requestid := l_cur_attendee_data(i).request_id;
lrec.attendeetype := l_cur_attendee_data(i).attendee_type;
lrec.attendeetype := json_doc;
IF l_num_counter > 1 THEN
out_attendee_tab.extend();
out_attendee_tab(l_num_counter) := return_attendee_report();
ELSE
out_attendee_tab := return_attendee_arr_result(return_attendee_report());
END IF;
out_attendee_tab(l_num_counter) := lrec;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Error occurred : ' || sqlerrm);
END;
END LOOP;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('HERE INSIIDE OTHERS' || sqlerrm);
END;
Whenever j"son_doc" is null we need to skip the in clause. Is this possible, let me know if we have any solution.
user will pass jin_son_doc will be like this "India, America".
by using the following function i'm converting string to array,
create or replace FUNCTION fn_varchar_to_array(p_list IN VARCHAR2)
RETURN CHAR_ARRAY
AS
l_string VARCHAR2(32767) := p_list || ',';
l_comma_index PLS_INTEGER;
l_index PLS_INTEGER := 1;
l_tab CHAR_ARRAY := CHAR_ARRAY();
BEGIN
LOOP
l_comma_index := INSTR(l_string, ',', l_index);
EXIT WHEN l_comma_index = 0;
l_tab.EXTEND;
l_tab(l_tab.COUNT) := SUBSTR(l_string, l_index, l_comma_index - l_index);
l_index := l_comma_index + 1;
END LOOP;
RETURN l_tab;
END fn_varchar_to_array;
You can use OR condition as following:
....
AND (json_doc is null
OR country IN (
SELECT
column_value
FROM
TABLE ( json_doc )
)
)
...
Cheers!!

PL-00215: varchar2 length error

I'm trying to do a very simple thing: extract a date and do some controls on it.
Everything's fine but when I try to compile this error pops out and I really don't have a clue about how to solve it...
This is the code:
function get_crediti_formativi_biennio(p_userid varchar2,
p_prof_abil varchar2,
p_id_persona number,
p_tipo_formazione number,
p_anno_formazione varchar2,
p_flag_calcolo number,
p_crediti_totali out number)
return varchar2 is
v_count number;
v_anno varchar2;
v_biennio_from number;
v_biennio_to number;
l_err_msg varchar2(1024) := '+OK0000 Operazione effettuata con successo';
begin
v_count := null;
begin
select TO_CHAR(ap.valore)
into v_anno
from intc_attr_persone ap
where ap.id_attributo = 202
and ap.id = p_id_persona;
exception
when no_data_found then
v_anno := '';
end;
if v_anno >= 2015 and (mod(v_anno, 2) != 0) then
if (mod(p_anno_formazione, 2) = 0) then
v_biennio_from := p_anno_formazione;
v_biennio_to := p_anno_formazione + 1;
else
v_biennio_from := p_anno_formazione - 1;
v_biennio_to := p_anno_formazione;
end if;
else
if v_anno < 2015 or v_anno = '' or v_anno is null then
if (mod(p_anno_formazione, 2) = 0) then
v_biennio_from := p_anno_formazione - 1;
v_biennio_to := p_anno_formazione;
else
v_biennio_from := p_anno_formazione;
v_biennio_to := p_anno_formazione + 1;
end if;
end if;
end if;
The problem is on v_anno.....

Transpose rows to columns in Oracle 10g : naming of the columns

My select query is as follows :
SELECT
R.ID_REQUEST, R.ID_PROJET, J.NAME, L.DATE_ACTION,L.NAME_ACTION
, LEAD(L.DATE_ACTION) OVER (PARTITION BY R.ID_REQUEST ORDER BY L.DATE_ACTION)- L.DATE_ACTION AS TOTAL_DAYS
FROM (REQUEST R LEFT JOIN LOG_TABLE L ON R.ID_REQUEST = L.ID_REQUEST)
LEFT JOIN JOB_TABLE J ON R.ID_JOB = J.ID_JOB
WHERE D.ID_REQUEST = 10
The result is something like this :
ID_REQUEST ID_PROJET NAME DATE_ACTION NAME_ACTION TOTAL_DAYS
10 152 pr1 01/01/2005 arbitrary_name1 3
10 152 pr1 04/01/2005 arbitrary_name2 1
10 152 pr1 05/01/2005 arbitrary_name3 null
what I want is to put the names of the actions as columns. I know that i can do it using DECODE (since there is no pivotin 10g). but how to use the same name of the action as the name of the column ? The list of actions vary depending on the request. (the table log_table contains the actions per request, the number of actions is variable).
I hope my question is clear enough ! thanks.
This solution by someone much smarter than I am works well on 10 or 11 with a dynamic number of column. The only thing it doesn't do is order the columns.
And the implementation
SELECT *
FROM TABLE(DYNAMIC_PIVOT(
'SELECT emp_no,dept_no from emp group by emp_no'));
CREATE OR REPLACE TYPE PIVOTIMPL AS OBJECT
(
--from here https://technology.amis.nl/2006/05/24/dynamic-sql-pivoting-stealing-antons-thunder/
RET_TYPE ANYTYPE, -- The return type of the table function
STMT VARCHAR2(32767),
FMT VARCHAR2(32767),
CUR INTEGER,
STATIC FUNCTION ODCITABLEDESCRIBE(RTYPE OUT ANYTYPE,
P_STMT IN VARCHAR2,
P_FMT IN VARCHAR2 := 'upper(#p#)',
DUMMY IN NUMBER := 0) RETURN NUMBER,
STATIC FUNCTION ODCITABLEPREPARE(SCTX OUT PIVOTIMPL,
TI IN SYS.ODCITABFUNCINFO,
P_STMT IN VARCHAR2,
P_FMT IN VARCHAR2 := 'upper(#p#)',
DUMMY IN NUMBER := 0) RETURN NUMBER,
STATIC FUNCTION ODCITABLESTART(SCTX IN OUT PIVOTIMPL,
P_STMT IN VARCHAR2,
P_FMT IN VARCHAR2 := 'upper(#p#)',
DUMMY IN NUMBER := 0) RETURN NUMBER,
MEMBER FUNCTION ODCITABLEFETCH(SELF IN OUT PIVOTIMPL,
NROWS IN NUMBER,
OUTSET OUT ANYDATASET) RETURN NUMBER,
MEMBER FUNCTION ODCITABLECLOSE(SELF IN PIVOTIMPL) RETURN NUMBER
)
/
prompt
prompt Creating function DYNAMIC_PIVOT
prompt ===============================
prompt
CREATE OR REPLACE FUNCTION BROO1APP.DYNAMIC_PIVOT(P_STMT IN VARCHAR2,
P_FMT IN VARCHAR2 := 'upper(#p#)',
DUMMY IN NUMBER := 0)
RETURN ANYDATASET
PIPELINED USING PIVOTIMPL;
/
prompt
prompt Creating type body PIVOTIMPL
prompt ============================
prompt
CREATE OR REPLACE TYPE BODY BROO1APP.PIVOTIMPL AS
STATIC FUNCTION ODCITABLEDESCRIBE(RTYPE OUT ANYTYPE,
P_STMT IN VARCHAR2,
P_FMT IN VARCHAR2 := 'upper(#p#)',
DUMMY IN NUMBER) RETURN NUMBER IS
ATYP ANYTYPE;
CUR INTEGER;
NUMCOLS NUMBER;
DESC_TAB DBMS_SQL.DESC_TAB2;
RC SYS_REFCURSOR;
T_C2 VARCHAR2(32767);
T_FMT VARCHAR2(1000);
BEGIN
CUR := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(CUR, P_STMT, DBMS_SQL.NATIVE);
DBMS_SQL.DESCRIBE_COLUMNS2(CUR, NUMCOLS, DESC_TAB);
DBMS_SQL.CLOSE_CURSOR(CUR);
--
ANYTYPE.BEGINCREATE(DBMS_TYPES.TYPECODE_OBJECT, ATYP);
FOR I IN 1 .. NUMCOLS - 2 LOOP
ATYP.ADDATTR(DESC_TAB(I).COL_NAME,
CASE DESC_TAB(I).COL_TYPE
WHEN 1 THEN
DBMS_TYPES.TYPECODE_VARCHAR2
WHEN 2 THEN
DBMS_TYPES.TYPECODE_NUMBER
WHEN 9 THEN
DBMS_TYPES.TYPECODE_VARCHAR2
WHEN 11 THEN
DBMS_TYPES.TYPECODE_VARCHAR2 -- show rowid as varchar2
WHEN 12 THEN
DBMS_TYPES.TYPECODE_DATE
WHEN 208 THEN
DBMS_TYPES.TYPECODE_VARCHAR2 -- show urowid as varchar2
WHEN 96 THEN
DBMS_TYPES.TYPECODE_CHAR
WHEN 180 THEN
DBMS_TYPES.TYPECODE_TIMESTAMP
WHEN 181 THEN
DBMS_TYPES.TYPECODE_TIMESTAMP_TZ
WHEN 231 THEN
DBMS_TYPES.TYPECODE_TIMESTAMP_LTZ
WHEN 182 THEN
DBMS_TYPES.TYPECODE_INTERVAL_YM
WHEN 183 THEN
DBMS_TYPES.TYPECODE_INTERVAL_DS
END,
DESC_TAB(I).COL_PRECISION,
DESC_TAB(I).COL_SCALE,
CASE DESC_TAB(I).COL_TYPE
WHEN 11 THEN
18 -- for rowid col_max_len = 16, and 18 characters are shown
ELSE
DESC_TAB(I).COL_MAX_LEN
END,
DESC_TAB(I).COL_CHARSETID,
DESC_TAB(I).COL_CHARSETFORM);
END LOOP;
IF INSTR(P_FMT, '#p#') > 0 THEN
T_FMT := P_FMT;
ELSE
T_FMT := '#p#';
END IF;
OPEN RC FOR REPLACE('select distinct ' || T_FMT || '
from( ' || P_STMT || ' )
order by ' || T_FMT,
'#p#',
DESC_TAB(NUMCOLS - 1).COL_NAME);
LOOP
FETCH RC
INTO T_C2;
EXIT WHEN RC%NOTFOUND;
ATYP.ADDATTR(T_C2,
CASE DESC_TAB(NUMCOLS).COL_TYPE WHEN 1 THEN
DBMS_TYPES.TYPECODE_VARCHAR2 WHEN 2 THEN
DBMS_TYPES.TYPECODE_NUMBER WHEN 9 THEN
DBMS_TYPES.TYPECODE_VARCHAR2 WHEN 11 THEN
DBMS_TYPES.TYPECODE_VARCHAR2 -- show rowid as varchar2
WHEN 12 THEN DBMS_TYPES.TYPECODE_DATE WHEN 208 THEN
DBMS_TYPES.TYPECODE_UROWID WHEN 96 THEN
DBMS_TYPES.TYPECODE_CHAR WHEN 180 THEN
DBMS_TYPES.TYPECODE_TIMESTAMP WHEN 181 THEN
DBMS_TYPES.TYPECODE_TIMESTAMP_TZ WHEN 231 THEN
DBMS_TYPES.TYPECODE_TIMESTAMP_LTZ WHEN 182 THEN
DBMS_TYPES.TYPECODE_INTERVAL_YM WHEN 183 THEN
DBMS_TYPES.TYPECODE_INTERVAL_DS END,
DESC_TAB(NUMCOLS).COL_PRECISION,
DESC_TAB(NUMCOLS).COL_SCALE,
CASE DESC_TAB(NUMCOLS).COL_TYPE WHEN 11 THEN 18 -- for rowid col_max_len = 16, and 18 characters are shown
ELSE DESC_TAB(NUMCOLS).COL_MAX_LEN END,
DESC_TAB(NUMCOLS).COL_CHARSETID,
DESC_TAB(NUMCOLS).COL_CHARSETFORM);
END LOOP;
CLOSE RC;
ATYP.ENDCREATE;
ANYTYPE.BEGINCREATE(DBMS_TYPES.TYPECODE_TABLE, RTYPE);
RTYPE.SETINFO(NULL,
NULL,
NULL,
NULL,
NULL,
ATYP,
DBMS_TYPES.TYPECODE_OBJECT,
0);
RTYPE.ENDCREATE();
RETURN ODCICONST.SUCCESS;
EXCEPTION
WHEN OTHERS THEN
RETURN ODCICONST.ERROR;
END;
--
STATIC FUNCTION ODCITABLEPREPARE(SCTX OUT PIVOTIMPL,
TI IN SYS.ODCITABFUNCINFO,
P_STMT IN VARCHAR2,
P_FMT IN VARCHAR2 := 'upper(#p#)',
DUMMY IN NUMBER) RETURN NUMBER IS
PREC PLS_INTEGER;
SCALE PLS_INTEGER;
LEN PLS_INTEGER;
CSID PLS_INTEGER;
CSFRM PLS_INTEGER;
ELEM_TYP ANYTYPE;
ANAME VARCHAR2(30);
TC PLS_INTEGER;
BEGIN
TC := TI.RETTYPE.GETATTRELEMINFO(1,
PREC,
SCALE,
LEN,
CSID,
CSFRM,
ELEM_TYP,
ANAME);
--
IF INSTR(P_FMT, '#p#') > 0 THEN
SCTX := PIVOTIMPL(ELEM_TYP, P_STMT, P_FMT, NULL);
ELSE
SCTX := PIVOTIMPL(ELEM_TYP, P_STMT, '#p#', NULL);
END IF;
RETURN ODCICONST.SUCCESS;
END;
--
STATIC FUNCTION ODCITABLESTART(SCTX IN OUT PIVOTIMPL,
P_STMT IN VARCHAR2,
P_FMT IN VARCHAR2 := 'upper(#p#)',
DUMMY IN NUMBER) RETURN NUMBER IS
CUR INTEGER;
NUMCOLS NUMBER;
DESC_TAB DBMS_SQL.DESC_TAB2;
T_STMT VARCHAR2(32767);
TYPE_CODE PLS_INTEGER;
PREC PLS_INTEGER;
SCALE PLS_INTEGER;
LEN PLS_INTEGER;
CSID PLS_INTEGER;
CSFRM PLS_INTEGER;
SCHEMA_NAME VARCHAR2(30);
TYPE_NAME VARCHAR2(30);
VERSION VARCHAR2(30);
ATTR_COUNT PLS_INTEGER;
ATTR_TYPE ANYTYPE;
ATTR_NAME VARCHAR2(100);
DUMMY2 INTEGER;
FIRST_COL VARCHAR2(30);
BEGIN
CUR := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(CUR, P_STMT, DBMS_SQL.NATIVE);
DBMS_SQL.DESCRIBE_COLUMNS2(CUR, NUMCOLS, DESC_TAB);
DBMS_SQL.CLOSE_CURSOR(CUR);
--
FOR I IN 1 .. NUMCOLS - 2 LOOP
T_STMT := T_STMT || ', "' || DESC_TAB(I).COL_NAME || '"';
END LOOP;
--
TYPE_CODE := SCTX.RET_TYPE.GETINFO(PREC,
SCALE,
LEN,
CSID,
CSFRM,
SCHEMA_NAME,
TYPE_NAME,
VERSION,
ATTR_COUNT);
FOR I IN NUMCOLS - 1 .. ATTR_COUNT LOOP
TYPE_CODE := SCTX.RET_TYPE.GETATTRELEMINFO(I,
PREC,
SCALE,
LEN,
CSID,
CSFRM,
ATTR_TYPE,
ATTR_NAME);
T_STMT := T_STMT ||
REPLACE(', max( decode( ' || SCTX.FMT || ', ''' ||
ATTR_NAME || ''', ' || DESC_TAB(NUMCOLS)
.COL_NAME || ' ) )',
'#p#',
DESC_TAB(NUMCOLS - 1).COL_NAME);
END LOOP;
T_STMT := 'select ' || SUBSTR(T_STMT, 2) || ' from ( ' || SCTX.STMT || ' )';
FOR I IN 1 .. NUMCOLS - 2 LOOP
IF I = 1 THEN
T_STMT := T_STMT || ' group by "' || DESC_TAB(I).COL_NAME || '"';
FIRST_COL := DESC_TAB(I).COL_NAME;
ELSE
T_STMT := T_STMT || ', "' || DESC_TAB(I).COL_NAME || '"';
END IF;
END LOOP;
T_STMT := T_STMT || ' ORDER BY "' || FIRST_COL || '"';
--
DBMS_OUTPUT.PUT_LINE(T_STMT);
SCTX.CUR := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(SCTX.CUR, T_STMT, DBMS_SQL.NATIVE);
FOR I IN 1 .. ATTR_COUNT LOOP
TYPE_CODE := SCTX.RET_TYPE.GETATTRELEMINFO(I,
PREC,
SCALE,
LEN,
CSID,
CSFRM,
ATTR_TYPE,
ATTR_NAME);
CASE TYPE_CODE
WHEN DBMS_TYPES.TYPECODE_CHAR THEN
DBMS_SQL.DEFINE_COLUMN(SCTX.CUR, I, 'x', 32767);
WHEN DBMS_TYPES.TYPECODE_VARCHAR2 THEN
DBMS_SQL.DEFINE_COLUMN(SCTX.CUR, I, 'x', 32767);
WHEN DBMS_TYPES.TYPECODE_NUMBER THEN
DBMS_SQL.DEFINE_COLUMN(SCTX.CUR, I, CAST(NULL AS NUMBER));
WHEN DBMS_TYPES.TYPECODE_DATE THEN
DBMS_SQL.DEFINE_COLUMN(SCTX.CUR, I, CAST(NULL AS DATE));
WHEN DBMS_TYPES.TYPECODE_UROWID THEN
DBMS_SQL.DEFINE_COLUMN(SCTX.CUR, I, CAST(NULL AS UROWID));
WHEN DBMS_TYPES.TYPECODE_TIMESTAMP THEN
DBMS_SQL.DEFINE_COLUMN(SCTX.CUR, I, CAST(NULL AS TIMESTAMP));
WHEN DBMS_TYPES.TYPECODE_TIMESTAMP_TZ THEN
DBMS_SQL.DEFINE_COLUMN(SCTX.CUR, I, CAST(NULL AS TIMESTAMP WITH TIME ZONE));
WHEN DBMS_TYPES.TYPECODE_TIMESTAMP_LTZ THEN
DBMS_SQL.DEFINE_COLUMN(SCTX.CUR, I, CAST(NULL AS TIMESTAMP WITH LOCAL TIME ZONE));
WHEN DBMS_TYPES.TYPECODE_INTERVAL_YM THEN
DBMS_SQL.DEFINE_COLUMN(SCTX.CUR,
I,
CAST(NULL AS INTERVAL YEAR TO MONTH));
WHEN DBMS_TYPES.TYPECODE_INTERVAL_DS THEN
DBMS_SQL.DEFINE_COLUMN(SCTX.CUR,
I,
CAST(NULL AS INTERVAL DAY TO SECOND));
END CASE;
END LOOP;
DUMMY2 := DBMS_SQL.EXECUTE(SCTX.CUR);
RETURN ODCICONST.SUCCESS;
END;
--
MEMBER FUNCTION ODCITABLEFETCH(SELF IN OUT PIVOTIMPL,
NROWS IN NUMBER,
OUTSET OUT ANYDATASET) RETURN NUMBER IS
C1_COL_TYPE PLS_INTEGER;
TYPE_CODE PLS_INTEGER;
PREC PLS_INTEGER;
SCALE PLS_INTEGER;
LEN PLS_INTEGER;
CSID PLS_INTEGER;
CSFRM PLS_INTEGER;
SCHEMA_NAME VARCHAR2(30);
TYPE_NAME VARCHAR2(30);
VERSION VARCHAR2(30);
ATTR_COUNT PLS_INTEGER;
ATTR_TYPE ANYTYPE;
ATTR_NAME VARCHAR2(100);
V1 VARCHAR2(32767);
N1 NUMBER;
D1 DATE;
UR1 UROWID;
IDS1 INTERVAL DAY TO SECOND;
IYM1 INTERVAL YEAR TO MONTH;
TS1 TIMESTAMP;
TSTZ1 TIMESTAMP WITH TIME ZONE;
TSLTZ1 TIMESTAMP WITH LOCAL TIME ZONE;
BEGIN
OUTSET := NULL;
IF NROWS < 1 THEN
-- is this possible???
RETURN ODCICONST.SUCCESS;
END IF;
--
DBMS_OUTPUT.PUT_LINE('fetch');
IF DBMS_SQL.FETCH_ROWS(SELF.CUR) = 0 THEN
RETURN ODCICONST.SUCCESS;
END IF;
--
DBMS_OUTPUT.PUT_LINE('done');
TYPE_CODE := SELF.RET_TYPE.GETINFO(PREC,
SCALE,
LEN,
CSID,
CSFRM,
SCHEMA_NAME,
TYPE_NAME,
VERSION,
ATTR_COUNT);
ANYDATASET.BEGINCREATE(DBMS_TYPES.TYPECODE_OBJECT,
SELF.RET_TYPE,
OUTSET);
OUTSET.ADDINSTANCE;
OUTSET.PIECEWISE();
FOR I IN 1 .. ATTR_COUNT LOOP
TYPE_CODE := SELF.RET_TYPE.GETATTRELEMINFO(I,
PREC,
SCALE,
LEN,
CSID,
CSFRM,
ATTR_TYPE,
ATTR_NAME);
DBMS_OUTPUT.PUT_LINE(ATTR_NAME);
CASE TYPE_CODE
WHEN DBMS_TYPES.TYPECODE_CHAR THEN
DBMS_SQL.COLUMN_VALUE(SELF.CUR, I, V1);
OUTSET.SETCHAR(V1);
WHEN DBMS_TYPES.TYPECODE_VARCHAR2 THEN
DBMS_SQL.COLUMN_VALUE(SELF.CUR, I, V1);
OUTSET.SETVARCHAR2(V1);
WHEN DBMS_TYPES.TYPECODE_NUMBER THEN
DBMS_SQL.COLUMN_VALUE(SELF.CUR, I, N1);
OUTSET.SETNUMBER(N1);
WHEN DBMS_TYPES.TYPECODE_DATE THEN
DBMS_SQL.COLUMN_VALUE(SELF.CUR, I, D1);
OUTSET.SETDATE(D1);
WHEN DBMS_TYPES.TYPECODE_UROWID THEN
DBMS_SQL.COLUMN_VALUE(SELF.CUR, I, UR1);
OUTSET.SETUROWID(UR1);
WHEN DBMS_TYPES.TYPECODE_INTERVAL_DS THEN
DBMS_SQL.COLUMN_VALUE(SELF.CUR, I, IDS1);
OUTSET.SETINTERVALDS(IDS1);
WHEN DBMS_TYPES.TYPECODE_INTERVAL_YM THEN
DBMS_SQL.COLUMN_VALUE(SELF.CUR, I, IYM1);
OUTSET.SETINTERVALYM(IYM1);
WHEN DBMS_TYPES.TYPECODE_TIMESTAMP THEN
DBMS_SQL.COLUMN_VALUE(SELF.CUR, I, TS1);
OUTSET.SETTIMESTAMP(TS1);
WHEN DBMS_TYPES.TYPECODE_TIMESTAMP_TZ THEN
DBMS_SQL.COLUMN_VALUE(SELF.CUR, I, TSTZ1);
OUTSET.SETTIMESTAMPTZ(TSTZ1);
WHEN DBMS_TYPES.TYPECODE_TIMESTAMP_LTZ THEN
DBMS_SQL.COLUMN_VALUE(SELF.CUR, I, TSLTZ1);
OUTSET.SETTIMESTAMPLTZ(TSLTZ1);
END CASE;
END LOOP;
OUTSET.ENDCREATE;
RETURN ODCICONST.SUCCESS;
END;
--
MEMBER FUNCTION ODCITABLECLOSE(SELF IN PIVOTIMPL) RETURN NUMBER IS
C INTEGER;
BEGIN
C := SELF.CUR;
DBMS_SQL.CLOSE_CURSOR(C);
RETURN ODCICONST.SUCCESS;
END;
END;
/

ORA-06550: line 1, column 7 (PL/SQL: Statement ignored) Error

I am getting following error for the stored procedure and not able to understand the issue (must be from db side) While googling, I found similar issues but couldn't get the solution. Can any one help me please find the error in PROCEDURE ??
Error :-
18:58:50,281 ERROR [STDERR] java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'SP_DIST_RETAILER_REMAP'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Stored Prodedure(SP_DIST_RETAILER_REMAP) :-
CREATE OR REPLACE PROCEDURE SMAPRD02.SP_DIST_RETAILER_REMAP (
i_old_dist_code IN VARCHAR2,
i_new_dist_code IN VARCHAR2,
i_territory_remapping IN NUMBER,
i_remapping_reason IN VARCHAR2,
i_trans_doneby_rolename IN VARCHAR2,
i_trans_doneby_id IN NUMBER,
i_trans_dist_rolename IN VARCHAR2,
i_trans_ret_rolename IN VARCHAR2,
i_activity_type IN VARCHAR2,
i_ret_list IN V_ARRAY,
result OUT VARCHAR2,
i_o_query OUT VARCHAR2
)
AS
--i_ret_codes OUT VARCHAR2;
v_dist_count NUMBER;
v_ret_count NUMBER;
v_ret_codes VARCHAR2(10000) := '';
v_flag VARCHAR2(10) := 'true';
v_trans_id NUMBER;
v_query VARCHAR2(10000);
BEGIN
IF i_territory_remapping = 1 then
SELECT count(*) into v_dist_count FROM tblemployee where EMPCODE = i_new_dist_code and circle_code = (select emp.circle_code
from tblemployee emp where emp.empcode = i_old_dist_code) and upper(user_type) like upper('%dist%') and upper(ACCESS_TO) in ('SALES','BOTH') and upper(stage) not in (upper('InActive'));
ELSE
SELECT count(*) into v_dist_count FROM tblemployee where EMPCODE = i_new_dist_code and circle_code = (select emp.circle_code from tblemployee emp
where emp.empcode = i_old_dist_code) and cluster_code = (select emp.cluster_code from tblemployee emp where emp.empcode = i_old_dist_code)
and upper(user_type) like upper('%dist%') and upper(ACCESS_TO) in ('SALES','BOTH') and upper(stage) not in (upper('InActive'));
END IF;
IF v_dist_count =0 THEN
result := 'invalid_new_dist_code';
v_flag := 'false';
ELSIF v_dist_count = 1 THEN
SELECT count(*) into v_ret_count FROM tblretailer t where t.DIST_CODE = i_old_dist_code and (upper(t.ACCESS_TO) = 'SALES' or upper(t.ACCESS_TO) = 'BOTH');
--SELECT count(*) into v_ret_count FROM tblretailer t where t.DIST_CODE = i_old_dist_code and upper(t.ACCESS_TO) = 'SALES' and upper(t.stage) in ('APPROVED','INACTIVE');
IF v_ret_count=i_ret_list.count THEN
IF i_territory_remapping = 1 THEN
result := 'no_ret_left';
v_flag := 'false';
END IF;
ELSE
IF i_territory_remapping != 1 THEN
result := 'ret_left';
v_flag := 'false';
END IF;
END IF;
END IF;
IF i_ret_list is null or i_ret_list.count = 0 THEN
result := 'empty retailers list';
v_flag := 'false';
END IF;
/*FOR i IN i_ret_list.FIRST .. i_ret_list.LAST
LOOP
IF v_ret_codes is null
THEN
v_ret_codes := ''''||i_ret_list(i)||'''';
ELSE
v_ret_codes := v_ret_codes||','''||i_ret_list(i)||'''';
END IF;
IF v_ret_codes is null
THEN
v_ret_codes := i_ret_list(i);
ELSE
v_ret_codes := v_ret_codes||','||i_ret_list(i);
END IF;
END LOOP;
i_ret_codes := v_ret_codes;
v_flag := 'false';
result := 'success';*/
IF v_flag = 'true' THEN
FOR i IN i_ret_list.FIRST .. i_ret_list.LAST
LOOP
IF v_ret_codes is null
THEN
v_ret_codes := ''''||i_ret_list(i)||'''';
ELSE
v_ret_codes := v_ret_codes||','''||i_ret_list(i)||'''';
END IF;
END LOOP;
--i_ret_codes := v_ret_codes;
--update tblretailer set dist_code=i_new_dist_code,DIST_ID=to_number(i_new_dist_code),cluster_code=(select cluster_code from tblemployee where empcode = i_new_dist_code),FOSID='',FOS_CODE='',DSR_ID='',DSR_CODE='',LAST_UPDATED_DATE=sysdate where retcode in (v_ret_codes);
v_query := 'update tblretailer set dist_code='||i_new_dist_code||',DIST_ID=to_number('||i_new_dist_code||'),cluster_code=(select cluster_code from tblemployee where empcode = '||i_new_dist_code||'),FOSID='''',FOS_CODE='''',DSR_ID='''',DSR_CODE='''',LAST_UPDATED_DATE=sysdate where retcode in ('||v_ret_codes||')';
execute immediate (v_query);
--i_query :='update tblretailer set dist_code='||i_new_dist_code||',DIST_ID=to_number('||i_new_dist_code||'),cluster_code=(select cluster_code from tblemployee where empcode = '||i_new_dist_code||'),FOSID='',FOS_CODE='',DSR_ID='',DSR_CODE='',LAST_UPDATED_DATE=sysdate where retcode in ('||v_ret_codes||');';
insert into TBL_TRANSFER_SUP_MASTER(MASTER_ID,TRANS_ID,TRANS_DONEBY_ROLENAME,TRANS_DONEBY_ID,TRANS_FROM_ROLENAME,TRANS_FROM,TRANS_TO_ROLENAME,TRANS_TO,ACTIVITY_CODE,TRANS_DATE,TRANSFER_REASON,LAST_UPDATED_DATE)
values(SUP_MASTER_TRANS_ID_SEQ.nextval,SUP_MASTER_TRANS_ID_SEQ.nextval,i_trans_doneby_rolename,i_trans_doneby_id,i_trans_dist_rolename,i_old_dist_code,i_trans_dist_rolename,i_new_dist_code,'101',sysdate,i_remapping_reason,sysdate) return TRANS_ID into v_trans_id;
FOR i IN i_ret_list.FIRST .. i_ret_list.LAST
LOOP
insert into TBL_TRANSFER_SUP_DTLS(DTLS_ID,TRANS_ID,TRANS_ON_ROLENAME,TRANS_ON_ID,LAST_UPDATED_DATE)
values(SUP_DTLS_ID_SEQ.nextval,v_trans_id,i_trans_ret_rolename,i_ret_list(i),sysdate);
END LOOP;
IF SQL%ROWCOUNT>0 THEN
result := 'success';
ELSE
result := 'failure';
END IF;
--update tblstock set NEW_DIST_CODE_REMAP=i_new_dist_code,REMAP_DATE=sysdate,LAST_UPDATED_DATE=sysdate where (DIST_CODE=i_old_dist_code or NEW_DIST_CODE_REMAP=i_old_dist_code) and RET_CODE in (v_ret_codes);
v_query := 'update tblstock set NEW_DIST_CODE_REMAP='||i_new_dist_code||',REMAP_DATE=sysdate,LAST_UPDATED_DATE=sysdate where (DIST_CODE='||i_old_dist_code||' or NEW_DIST_CODE_REMAP='||i_old_dist_code||') and RET_CODE in ('||v_ret_codes||')';
execute immediate (v_query);
i_o_query := v_query;
insert all into TBL_ACTIVITY_LOG (LOG_ID,TRANS_ID,ACTIVITY_DONEBY_ROLENAME,ACTIVITY_DONEBY_ID,ACTIVITY_REFERENCE_ID,ACTIVITY_CODE,ACTIVITY_DATE)
values(ACTIVITY_LOG_TRANS_ID_SEQ.NEXTVAL,ACTIVITY_LOG_TRANS_ID_SEQ.NEXTVAL,i_trans_doneby_rolename,i_trans_doneby_id,v_trans_id,
act_code,sysdate) select log_config.ACTIVITY_CODE act_code from TBL_ACTIVITY_LOG_CONFIG log_config
where upper(log_config.ACTIVITY_TYPE)= upper(i_activity_type);
END IF;
END;
/
Java Code :-
try{
if(ret_list.size()>0)
ret_code = ret_list.toArray();
con = ConnectionManager.getDirectConnection();
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor(PropertyLoader.RET_SECONDARY_V_ARRAY,con);
ARRAY array_to_pass = new ARRAY( descriptor,con, ret_code );
cstmt = con.prepareCall("{ call SP_DIST_RETAILER_REMAP(?,?,?,?,?,?,?,?,?,?,?,?)}");
cstmt.setString(1,old_dist_code.trim());
cstmt.setString(2,new_dist_code.trim());
if(territory_remapping)
cstmt.setInt(3,1);
else
cstmt.setInt(3,2);
cstmt.setString(4,remapping_reason);
cstmt.setString(5,userVO.getRolename().trim());
cstmt.setInt(6,userVO.getEmpid());
cstmt.setString(7,PropertyLoader.DISTRIBUOTR_ROLENAME);
cstmt.setString(8,PropertyLoader.RETAILER_ROLENAME);
cstmt.setString(9,PropertyLoader.ACTIVITY_TYPES_RETAILER_REMAPPING);
cstmt.setArray(10,array_to_pass);
cstmt.registerOutParameter(11,Types.VARCHAR);
cstmt.registerOutParameter(12,Types.VARCHAR);
/*cstmt.registerOutParameter(13,Types.VARCHAR);*/
cstmt.execute();
status = cstmt.getString(11);
System.out.println("Remap Update Query "+cstmt.getString(12));
//System.out.println(cstmt.getString(13));
}
If the value stored in PropertyLoader.RET_SECONDARY_V_ARRAY is not "V_ARRAY", then you are using different types; even if they are declared identically (e.g. both are table of number) this will not work.
You're hitting this data type compatibility restriction:
You can assign a collection to a collection variable only if they have
the same data type. Having the same element type is not enough.
You're trying to call the procedure with a parameter that is a different type to the one it's expecting, which is what the error message is telling you.
The procedure which you are using is should be properly declared in the place which you are using it. For an example if it is under a user and in a package then it should be in that order. The username, package and procedurename.