Is there any way to spool with variable column size?

Hi, I'm spooling to a CSV file with the following script (the real SELECT is different but similar, Oracle 10.2.0.3.0):
SET COLSEP ';'
SET FEEDBACK OFF
SET LINESIZE 2000
SET PAGESIZE 0
SET TERMOUT OFF
SET TRIMSPOOL ON
SET VERIFY OFF
SPOOL test.csv REPLACE
SELECT 'COLUMN1', 'COLUMN2', 'COLUMN3' FROM dual UNION ALL
SELECT 'value1', NULL, NULL FROM dual UNION ALL
SELECT 'value2', NULL, NULL FROM dual;
SPOOL OFF
EXIT SUCCESS COMMITThis produces the following output:
COLUMN1;COLUMN2;COLUMN3
value1 ;       ;
value2 ;       ;Is there any way to get the following output with variable column size
COLUMN1;COLUMN2;COLUMN3
value1;;
value2;;I've tried SET NULL '' but I see no difference. Thanks in advance!
Markus

In short, No, because SQL*Plus is laying out the data in columns.
You could either combine the data into a single column by concatenating as strings or use some other method e.g.
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
    v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
  END LOOP;
  --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
  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 := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
        WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                    v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
        WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                    v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
      ELSE
        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
      END CASE;
    END LOOP;
  --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
    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.txt file contains:
empno,ename,job,mgr,hiredate,sal,comm,deptno
7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10The 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.

Similar Messages

  • Is there any way, to create with Adobe Muse HTML-Mail Templates?

    Is there any way, to create with Adobe Muse HTML-Mail Templates? or to convert the createt page to only html content? any other tool like an website copyer?
    tanks for help!

    Off the top of my head, you should be able to create mail templates in muse BUT it will require  very basic html/css knowledge on your part. I am assuming you want to do just the signature?
    Create the design you would like on one page, dont do any kind of styling in a master page. Then export the site into a folder. Open the html file with notepad/ textedit and then copy just the code for JUST the template. Throw it in you mail app of choice and it should work.
    This seems like something that would be done alot quicker in dreamweaver in design view.
    PLEASE NOTE: ^i could be completely wrong - but in theory this may work.

  • Is there any way to interact with ipad3 and a smartboard?

    Is there any way to interact with ipad3 and a smartboard?

    A google search revealed that currently there is no software or App which permits iPad to work with Smartboard.

  • Is there any way to copy S.Variables via Maxl or Essbase

    Guyz,
    Is there any way to copy S.Variables from one App to another app via Maxl or Essbase.
    Cheers
    Cnee

    you can copy substitution variables between different Essbase servers through Admin console.
    At first you should be able to add both the essbase servers in the admin console.
    Then you can copy the subst variables from one essbase server to other.
    in subst variable window -> select copy -> select server, app, db -> select subst variable to be copied -> you can tick overwrite existing variables option if needed -> click OK.
    the other way is to collect the subst variable information through maxl & then write maxl scripts to create the subst variables on the other server.
    - Krish

  • I'm using TestStand/Labview to do a string value test. Is there any way to use a variable in the edit string value test?? This forces you to hard code a string to test against.

    I'm using TestStand 2.0/Labview 6i to do a string value test. Is there any way to use a string variable in the edit string value test instead of an actual string?? This forces you to hard code a string to test against.

    Hi ART,
    You can also use the LimitLoader step to load your string into to step similar to the Numeric Step type.
    There should be an example of this in the Resource Library | TestStand
    Regards
    Ray Farmer
    Regards
    Ray Farmer

  • Is there any way to sync with new pc? HELP!

    Ok, so I have an ipod touch and a new computer. The old computer that the ipod was synced to was destoyed. Can anyone tell me if there is ANY way to sync with the new pc AND keep all the songs, games, pic, and everything? I don't want to lose everything!!

    There are several shareware utilities that can be used to transfer some of your data such as music files from the Touch to the computer - search for "ipod" at VersionTracker. Contacts and calendar data will sync automatically when you use iTunes to sync the Touch, but be sure to get your music files and pics transferred first. Apps should sync normally.

  • HT2020 we upgraded to Lion and lost iChat.  Is there any way to continue with iChat?

    We use iChat for conference calls.  When we upgraded to Lion it was replaced with facetime so it appears we lost the ability to use iChat.  It does not appear facetime allows conference calls (more than 2 locations to connect at the same time).  Is there any way to obtain a multipul connection so we can continue with multipul connections?

    HI,
    Lion = OS X 10.7.x and comes with iChat 6
    Mountain Lion = OS X 10.8.x and comes with Messages.
    Messages is iChat +
    The Plus bit is the iMessages Service from the iOS stable.
    It is compatible with Messages on the iPhone and iPad.
    It takes an Apple ID to "register" with the iMessages service.
    However all the "Accounts" you had with AIM or Jabber work just the same in Messages.
    By default the Buddy lists are combined (but can be unlinked in the general section of the Preferences) are are not on show at the App Start.
    As the Other thread says you get sent to Make your iMessages Registration first before looking at what were iChat Logins.
    From your Buddy Lists you can make the same 3 or 4 way Video chats you did in iChat.
    8:24 PM      Monday; December 17, 2012
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
      iMac 2.5Ghz 5i 2011 (Mountain Lion 10.8.2)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • *Is there any way to limit the Chart Bar size dynamically?*

    Hi
    I have selected the Marker size as Medium for my Bar chart.
    Bar chart bar showing too big when there is only one bar.
    Is there any way to limit the bar size dynamically?
    Thank you

    hi Ruwan,
    Don is correct in that there is no option in the chart design component to do this.
    what you can do though (i know it is a pain) is to
    1) create a new chart in a new section with a narrower bar using the chart options dialogue
    2) create a conditional suppression formula for the new section and the old chart section based on the value returned in the Show Value for the chart
    i have created a request for a charting overhaul [here |https://ideas.sap.com/community/products_and_solutions/crystalreports;jsessionid=B3E2E9F6A6CC9C9F5321659382A91855.node0]in the ideas place which includes a solution for this particular issue. please feel free to give it the thumbs up if you think that this is a worthwhile idea.
    jamie

  • Is there any way to pan with the mouse in Multisim?

    For some reason, I can't seem to find a way to pan with the mouse in Multisim.  Is there a pan tool, or a keyboard shortcut that allows me to use the mouse to drag the document where I want it?

    To add to Tayyab's suggestion, you can also enable the 'Center on mouse' option when zooming in and out using the scroll wheel.   I sometimes find this useful now since in Multisim v12 the upper left corner of the workspace is not locked as it was in v11 and previous.   With this option checked, when zooming in/out, the schematic workspace will automatically snap to center of the mouse location.
    Also there is a scroll option (instead of zoom) but it is really only useful for scrolling up and down (it is not horizontal scroll bar sensitive like other applications).
    To enable the 'Center on mouse' option, from the menu go to:
    Options -> Global preferences -> General (tab) -> Mouse wheel behavior (section)
    - Pat N

  • Is there any way to modify the photo book size after I have created the book?

    I created a photo book then realized it was not the correct size. Is there a way to correct the size or do I have to start from scratch?
    I Found the answer after I posted this- CTRL D to duplicate, then choose new theme - Worked like a charm.

    Yes.  First click on the book in the Projects section and type Command +D (duplicate).  Open the book, click on Change Themes and in the next window select the size and type you want.
    The duplicate is to have in case you find any text that was removed in the resizing.  You can cut and past from the duplicate copy to the original.  Also verify that the resized book has all of its text, not text warning indicators and that all photos are there and in the correct order.
    Always create a PDF version of the book according to this Apple doucment, iPhoto, Aperture: Previewing an order in iPhoto or Aperture, to check for any errors, i.e. typos, missing text, etc., before ordering the book.  Keep the pdf file to compare with the printed version when it arrives.
    Opps!  Answered your question from the title without reading the full body of your post. However, the last 2 paragraphs are worth reviewing.
    OT
    Message was edited by: Old Toad

  • Is there any way to select multiple variables on a block diagram and change them all to read or write?

    Doing one variable at a time can be tedious.  It's hard to believe there wouldn't be a solution for this.

    I agree with tbd that there is rarelynever a reason for ton's of local variables.
    Even if you feel you need many, it does not take much time to configure each right after creation and I see little use to globally change many from read to write or vice versa at a later point. An overuse of Local variable tend to make code hard to read and can easily cause race conditions. For one perspective have a look at some older discussions, e.g.: http://forums.ni.com/ni/board/message?board.id=170&message.id=112401#M112401.
    To make a new local variable, I typically ctrl+drag an existing one (read or write as needed) and "right-click..select item" to assign the desired control/indicator.
    LabVIEW Champion . Do more with less code and in less time .

  • Is there any way to respond with imessage in the menubar?

    I have a 13 inch Macbook Pro running Mountain Lion and have been wondering if there is some way to put imessage in the menu bar for quick responding capablities? I have been looking for a number of ways to tweak my mac and speed up my workflow.
    Any suggestions are greatly appreciated.

    There's not way to send a iMessage from the menu bar, but if you want, you can put Messages on the menu bar to access quickly to Messages. To do that, open Messages. Then, go to the Messages menu, on the menu bar, and select Preferences. Finally, mark "Show status in menu bar"

  • Is there any way to connect with iCloud

    I have a 15" Mac Book Pro running Snow Leopard and a 13" Mac Book Pro running Lion. I have My 13"MBP, my iPhone and my iPad connected to iCloud but am now unable to get my email from my mac account to my mail program on my 15" MBP. Any ideas?

    Have you followed Apple's guidance to setup your Snow Leopard Mail account using IMAP?
    iCloud: Mail server information
    http://support.apple.com/kb/HT4864
    If that doesn't work, search for detailed instructions.  There are plenty of posts that describe success connecting iCloud email, calendar, etc. to Snow Leopard.

  • Is there any way to speak with an actual person at verizon support. i could not find a phone number and the chat is always unavailable?

    is there anyway to speak with

    Dial *611 from a cell phone or (800) 922-0204; when you get the phone tree, press 4 for Other and say Agent.

  • Is there any way to chat with my Game Center friends?

    I would prefer not getting a new app to do this. Is it already implemented, or how I can I ask Apple to add it?

    I know of no way without another app such as Yahoo, Skype.  Make a suggestin to Apple here:
    Apple - iPod touch - Feedback

Maybe you are looking for