Creating a ascii text file of oracle table data with pipe delimited columns.
Code:
#!/bin/ksh
#First line in the .txt file is column names
USR=username/password
echo "set feedback off\n set pagesize 0\n
select 'XXTT' || table_name from user_tables ;" | sqlplus -s $USR | grep '^XXTT' | cut -c5- |
while read TABL
do
STR="nothing"
STR1="nothing"
echo "desc $TABL\n" | sqlplus -s $USR | tail +3 | grep "^[A-Z,a-z]" | awk '{print $1}' |
while read COLUM
do
if [ "$STR" = "nothing" ] then
STR=$COLUM
STR1=$COLUM
else
STR="$STR || '|' || $COLUM"
STR1="$STR1|$COLUM"
fi
Done
echo "$STR1" > $TABL.txt
echo "set feedback off\nset pagesize 0\nset linesize 2000\nselect $STR from $TABL;"| sqlplus -s $USR >> $TABL.txt
Done
Welcome to the GEEK world, best place where you find topic about latest cutting edge technology on website and mobile. Learn and grow your knowledge with the information and tutorials about Website designing, CSS tutorials, Java Script tutorials, Ruby tutorials, ROR tutorials, HTML tutorials, HTML5 , JQuery, Javascript tutorials, Photoshop tutorials, Flash, games tutorials, Cheat sheets, Design tools, Action Scripts as well as MySql, Oracle and many more in a easy way to use and understand.
Subscribe to:
Post Comments (Atom)
1 comment:
I fail to understand where do i substitute the table name. For example if my table is called "filter" where do I write it in the script.
Post a Comment