Showing posts with label Oracle - SQL Plus. Show all posts
Showing posts with label Oracle - SQL Plus. Show all posts

Tuesday, December 11, 2007

Data extraction from oracle to csv file

First of all we have to create a script (test.sql) to extract our data:

spool test.csv
set colsep ";"
set pagesize 0
set linesize 10000

SELECT A, B, C
FROM TB_AA
INNER JOIN TB_BB
ON TB_BB.ID = TB_AA.EXT_ID
WHERE TB_AA.FOO = 4;

spool off
exit

Once this is done we can use this command to run the script we have just created:

$ sqlplus user/passwor@ @test.sql

At this point we will obtain as result a file (test.csv) in our folder.

Oracle - SQL Plus - See avaible tables in your table space

To see all the table available inside your table space you can use the views available inside sys schema:

SQL> select table_name from user_tables;

Now lets try to have additional information:

SQL>select sys.USER_TABLES.table_name, sys.USER_TAB_COLS.COLUMN_NAME, sys.USER_TAB_COLS.DATA_TYPE
from sys.USER_TABLES
join sys.USER_TAB_COLS on sys.USER_TAB_COLS.TABLE_NAME = sys.USER_TABLES.TABLE_NAME
order by sys.USER_TABLES.table_name asc;