473,394 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to extract output file comma deli. calling XX.sql file

db2 EXPORT TO ~/data_export/$TABLE.ixf OF IXF MESSAGES messages.txt SELECT \* FROM schema.$TABLE
Jun 12 '14 #1
2 1502
I'd probably use sqlplus myself (see;
http://asktom.oracle.com/~tkyte/flat/index.html
for some tools).

PL/SQL can do it, it might look like:

Expand|Select|Wrap|Line Numbers
  1. create or replace function  dump_csv( p_query     in varchar2,
  2.                                       p_separator in varchar2 
  3.                                                     default ',',
  4.                                       p_dir       in varchar2 ,
  5.                                       p_filename  in varchar2 )
  6. return number
  7. AUTHID CURRENT_USER
  8. is
  9.     l_output        utl_file.file_type;
  10.     l_theCursor     integer default dbms_sql.open_cursor;
  11.     l_columnValue   varchar2(2000);
  12.     l_status        integer;
  13.     l_colCnt        number default 0;
  14.     l_separator     varchar2(10) default '';
  15.     l_cnt           number default 0;
  16. begin
  17.     l_output := utl_file.fopen( p_dir, p_filename, 'w' );
  18.  
  19.     dbms_sql.parse(  l_theCursor,  p_query, dbms_sql.native );
  20.  
  21.     for i in 1 .. 255 loop
  22.         begin
  23.             dbms_sql.define_column( l_theCursor, i, 
  24.                                     l_columnValue, 2000 );
  25.             l_colCnt := i;
  26.         exception
  27.             when others then
  28.                 if ( sqlcode = -1007 ) then exit;
  29.                 else
  30.                     raise;
  31.                 end if;
  32.         end;
  33.     end loop;
  34.  
  35.     dbms_sql.define_column( l_theCursor, 1, l_columnValue, 
  36.                             2000 );
  37.  
  38.     l_status := dbms_sql.execute(l_theCursor);
  39.  
  40.     loop
  41.         exit when ( dbms_sql.fetch_rows(l_theCursor) <= 0 );
  42.         l_separator := '';
  43.         for i in 1 .. l_colCnt loop
  44.             dbms_sql.column_value( l_theCursor, i, 
  45.                                    l_columnValue );
  46.             utl_file.put( l_output, l_separator ||  
  47.                                     l_columnValue );
  48.             l_separator := p_separator;
  49.         end loop;
  50.         utl_file.new_line( l_output );
  51.         l_cnt := l_cnt+1;
  52.     end loop;
  53.     dbms_sql.close_cursor(l_theCursor);
  54.  
  55.     utl_file.fclose( l_output );
  56.     return l_cnt;
  57. end dump_csv;
  58. /
  59.  
  60.  
  61. You would use that for example like this:
  62.  
  63. create or replace procedure test_dump_csv
  64. as
  65.     l_rows  number;
  66. begin
  67.     l_rows := dump_csv( 'select * 
  68.                            from all_users 
  69.                            where rownum < 25', 
  70.                         ',', '/tmp', 'test.dat' );
  71. end;
  72. /

Make sure to read about the INIT.ORA parameters (utl_file_dir) you need to setup !!!
Jun 13 '14 #2
Anas Mosaad
185 128KB
Your export command is exporting IXF file, you just need to change it to DEL instead of IXF.
Jun 21 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Kenneth Koski | last post by:
Hello All, I have a comma delimited text file, which I would like to move into a SQL 2000 table . I created a DTS package in SQL Server and saved it as a VB.bas . I am writting the code in C#...
9
by: Bernie Yaeger | last post by:
Is there a way to convert or copy a .xml file to a comma delimited text file using vb .net? Thanks for any help. Bernie Yaeger
3
by: Avi | last post by:
I need to create a text file that has the data from the 10 tables in the database. The number of fields in the tables exceeds 255 and so I cannot make a new table with all the fields and then...
4
by: JustSomeGuy | last post by:
Hi. I have a comma delimited text file that I want to parse. I was going to use fscanf from the C library but as my app is written in C++ I thought I'd use the std io stream library... My Text...
3
by: gujarsachin2001 | last post by:
Hi friends, I m just stuck with extracting excel file data into text file. So can any body please help me out. thx, Sachin.
0
MMcCarthy
by: MMcCarthy | last post by:
This is a module that imports information to a Query or a Table from comma separated values file in a text format! It is very helpful for getting information from other applications and from files! ...
6
by: Mohammad Omer | last post by:
Hi, I tried to validate file path without calling file creating functions. Is it possible? How? Regards, -aims
1
by: Quentin | last post by:
I want to take a comma delimited text file and export it to excel format, using the comma as the delimiter. Any help on this would be great, thank you.
2
by: rparimi | last post by:
I am trying to redirect stderr of a process to a temporary file and then read back the contents of the file, all in the same python script. As a simple exercise, I launched /bin/ls but this doesn't...
3
rizwan6feb
by: rizwan6feb | last post by:
I am trying to extract php code from a php file (php file also contains html, css and javascript code). I am using the following regex for this <\?*?\?> but this doesn't cater quotation marks...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.