I think your problem ist the data type. You store the file in blob
and your table function needs a clob
.
I don't know your package csv_util_pkg
, but i think the following is a solution for you.
Setup:
I used the Package csv_util_pkg
from https://github.com/mortenbra/alexandria-plsql-utils
create table
create table tableA (id number(10),
file_name varchar2(255),
file_uploaded blob);
upload data
utl_raw.cast_to_raw()
to create blob data
insert into tableA (id,file_name, file_uploaded)
values (
1,
'employees.csv',
utl_raw.cast_to_raw(
'"EMPLOYEE_ID","FIRST_NAME","LAST_NAME","EMAIL","PHONE_NUMBER","HIRE_DATE","JOB_ID","SALARY","COMMISSION_PCT","MANAGER_ID","DEPARTMENT_ID"
100,"Steven","King","SKING","515.123.4567",17.06.2003,"AD_PRES",24000,,,90
101,"Neena","Kochhar","NKOCHHAR","515.123.4568",21.09.2005,"AD_VP",17000,,100,90
102,"Lex","De Haan","LDEHAAN","515.123.4569",13.01.2001,"AD_VP",17000,,100,90')
);
create helper function
get it from https://stackoverflow.com/a/12854297/12277315
create function clobfromblob(p_blob blob) return clob is
l_clob clob;
l_dest_offsset integer := 1;
l_src_offsset integer := 1;
l_lang_context integer := dbms_lob.default_lang_ctx;
l_warning integer;
begin
if p_blob is null then
return null;
end if;
dbms_lob.createTemporary(lob_loc => l_clob
,cache => false);
dbms_lob.converttoclob(dest_lob => l_clob
,src_blob => p_blob
,amount => dbms_lob.lobmaxsize
,dest_offset => l_dest_offsset
,src_offset => l_src_offsset
,blob_csid => dbms_lob.default_csid
,lang_context => l_lang_context
,warning => l_warning);
return l_clob;
end;
/
use helper function
select d.file_name, csv.*
from tableA d, table(csv_util_pkg.clob_to_csv(clobfromblob(d.file_uploaded))) csv
where d.id= 1;
Result
note, my example is limited to 20 columns. See type t_csv_line
in types.sql