Monday, 18 April 2016

How to take Data EXTRACT of a database table in a text file using shell script

In this tutorial , you will learn how we can take extract of a database table and save it in a text file by using Shell Script in Linux.

sqlplus dbuser/dbpasswd@dbinstance<< EOF
set pagesize 0;
set trims on;
set linesize 32767;
set feedback 0;
set colsep ",";
set timing off;
set serveroutput on;
set autocommit off;
set heading on;
spool fileName.txt

select COLUMN_1||','||COLUMN_2||','||COLUMN_3 from MYDBTABLE;

spool off;

exit;

EOF

Save above code in a file (i.e DBEXTRACT.sh) , and run that file. Make sure to provide  execute permission on the file. 
(For Execute Permission, run command chmod 777  DBEXTRACT.sh )

For explanation of these SET statement : please check Oracle docs. I will explain these above set statements in my next post.

No comments:

Post a Comment