Generating Text file from table using Shell script

I am using KSH for generating and FTPing a text file from a table.
While generating Text file I am not getting my Column names in orderly manner.
q2="select COLUMN1||' '||COLUMN2||' '||COLUMN3 from table1;"
set pagesize 0
set head off
set trimspool on
set trimout on
set colsep ' '
set linesize 1500
set trimspool on
spool /ss/app11/oastss/reports/$file2
select 'COLUMN1'||' '||'COLUMN2'||' '||'COLUMN3' from dual;
$q2
spool off;
EOF
I am getting the result some what like below in text file
COLUMN1 COLUMN2 COLUMN3
MALLIK_ACCT     17-SEP-11     908030482     
MALLIK_ACCT     17-SEP-11     908266967     
MALLIK_ACCT     17-SEP-11     909570766     
I want the format like below
COLUMN1........ COLUMN2 .... COLUMN3
MALLIK_ACCT ...17-SEP-11 .... 908030482     
MALLIK_ACCT ...17-SEP-11 .... 908266967     
MALLIK_ACCT ...17-SEP-11 .... 909570766
I put dots(.) for illustration purpose.
column data length may icrease some times . it shoudl automatically adjust column and data so that they are in alignment. thanks in advance.

Mallik wrote:
Hi my question is to format the headers so that they will be in alignment with column data and readable.So you want to output a query as a fixed width format data file? How about this (rather than using scripts)...
As sys user:
CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
/As myuser:
CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                     ,p_dir IN VARCHAR2
                                     ,p_header_file IN VARCHAR2
                                     ,p_data_file IN VARCHAR2 := NULL) IS
  v_finaltxt  VARCHAR2(4000);
  v_v_val     VARCHAR2(4000);
  v_n_val     NUMBER;
  v_d_val     DATE;
  v_ret       NUMBER;
  c           NUMBER;
  d           NUMBER;
  col_cnt     INTEGER;
  f           BOOLEAN;
  rec_tab     DBMS_SQL.DESC_TAB;
  col_num     NUMBER;
  v_fh        UTL_FILE.FILE_TYPE;
  v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
BEGIN
  c := DBMS_SQL.OPEN_CURSOR;
  DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
  d := DBMS_SQL.EXECUTE(c);
  DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
  FOR j in 1..col_cnt
  LOOP
    CASE rec_tab(j).col_type
      WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
      WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
      WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
    ELSE
      DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
    END CASE;
  END LOOP;
  -- This part outputs the HEADER
  v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
  FOR j in 1..col_cnt
  LOOP
    CASE rec_tab(j).col_type
      WHEN 1 THEN v_finaltxt := v_finaltxt||rpad(lower(rec_tab(j).col_name),rec_tab(j).col_max_len,' ');
      WHEN 2 THEN v_finaltxt := v_finaltxt||rpad(lower(rec_tab(j).col_name),rec_tab(j).col_max_len,' ');
      WHEN 12 THEN v_finaltxt := v_finaltxt||rpad(lower(rec_tab(j).col_name),greatest(19,length(rec_tab(j).col_name)),' ');
    END CASE;
  END LOOP;
  UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
  IF NOT v_samefile THEN
    UTL_FILE.FCLOSE(v_fh);
  END IF;
  -- This part outputs the DATA
  IF NOT v_samefile THEN
    v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
  END IF;
  LOOP
    v_ret := DBMS_SQL.FETCH_ROWS(c);
    EXIT WHEN v_ret = 0;
    v_finaltxt := NULL;
    FOR j in 1..col_cnt
    LOOP
      CASE rec_tab(j).col_type
        WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                    v_finaltxt := v_finaltxt||rpad(nvl(v_v_val,' '),rec_tab(j).col_max_len,' ');
        WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                    v_finaltxt := v_finaltxt||rpad(nvl(to_char(v_n_val,'fm99999999999999999999999999999999999999'),' '),rec_tab(j).col_max_len,' ');
        WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                    v_finaltxt := v_finaltxt||rpad(nvl(to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),' '),greatest(19,length(rec_tab(j).col_name)),' ');
      END CASE;
    END LOOP;
    UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
  END LOOP;
  UTL_FILE.FCLOSE(v_fh);
  DBMS_SQL.CLOSE_CURSOR(c);
END;This allows for the header row and the data to be written to seperate files if required.
e.g.
SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
PL/SQL procedure successfully completed.Output.csv file contains:
empno                 ename     job      mgr                   hiredate           sal                   comm                  deptno               
7369                  SMITH     CLERK    7902                  17/12/1980 00:00:00800                                         20                   
7499                  ALLEN     SALESMAN 7698                  20/02/1981 00:00:001600                  300                   30                   
7521                  WARD      SALESMAN 7698                  22/02/1981 00:00:001250                  500                   30                   
7566                  JONES     MANAGER  7839                  02/04/1981 00:00:002975                                        20                   
7654                  MARTIN    SALESMAN 7698                  28/09/1981 00:00:001250                  1400                  30                   
7698                  BLAKE     MANAGER  7839                  01/05/1981 00:00:002850                                        30                   
7782                  CLARK     MANAGER  7839                  09/06/1981 00:00:002450                                        10                   
7788                  SCOTT     ANALYST  7566                  19/04/1987 00:00:003000                                        20                   
7839                  KING      PRESIDENT                      17/11/1981 00:00:005000                                        10                   
7844                  TURNER    SALESMAN 7698                  08/09/1981 00:00:001500                  0                     30                   
7876                  ADAMS     CLERK    7788                  23/05/1987 00:00:001100                                        20                   
7900                  JAMES     CLERK    7698                  03/12/1981 00:00:00950                                         30                   
7902                  FORD      ANALYST  7566                  03/12/1981 00:00:003000                                        20                   
7934                  MILLER    CLERK    7782                  23/01/1982 00:00:001300                                        10                   
               The procedure allows for the header and data to go to seperate files if required. Just specifying the "header" filename will put the header and data in the one file.
Adapt to output different datatypes and styles are required (this is currently coded for VARCHAR2, NUMBER and DATE)

Similar Messages

  • Generating Text files from PL/SQL

    To generate Text files from PL/SQL on SERVER, i can use UTL_FILE
    package, but how do i create text files on client ( i.e., on the
    C: drive ) by executing anonymous PL/SQL blocks.
    Thanks in advance.

    You can use DBMS_OUTPUT to display stuff to the screen and the
    SQL*Plus SPOOL command to write screen output to a file on your
    local drive.
    magic!
    APC

  • Generate Text File from Goods Receipt (MIGO)

    Hi Expert,
         Please help me ....................
         My company outsource W/H but when I 'm goods receipt or goods issue (MIGO)
         I send slip GR/IR by Fax to W/H but I want generate text file from system to W/H.
         How can I do?
    Thanks.

    Keerthi Hiremath,
           Please .............
           Can you more explain what is medium of 8 (special function) and other ?
    Thanks.

  • How to write CLOB parameter in a file or XML using shell script?

    I executed a oracle stored procedure using shell script. How can i get the OUT parameter of the procedure(CLOB) and write it in a file or XML in UNIX environment using shell script?
    Edit/Delete Message

    SQL> var c clob
    SQL>
    SQL> begin
      2          select
      3                  DBMS_XMLGEN.getXML(
      4                          'select rownum, object_type, object_name from user_objects where rownum <= 5'
      5                  ) into :c
      6          from    dual;
      7  end;
      8  /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> set long 999999
    SQL> set heading off
    SQL> set pages 0
    SQL> set feedback off
    SQL> set termout off
    SQL> set trimspool on
    // following in the script is not echo'ed to screen
    set echo off
    spool /tmp/x.xml
    select :c from dual;
    spool off
    SQL>
    SQL> --// file size
    SQL> !ls -l /tmp/x.xml
    -rw-rw-r-- 1 billy billy 583 2011-12-22 13:35 /tmp/x.xml
    SQL> --// file content
    SQL> !cat /tmp/x.xml
    <?xml version="1.0"?>
    <ROWSET>
    <ROW>
      <ROWNUM>1</ROWNUM>
      <OBJECT_TYPE>TABLE</OBJECT_TYPE>
      <OBJECT_NAME>BONUS</OBJECT_NAME>
    </ROW>
    <ROW>
      <ROWNUM>2</ROWNUM>
      <OBJECT_TYPE>PROCEDURE</OBJECT_TYPE>
      <OBJECT_NAME>CLOSEREFCURSOR</OBJECT_NAME>
    </ROW>
    <ROW>
      <ROWNUM>3</ROWNUM>
      <OBJECT_TYPE>TABLE</OBJECT_TYPE>
      <OBJECT_NAME>DEPT</OBJECT_NAME>
    </ROW>
    <ROW>
      <ROWNUM>4</ROWNUM>
      <OBJECT_TYPE>TABLE</OBJECT_TYPE>
      <OBJECT_NAME>EMP</OBJECT_NAME>
    </ROW>
    <ROW>
      <ROWNUM>5</ROWNUM>
      <OBJECT_TYPE>TABLE</OBJECT_TYPE>
      <OBJECT_NAME>EMPTAB</OBJECT_NAME>
    </ROW>
    </ROWSET>
    SQL>

  • Generate XML File from table

    How to generate XML file from a table without using UTL_FILE that too in local machine...

    You downloaded the wrong XML Parser!
    XSQL requires Java Parser. Well, there's a copy included with the XSQL package so you actually don't need to do another download.
    You really don't need XSQL if you just want a XML file from DB, you just needed a XML SQL Utility. Download that and run the samples.

  • Generate text file from a group above report

    i have problem in generating report in developer 6 report builder my report is master -detail(group above report)
    when i generate text file or csv file then my report is not in group above,master records are repeated along with every detail record.
    is there any solution that i generate group above report in text or csv file
    instead of pdf,rtf,html
    please mail me
    [email protected]

    Can you try adding this in your URL delimited_hdr=NO
    I am not sure it works.
    Just give a try

  • Sqlldr flat file to external table using shell scripts

    Hi,
    Has anyone done this before? Please give me a hand.
    Thanks!

    Thanks Justin.
    When do I need to create the external table EMP_STAGING ?
    These are my steps so far:
    - shell script to crate the flat file (but I need to change the table name to EMP_STAGING)
    - use a script to call sqlldr to load the flat file into the external table
    - then the script will call the MERGE sql script to merge the data from the external table into the database table
    Am I on the right track?
    In which stage should I create and drop the external table?
    Thanks!

  • Moving files into directory using shell script

    Can someone tell me how I move files into directory using *nix/linux shell script?
    I have files which created from stored procedures using utl_file. The files name for example:
    DKH_104_12345
    DKE_101_42324242
    DKH_102_32432
    DKE_101_34553
    Then I create directories automatically for example:
    /oradata/apps/dmp/output/101
    /oradata/apps/dmp/output/102
    /oradata/apps/dmp/output/103
    /oradata/apps/dmp/output/104
    Using this procedure :
    CREATE OR REPLACE PROCEDURE Xorganize AS
    v_item VARCHAR2(5);
    v_DirName VARCHAR2(50);
    v_FileName VARCHAR2(50):='xorganize';
    v_FileExt VARCHAR2(5):='.sh';
    v_ID UTL_FILE.file_type;
    CURSOR res IS
    --find the directory name from table
    SELECT brn_cde FROM vcr_brn_cde ORDER BY 1;
    BEGIN
    --used by utl.file funtion
    SELECT PRD_DIR INTO v_DirName
    FROM CR_SYS_PRM
    WHERE CLT_CDE ='FIF';
    SELECT v_FileName||v_FileExt INTO v_FileName FROM dual;
    v_ID:=UTL_FILE.FOPEN(v_DirName,v_FileName, 'w');
    utl_file.PUTF(v_ID,'%s\n','@@echo OFF');
    utl_file.PUTF(v_ID,'%s\n','cls');
    utl_file.PUTF(v_ID,'%s\n','echo Reorganizing ...');
    OPEN res;
         LOOP
              FETCH res INTO v_item;
              EXIT WHEN res%NOTFOUND;
              utl_file.PUTF(v_ID,'%s\n','mkdir '||v_item);
         END LOOP;
    CLOSE res;
    OPEN res;
         LOOP
              FETCH res INTO v_item;
              EXIT WHEN res%NOTFOUND;
              utl_file.PUTF(v_ID,'%s\n','move _'||v_item||'_.* '||v_item||'\');
         END LOOP;
    CLOSE res;
    utl_file.PUTF(v_ID,'%s\n','FOR /F "usebackq delims=" %%1 IN (`dir /b *.`) DO @rd/q %%1');
    utl_file.PUTF(v_ID,'%s\n','cls');
    utl_file.PUTF(v_ID,'%s\n','echo Reorganizing ...Done');
    utl_file.fclose(v_ID);
    END;
    Everything works fine, BUT, the script is generated in dos/windows scripting.
    Now I need to run the script in *nix/linux shell, which I still can’t do it (because of my knowledge :p).
    And also I don’t know if the script already generated in *nix/linux shell version, how do I chmod +x the script from stored procedure, I can’t use ‘host’ command in my tools
    Thanks a lot
    -firman

    If you're using 9i then UTL_FILE.FRENAME() will execute something like a Unix mv command.
    If you want to do a chmod then you'll need to check out how to use a Java Stored Procedure to execute OS calls.
    Cheers, APC

  • Error reading data from Infocube using shell script.

    Dear all ,
    I am facing a problem while reading data from an infocube using a shell script.
    The details are as follows.
    One of the shell script reads the data from the infocube to extract files with the values.
    The tables used for extraction by the shell script are :
    from   SAPR3."/BIC/F&PAR_CUBE.COPA"     FCOPA,
           SAPR3."/BIC/D&PAR_CUBE.COPAU"    COPAU,
           SAPR3."/BIC/D&PAR_CUBE.COPAP"    COPAP,
           SAPR3."/BIC/D&PAR_CUBE.COPA1"    CCPROD,
           SAPR3."/BIC/D&PAR_CUBE.COPA2"    CCCUST,
           SAPR3."/BIC/D&PAR_CUBE.COPA3"    COPA3,
           SAPR3."/BIC/D&PAR_CUBE.COPA4"    COPA4,
           SAPR3."/BIC/D&PAR_CUBE.COPA5"    COPA5,
           SAPR3."/BIC/MCCPROD"      MCCPROD,
           SAPR3."/BIC/SCCPROD"      SCCPROD,
           SAPR3."/BIC/MCCCUSTOM"    MCCCUSTOM,
           SAPR3."/BIC/SCCCUSTOM"    SCCCUSTOM,
           SAPR3."/BIC/SORGUNIT"     SORGUNIT,
           SAPR3."/BIC/SUNIMOYEAR"   SUNIMOYEAR,
    /*     SAPR3."/BI0/SFISCPER"     SFISCPER, */
           SAPR3."/BI0/SREQUID"      SREQUID,
           SAPR3."/BI0/SCURRENCY"    SCURRENCY,
           SAPR3."/BIC/SSCENARIO"    SSCENARIO,
           SAPR3."/BIC/SSOURCE"      SSOURCE
    The problem is that the file generation by this script (after reading the data from teh infocube) is taking an unexpected time of 2 hours which needs to be maximum 10 mins only.
    I used RSRV to get the info about these tables for the infocube:
    Entry '00046174', SID = 37 in SID table is missing in master data table /BIC/MCUSLEVEL2
    Entry '00081450', SID = 38 in SID table is missing in master data table /BIC/MCUSLEVEL2
    and so on for SID = 39  and SID = 35 .
    Checking of SID table /BIC/SCUSLEVEL2 produced errors
    Checking of SID table /BIC/SCUSLEVEL3 produced errors
    Can you please let me know if this can be a reason of delay in file generation (or reading of data from the infocube).
    Also , Please let me know how to proceed with this issue.
    Kindly let me know for more information, if required.
    Thanks in advance for your help.
    -Shalabh

    Hi ,
    In continuation with searching the solution to the problem , I could manage to note a difference in the partition of the Fact table of the infocube.
    Using SE14 -> Storage Parameters, I could find the partition done for the fact table as :
    PARTITION BY: RANGE
    COLUMN_LIST: KEY_ABACOPA
    and subsequently there are partitions with data in it.
    I need to understand the details of these partitions .
    Do they correspond to each requests in the infocube(which may not be possible as there are 13 requests in infocube and much more partitions).
    Most importantly, since this partition is observed for this onfocube only and not for other infocubes, it is possible that it can be a reason for SLOW RETRIEVAL of data from this ionfocube( not sure since the partition is used to help in fast retreival of data from the infocubes).
    Kindly help.
    Thanks for your co-operation in advance.
    -Shalabh

  • Reading Text file & Updating table using PL SQL Procedure

    Guys, I am trying to read data from a large text file which
    contains tab delimited data. Based on success of validations, I
    have to insert/update data in to table(s). Does any one has any
    sample procedure to read data (tab delimted/comma seperated)
    from a text file and write to database table? Your help is
    greatly appreciated!

    Is there any particular reason why you're not using SQL*Loader
    for this? Otherwise you would seem to be re-inventing the wheel.
    rgds, APC

  • Generate XML file from RFC using Web Services

    Hi,
      I am trying to save an RFC enabled Function Module output to an XML file using ABAP web services.
    I could able to create Web Service and release it using WSCONFIG/WSADMIN. I can actually get the output in XML file when i launch the web service home page. But I need this to be done in the ABAP program itself. So If i run the RFC I could able to create,release web service and capture the Generated XML file by SOAP runtime.
    Any FM available?
    Thanks,
    Ram Sanjeev

    which version of WAS you are on .
    if you are on WAS6.40 check the following weblog on how to consume webservice using the wsdl file.
    /people/thomas.jung3/blog/2004/11/17/bsp-a-developers-journal-part-xiv--consuming-webservices-with-abap
    lower version of WAS use class cl_http_client.
    if this case you have to manually build the soap message.
    /people/durairaj.athavanraja/blog/2004/09/20/consuming-web-service-from-abap
    Regards
    Raja

  • Creating text file from table

    Hi all
    I have a table LFA1 with headers LIFNR, MANDT, NAME1, NAME2, ...., . That table contains data and I need to create text file that collects all headers with all data, where each field is separated by TAB.
    thanks for your help.

    Here is program for KNA1.
    *"Table declarations...................................................
    tables:
      kna1.                              " General Data in Customer Master
    *"Selection screen elements............................................
    select-options:
      s_kunnr for kna1-kunnr.            " Customer Number 1
    *" Type declarations...................................................
    types:
      begin of type_s_customer_details,
        name        like kna1-kunnr,
        address     like kna1-adrnr,
        title       like kna1-anred,
        createdon   like kna1-erdat,
        createdby   like kna1-ernam,
      end of type_s_customer_details.
    Internal table to hold General Data in Customer Master data         *
    data:
      t_customer_details type table
                           of type_s_customer_details
                         with header line.
                          START-OF-SELECTION EVENT                      *
    start-of-selection.
      perform select.
    *&      Form  select
    This subroutine selects information from database and exports the    *
    data into presentation layer                                         *
    There are no interface parameters to be passed to this subroutine.  *
    form select .
      select kunnr
              adrnr
              anred
              erdat
              ernam
         into table t_customer_details
         from kna1
        where kunnr in s_kunnr.
      if sy-subrc ne 0.
        write : / 'DATABASE SELECTION FAILED'.
      else.
        call function 'GUI_DOWNLOAD'
          exporting
      BIN_FILESIZE                    =
           filename                        = 'd:\customer_details.txt'
           filetype                        = 'ASC'
      APPEND                          = ' '
      WRITE_FIELD_SEPARATOR           = ' '
      HEADER                          = '00'
      TRUNC_TRAILING_BLANKS           = ' '
      WRITE_LF                        = 'X'
      COL_SELECT                      = ' '
      COL_SELECT_MASK                 = ' '
      DAT_MODE                        = ' '
      CONFIRM_OVERWRITE               = ' '
      NO_AUTH_CHECK                   = ' '
      CODEPAGE                        = ' '
      IGNORE_CERR                     = ABAP_TRUE
      REPLACEMENT                     = '#'
      WRITE_BOM                       = ' '
      TRUNC_TRAILING_BLANKS_EOL       = 'X'
    IMPORTING
      FILELENGTH                      =
          tables
            data_tab                        = t_customer_details
      FIELDNAMES                      =
         exceptions
           file_write_error                = 1
           no_batch                        = 2
           gui_refuse_filetransfer         = 3
           invalid_type                    = 4
           no_authority                    = 5
           unknown_error                   = 6
           header_not_allowed              = 7
           separator_not_allowed           = 8
           filesize_not_allowed            = 9
           header_too_long                 = 10
           dp_error_create                 = 11
           dp_error_send                   = 12
           dp_error_write                  = 13
           unknown_dp_error                = 14
           access_denied                   = 15
           dp_out_of_memory                = 16
           disk_full                       = 17
           dp_timeout                      = 18
           file_not_found                  = 19
           dataprovider_exception          = 20
           control_flush_error             = 21
           others                          = 22
        if sy-subrc <> 0.
          write : / 'Upload Failed' , sy-subrc.
        else.
          write : / 'Upload Completed'.
        endif.
      endif.
    endform.                               " SELECT

  • Generating Text Files from reports

    Hi all,
    Could anyone help me to generate reports to text files using command line. I could do this using the menus but I need to do it by command line.
    I tried to use the DESFORMAT parameter but the values for this parameter do not include a value for a text file. I could find PDF, HTML, RTF and.....
    Thanks in advance

    Hi,
    Try using DESFORMAT=DELIMITED eg.
    rwrun60.exe REPORT="XXXXX.RDF" USERID=userid/passwordf@databaseid DESTYPE=FILE DESFORMAT=DELIMITED DELIMITER=TAB DESNAME="XXX.TXT" BATCH=YES
    I think the default delimiter is TAB but you can specify your own delimiter. There is a list of command line options and delimiter options on the Reports Runtime Help.
    I hope this helps !
    regards
    Warren

  • Is the syntax correct to export tables using shell script

    can you please tell me the syntax to plaxce the exp utility in shelle script.
    Appreciate your help
    Is the syntax correct for export.
    It is throwing errors
    vi test.sh
    echo migrating data...
    echo Exporting ADDRESS_COUNTRY_CODE ...
    exp userid=scott/tiger@orcl file=address_country_code log=exp_address_country_code tables=ADDRESS_COUNTRY_CODE compress=n indexes=n constraints=n grants=n triggers=n statistics=none consistent=y query='where org_grp_i in ( 66 )' > /dev/null
    echo Exporting ASSUMPTION_DETAIL_SUMMARY ...
    exp userid=scott/tiger@orcl file=assumption_detail_summary log=exp_assumption_detail_summary tables=ASSUMPTION_DETAIL_SUMMARY compress=n indexes=n constraints=n grants=n triggers=n statistics=none consistent=y query='where org_grp_i in ( 66 )' > /dev/null

    Just follow the notes and the example in the utilities guide
    http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96652/ch01.htm#1005843
    exp scott/tiger TABLES=emp QUERY=\"WHERE job=\'SALESMAN\' and sal \<1600\"

  • Seeking simple example pl/sql to create text file from table data

    hello,
    I am hoping someone can provide very simple example of creating a file on my local harddrive using a pl/sql program. The basic steps are as follows:
    First, I store some text in a varchar2 variable like this:
    1. select sometext into otextvar from mytable where recordid = 1;
    Second, I want this text to become a file in my data directory:
    2. c:\data\sometext.txt
    The second step is where I need help.
    Any suggestions are greatly appreciated.

    Use this function
    It will create for you a file in your /home/oracle directory with sysdate name and will insert all table names in it
    CREATE OR REPLACE PROCEDURE my_proc AS
    CURSOR cursor1 IS
    SELECT table_name from all_tables;
    CURSOR cursor2 IS
    SELECT sysdate from dual;
    rec1 cursor1%ROWTYPE;
    rec2 cursor2%ROWTYPE;
    created_file_name VARCHAR2(100);
    file_name utl_file.file_type;
    BEGIN
    OPEN cursor2;
    LOOP
    FETCH cursor2 INTO rec2;
    EXIT WHEN cursor2%NOTFOUND;
    created_file_name:=rec2.sysdate;
    file_name := utl_file.fopen('/home/oracle', created_file_name,'W');
    OPEN cursor1;
    LOOP
    FETCH cursor1 INTO rec1;
    EXIT WHEN cursor1%NOTFOUND;
    utl_file.putf(file_name, '%s\n',rec1.TABLE_NAME);
    END LOOP;
    utl_file.fclose(file_name);
    END LOOP;
    END my_proc;
    SQL>exec my_proc;

Maybe you are looking for

  • Deployment order of MDBs vs EJBs in WL startup sequence

              This is a problem that follows on from my last posting.           To recap, we have multiple WL servers not clustered, one acts as the JMS server that           all of them use as their MDB jndi-provider-url so when a message (on a JMS topi

  • PDF Merge software on Server side

    Hi, Do you use any PDF Merge software on Server side that combines the many PDF files (originally from Broadcaster) into one PDF? This final PDF file should have the Table of Contents with the corresponding page numbers. Therefore, this software shou

  • How To Work With Jtree Pls Help

    I heared about JTree but dont have idea to use it in form6i where i can get help or sample form can i use jtree in forms 6i

  • Is it possible to correct camera shake in CS2

    Is it possible to correct camera shake in Photoshop CS2

  • Where to make feature request

    Where can I request a feature to be added to mac mail? I need more than just a flag to mark email that I want to go back to or to save. I really like to have color coded flags or markers so that I can find a particular type of email quickly and at a