Skip to content

Instantly share code, notes, and snippets.

@fibo
Last active April 22, 2020 15:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save fibo/6807322 to your computer and use it in GitHub Desktop.
Save fibo/6807322 to your computer and use it in GitHub Desktop.
Script to spool Oracle table content to a file
#!/bin/bash
#
# [Gist](https://gist.github.com/fibo/6807322)
#
## Configuration
#
# Don' t forget to edit filename and query, see below.
#
## How to launch
#
# $ chmod +x spool_Oracle_table.sh
# $ nohup spool_Oracle_table.sh > spool_Oracle_table.nohup &
sqlplus -S /nolog <<EOF > /dev/null
-------------------------------------------
-- Set your credentials here
-------------------------------------------
CONN Oracle_user/Oracle_password@Oracle_sid
-------------------------------------------
SET ARRAY 100
SET PAGES 0
SET WRAP OFF
SET FLUSH OFF
SET FEED OFF
SET FEEDBACK OFF
SET ECHO OFF
SET VERIFY OFF
SET TERM OFF
SET TRIMSPOOL ON
SET HEAD OFF
SET TRIM ON
SET COLSEP "|"
SET LINESIZE 800 --> this value should be enough otherwise rows will be truncated
--------------------------------------------------------------------
-- edit you filename here
SPOOL filename.dat
--------------------------------------------------------------------
-- your spool query here, something like
-- SELECT
-- col1
-- || '|' || col2
-- || '|' || TRIM(col3_varchar)
-- || '|' || TO_CHAR(col3_date, 'yyyy-mm-dd')
-- FROM table;
SPOOL OFF
EXIT
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment