How to export Oracle data using shell?

To export Oracle data using a shell script, you can follow these steps:

  1. Create a shell script file, such as export_data.sh.
  2. Configure Oracle database connection information in the script file, including username, password, and database instance name. You can set environment variables using the following command.
export ORACLE_SID=<数据库实例名>
export ORACLE_HOME=<Oracle安装目录>
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH
export NLS_LANG=<字符集>
  1. open sqlplus
sqlplus -S <用户名>/<密码>@<数据库实例名> <<EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SET COLSEP '|'
SPOOL output.txt
SELECT * FROM <表名>;
SPOOL OFF
EOF
  1. open the SQL command line interface
sqlplus -S <用户名>/<密码>@<数据库实例名> @export_data.sql

Export_data.sql is the file that contains the SQL query statements from the previous step.

  1. The exported data will be saved in the specified file, and can be processed and used as needed.

Please note that the code above is for reference only, and the specific script content and parameters need to be modified according to actual circumstances.

广告
Closing in 10 seconds
bannerAds