简体   繁体   中英

TOAD ORACLE SQL - Export CSV Script

I would like to export in .csv file results of the following query using a SQL Script (not using a Toad tool).

The objective is to use this SQL script by an external tool : eControl-M Workload Automation - BMC This tool just has to execute this sql Query + export script Can you please help me ?

SELECT * FROM TABLE

I found this script. What do you think about this script?

SET COLSEP ";"

COL colonne1 FORMAT A25
COL colonne2 FORMAT A30
COL colonne3 FORMAT A30
COL colonne4 FORMAT A12
COL colonne5 FORMAT A20
COL colonne6 FORMAT A25

SET TERM OFF
SET AUTOTRACE OFF
SET VERIFY OFF
SET ECHO OFF
SET FEEDBACK OFF
SET HEAD ON
SET LINESIZE 1000 
SET PAGESIZE 5000

SET TRIMSPOOL ON

SPOOL &1; --- Mettre la destination du fichier en lieu et place du &1 ---

--- ta requete ---
select....

SPOOL OFF; 
EXIT;

-- Normalement tu vas pouvoir te débrouiller avec ça

Tools like TOAD, Oracle SQL Developer, and SQL Server Management Studio all have built in features to export/save query results to .CSV format. These are all part of the tool's functionality and not a function of the SQL language.

I am not familiar with eControl-M Workload Automation, but assuming you can get text output from that tool, you should be able to construct the output using Oracle's concatenate operator || and test it in something like TOAD, just output the results to TEXT format. Note: Concatenating fields can be simple if they are a VARCHAR() or CHAR() data type, but may require explicit conversion if they are some other data type.

Example:

SELECT (FIRST || ',' || LAST || ',' || AGE || ',' || SAL) FROM tbl1;

Example in SQL Fiddle

If you have other data types that need explicit conversion before concatenating to string output, you may want to look into using Oracle's CAST Function.

Hopefully this will help you get started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM