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