Last active
April 22, 2020 15:26
-
-
Save fibo/6807322 to your computer and use it in GitHub Desktop.
Script to spool Oracle table content to a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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