abdeen-ahmad
12/10/2015 - 6:45 PM

Export Tables to txt file #Extract

Export Tables to txt file #Extract

--sqlplus -s ABDEEN/dba@XE @tmp.sql >  C:\Users\abdee_000\Documents\myoutputfile.txt

set echo       off
set feedback   off
set heading    off
set linesize   32767
set pagesize   0
set termout    off
set trimspool  on
set verify     off
set colsep ","
spool C:\Users\abdee_000\Documents\myoutputfile2.txt
select * from dept;
spool off;
--First create directory to read the file from
CREATE or replace DIRECTORY TEST_DIR AS 'C:\Users\abdee_000\Documents';

--Second Give grants to the user on Directory
grant read, write, execute on DIRECTORY TEST_DIR to HR;

--Third Run the code
CREATE TABLE countries_ext (
  country_code      VARCHAR2(50),
  country_name      VARCHAR2(50),
  country_language  VARCHAR2(50),
  country_no        VARCHAR2(50)  
)
ORGANIZATION EXTERNAL (
  TYPE ORACLE_LOADER
  DEFAULT DIRECTORY TEST_DIR
  ACCESS PARAMETERS (
    RECORDS DELIMITED BY NEWLINE
    FIELDS TERMINATED BY ','
    MISSING FIELD VALUES ARE NULL
    (
      country_code      CHAR(50),
      country_name      CHAR(50),
      country_language  CHAR(50),
      country_no        CHAR(50) 
    )
  )
  LOCATION ('t001.txt')  --file to read from
)
PARALLEL 1
REJECT LIMIT UNLIMITED;