Home » RDBMS Server » Server Utilities » sql loader
sql loader [message #73275] Mon, 15 March 2004 05:19 Go to next message
satish
Messages: 112
Registered: September 2000
Senior Member
hi ,
Is there a way to put user defined functions into the controlfile of the loader.The function should be capable of generating data values after execcuting some queries and load the data into table.if yes please gimme an example showing the syntax of how to use it.tht would help me greatly.thnks frank for ur earlier reply .plz help me on this.regards
satish.
Re: sql loader [message #73298 is a reply to message #73275] Thu, 18 March 2004 02:12 Go to previous message
Barbara Boehmer
Messages: 9097
Registered: November 2002
Location: California, USA
Senior Member
Example:

scott@ORA92> -- lookup table that function selects values from:
scott@ORA92> DESC lookup_table
 Name                                                  Null?    Type
 ----------------------------------------------------- -------- ------------------------------------
 LOOKUP_ID                                                      NUMBER
 LOOKUP_VALUE                                                   VARCHAR2(5)

scott@ORA92> SELECT * FROM lookup_table
  2  /

 LOOKUP_ID LOOKU
---------- -----
         1 TEST1
         2 TEST2
         3 TEST3
         4 TEST4
         5 TEST5


scott@ORA92> -- function:
scott@ORA92> CREATE OR REPLACE FUNCTION <b>test_function</b>
  2    (p_lookup_id IN lookup_table.lookup_id%TYPE)
  3    RETURN VARCHAR2
  4  AS
  5    v_lookup_value lookup_table.lookup_value%TYPE;
  6  BEGIN
  7    SELECT lookup_value
  8    INTO   v_lookup_value
  9    FROM   lookup_table
 10    WHERE  lookup_id = p_lookup_id;
 11    RETURN v_lookup_value;
 12  EXCEPTION
 13    WHEN NO_DATA_FOUND THEN RETURN NULL;
 14  END test_function;
 15  /

Function created.

scott@ORA92> SHOW ERRORS
No errors.


scott@ORA92> -- contents of text file test.dat that has values used in loading data:
1 
2 
3 
4
5 


scott@ORA92> -- empty table to load data into
scott@ORA92> DESC test_table
 Name                                                  Null?    Type
 ----------------------------------------------------- -------- ------------------------------------
 TEST_VALUE                                                     VARCHAR2(5)

scott@ORA92> SELECT * FROM test_table
  2  /

no rows selected


scott@ORA92> -- contents of SQL*Loader control file test.ctl:
LOAD DATA
INFILE 'test.dat'
REPLACE
INTO TABLE test_table
FIELDS TERMINATED BY WHITESPACE
TRAILING NULLCOLS
  (test_value "<b>test_function</b> (:test_value)")


scott@ORA92> -- load data:
scott@ORA92> host sqlldr scott/tiger control=test.ctl log=test.log


scott@ORA92> -- results:
scott@ORA92> SELECT * FROM test_table
  2  /

TEST_
-----
TEST1
TEST2
TEST3
TEST4
TEST5
Previous Topic: sql loader rejects all -ve decimal values
Next Topic: SQL*PLUS COPY (IMPORT EXPORT)
Goto Forum:
  


Current Time: Sat Jun 29 04:56:08 CDT 2024