Search notes:

Oracle: SQL Loader Example: call a PL/SQL function to determine a value

@drop_if_exists tq84_sql_loader_10

create table tq84_sql_loader_10 (
     id     varchar2(10),
     result number
);
Github repository Oracle-Patterns, path: /SQLLoader/ex_10/create_table.sql
create function tq84_func(op varchar2, num1 in number, num2 in number) return number is
begin

  if op = 'plus'  then return num1 + num2; end if;
  if op = 'minus' then return num1 - num2; end if;
  if op = 'mult'  then return num1 * num2; end if;
  if op = 'div'   then return num1 / num2; end if;
  return 0;

end tq84_func;
/
Github repository Oracle-Patterns, path: /SQLLoader/ex_10/create_func.plsql
options(skip=1)
load data
infile 'data.csv'
insert
into table tq84_sql_loader_10
fields 
  terminated by ',' 
  optionally enclosed by '"'
(
  id,
  op        boundfiller,
  num1      boundfiller,
  num2      boundfiller,
  result   "tq84_func(:op, :num1, :num2)"
)
Github repository Oracle-Patterns, path: /SQLLoader/ex_10/load.ctl
id,op,num1,num2
abc,plus,22,20
def,minus,12,4
ghi,mult,10,10
jkl,div,35,7
Github repository Oracle-Patterns, path: /SQLLoader/ex_10/data.csv
start create_table.sql
start create_func.plsql

host sqlldr control=load.ctl userid=rene/rene

select * from tq84_sql_loader_10;

prompt
prompt check load.bad file
prompt
Github repository Oracle-Patterns, path: /SQLLoader/ex_10/all.sql

See also

Other SQL Loader examples
SQL*Loader

Index