Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
load data
append
into table emp
fields terminated by "," optionally enclosed by '"'
( empno, empname, sal, deptno )
load data
replace you can use truncate to improve performance
into table departments
( dept position (02:05) char(4),
deptname position (08:27) char(20)
)
How to load
LOAD DATA
APPEND
INTO TABLE mailing_list
FIELDS TERMINATED BY ","
( addr,
city,
state,
zipcode,
mailing_addr "decode(:mailing_addr, null, :addr, :mailing_addr)",
mailing_city "decode(:mailing_city, null, :city, :mailing_city)",
mailing_state
)
LOAD DATA
APPEND
INTO TABLE my_selective_table
WHEN (01) <> 'H' and (01) <> 'T' and (30:37) = '20031217'
(
region CONSTANT '31',
service_key POSITION(01:11) INTEGER EXTERNAL,
call_b_no POSITION(12:29) CHAR
)
LOAD DATA
APPEND
INTO TABLE my_selective_table
WHEN (01) <> 'H' and (01) <> 'T'
(
region CONSTANT '31',
service_key POSITION(01:11) INTEGER EXTERNAL,
call_b_no POSITION(12:29) CHAR
)
INTO TABLE my_selective_table
WHEN (30:37) = '20031217'
(
region CONSTANT '31',
service_key POSITION(01:11) INTEGER EXTERNAL,
call_b_no POSITION(12:29) CHAR
)
LOAD DATA
INFILE *
INTO TABLE image_table
REPLACE
FIELDS TERMINATED BY ','
(
image_id INTEGER(5),
file_name CHAR(30),
image_data LOBFILE (file_name) TERMINATED BY EOF
)
BEGINDATA
001,image1.gif
002,image2.jpg
003,image3.jpg
Control file
UNRECOVERABLE
LOAD DATA
TRUNCATE
INTO TABLE customers
FIELDS TERMINATED BY "|"
( CUST_ID,
CUST_FIRST_NAME,
CUST_LAST_NAME,
CUST_GENDER,
CUST_YEAR_OF_BIRTH,
CUST_MARITAL_STATUS,
CUST_STREET_ADDRESS,
CUST_POSTAL_CODE,
CUST_CITY,
CUST_STATE_PROVINCE,
COUNTRY_ID,
CUST_MAIN_PHONE_NUMBER,
CUST_INCOME_LEVEL,
CUST_CREDIT_LIMIT,
CUST_EMAIL)
Data
BEGIN
v_dir := '/u01/app/oracle/common/out';
v_filename := 'dept01.csv';
v_file := UTL_FILE.FOPEN(v_dir, v_filename, 'r');
-- --------------------------------------------------------
-- Loop over the file, reading in each line. GET_LINE will
-- raise NO_DATA_FOUND when it is done, so we use that as
-- the exit condition for the loop.
-- --------------------------------------------------------
LOOP
BEGIN
UTL_FILE.GET_LINE(v_file, v_line);
EXCEPTION
WHEN no_data_found THEN
exit;
END;
-- ----------------------------------------------------------
-- Each field in the input record is delimited by commas. We
-- need to find the locations of the two commas in the line,
-- and use these locations to get the fields from v_line.
-- ----------------------------------------------------------
v_1st_Comma := INSTR(v_line, ',' ,1 , 1);
v_2nd_Comma := INSTR(v_line, ',' ,1 , 2);
END LOOP;
UTL_FILE.FCLOSE(v_file);
COMMIT;
END;
/
SQL UnLoader There is nothing called as SQL Unloader
Use spool
set echo off newpage 0 space 0 pagesize 0 feed off head off
trimspool on
spool oradata.txt
select col1 || ',' || col2 || ',' || col3
from tab1
where col2 = 'XYZ';
spool off
Use UTL_FILE
l_status := dbms_sql.execute(l_theCursor);
loop
exit when ( dbms_sql.fetch_rows(l_theCursor) <= 0 );
l_separator := '';
for i in 1 .. l_colCnt loop
dbms_sql.column_value( l_theCursor, i,
l_columnValue );
utl_file.put( l_output, l_separator ||
l_columnValue );
l_separator := p_separator;
end loop;
utl_file.new_line( l_output );
l_cnt := l_cnt+1;
end loop;
dbms_sql.close_cursor(l_theCursor);
utl_file.fclose( l_output );
return l_cnt;
end dump_csv;
/