backup sql output as separate command values

Hello

version 10.2.0.3

I am trying to wrap an output select sql in the form of values separated by commas. Could you help me on this please?

I'm getting

1234, testdata (spaces), atr

Expected result:

1234, testdata, atr


Thank you

Published by: APV on October 7, 2009 09:30

If you don't mind each column space padded then you can use:

set colsep ,

But if (as I think is the case with your query) you want to get rid of the padding, then you're going to concatenate columns together in a single string:

select col1 || ',' || col2 || ',' || col3
from 

Additional note: If one of your columns contains commas in the data, you'll probably like too much quoting them and double quotes in the data.

Published by: Andy Triggs on October 7th, 2009 10:42

Tags: Database

Similar Questions

  • Backup SQL + output to a text file

    I have to use SQL + on one of my databases. No way around it. So I'll write my queries, execute them, check the output, tweak them and run again if necessary. So I could start with
    SELECT
    ename,
    job
    FROM
    emp;
    Once I know that it's working properly, I wrap it in a procedure so I can get the data in a text file:
    SET TRIM ON
    SET PAGESIZE 2000
    SET SERVEROUTPUT ON SIZE unlimited
    EXEC DBMS_OUTPUT.ENABLE(null)
    --
    SPOOL c:\mySQL\out.txt
    --
    BEGIN
    --
    DECLARE
    --
    CURSOR c_cur IS
    --
    SELECT
    ename,
    job
    FROM
    emp;
    --
    BEGIN
    --
    DBMS_OUTPUT.PUT_LINE(
    'NAME|JOB|'
    );
    FOR r_cur IN c_cur LOOP
    DBMS_OUTPUT.PUT_LINE(
    r_cur.ename||'|'||
    r_cur.job
    );
    END LOOP;
    END;
    END;
    /
    Then I import into Excel as data delimited on the pipe.

    works fine until I have decide that I really need a column more. So I made changes on the SQL code, and two more changes in the part of the output (one for the title and one for the LOOP)
    I was wondering if someone had written a cool procedure I could run across ALL SQL, and he would automatically know my names to column write the titles and then to loop through data automatically.

    I'm not tied to the use of the exact procedure I described above. The key is, I'm looking for a general procedure that I can run any script through, and it will load the output for me, without further changes.

    Hello

    Why do you not consider creation and HTML file which can be read easily with Excel.

    that is to say:

    SET SERVEROUTPUT ON SIZE UNLIMITED
    SET LIN 500
    
    SET DEFINE OFF
    SET UNDERLINE OFF
    SET TAB OFF
    SET FEEDBACK OFF
    SET VERIFY OFF
    SET TERMOUT OFF
    SET PAGES 9999
    
    SET MARKUP HTML ON TABLE "cellspacing=0 border=1" ENTMAP OFF
    
    spool myexcel.xls
    
    /* Replace the query below as you like */
    SELECT * FROM EMP;
    
    spool off
    
    EXIT
    

    The format is HTML, but once you load in Excel, you can easily save the format you like.

    Kind regards.
    Al

  • XML and SQL output

    Hi all

    Please find test data and results as XML and SQL output.

    Version : Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production

    create table emp_xml (empno number, emp_name varchar2 (100), by e-mail to varchar2 (100));

    insert into emp_xml values (100, 'DAVID',' [email protected]');

    insert into emp_xml values (101, 'ROBERT',' [email protected]');

    insert into emp_xml values (102, 'DANIEL',' [email protected]');

    CREATE table emp_dept_xml (empno number, dept_list varchar2 (4000));

    insert into emp_dept_xml values (' 100,'10, 20, 30, ");

    insert into emp_dept_xml values (' 101,'40, 20, 10, 30, 50, ");

    insert into emp_dept_xml values (102, ' 10'),

    Expected in SQL output

    -----------------------

    EMPNO EMP_NAME EMAIL DEPTNO

    DAVID 100 [email protected] 10

    DAVID 100 [email protected] 20

    DAVID 100 [email protected] 30

    ROBERT 101 [email protected] 10

    ROBERT 101 [email protected] 20

    ROBERT 101 [email protected] 30

    ROBERT 101 [email protected] 40

    ROBERT 101 [email protected] 50

    DANIEL 102 [email protected] 10

    Results in XML

    -----------------------

    < USERS_DETAILS >

    < USER >

    < EMPNO > 100 < / EMPNO >

    DAVID < NAME > < / NAME >

    < EMAIL > [email protected] < / EMAIL >

    < ASSIGNED_DEPT >

    < DEPT > 10 < / DEPT >

    < DEPT > 20 < / DEPT >

    < DEPT > 30 < / DEPT >

    < / ASSIGNED_DEPT >

    < / USER >

    < USER >

    101/EMPNO < EMPNO > >

    ROBERT < NAME > < / NAME >

    < EMAIL > [email protected] < / EMAIL >

    < ASSIGNED_DEPT >

    < DEPT > 10 < / DEPT >

    < DEPT > 20 < / DEPT >

    < DEPT > 30 < / DEPT >

    < DEPT > 40 < / DEPT >

    < DEPT > 50 < / DEPT >

    < / ASSIGNED_DEPT >

    < / USER >

    < USER >

    < > 102 EMPNO < / EMPNO >

    DANIEL < NAME > < / NAME >

    < EMAIL > [email protected] < / EMAIL >

    < ASSIGNED_DEPT >

    < DEPT > 10 < / DEPT >

    < / ASSIGNED_DEPT >

    < / USER >

    < / USERS_DETAILS >

    Thank you

    Rambeau

    SQL>   select e.empno
      2         , e.emp_name
      3         , e.email
      4         , regexp_substr(d.dept_list, '[^,]+', 1, level) deptno
      5      from emp_xml e
      6      join emp_dept_xml d
      7        on e.empno = d.empno
      8   connect
      9        by level <= length(d.dept_list) - length(replace(dept_list, ','))
     10       and prior e.empno = e.empno
     11       and prior dbms_random.value() is not null;
    
         EMPNO EMP_NAME             EMAIL                DEPTNO
    ---------- -------------------- -------------------- --------------------
           100 DAVID                [email protected]      10
           100 DAVID                [email protected]      20
           100 DAVID                [email protected]      30
           101 ROBERT               [email protected]     40
           101 ROBERT               [email protected]     20
           101 ROBERT               [email protected]     10
           101 ROBERT               [email protected]     30
           101 ROBERT               [email protected]     50
           102 DANIEL               [email protected]     10
    
    9 rows selected.
    
    SQL> select xmlelement
      2         (
      3              "USERS_DETAILS"
      4            , xmlagg(xmlelement
      5              (
      6                  "USER"
      7                , xmlelement("EMPNO", empno)
      8                , xmlelement("NAME", emp_name)
      9                , xmlelement("ASSIGNED_DEPT", xmlagg(xmlelement("DEPT", deptno)))
     10              ))
     11         ).extract('*') xml_output
     12    from (
     13            select e.empno
     14                 , e.emp_name
     15                 , e.email
     16                 , regexp_substr(d.dept_list, '[^,]+', 1, level) deptno
     17              from emp_xml e
     18              join emp_dept_xml d
     19                on e.empno = d.empno
     20           connect
     21                by level <= length(d.dept_list) - length(replace(dept_list, ','))
     22               and prior e.empno = e.empno
     23               and prior dbms_random.value() is not null
     24         )
     25   group
     26      by empno
     27       , emp_name;
    
    XML_OUTPUT
    --------------------------------------------------------------------------------
    
      
        100
        DAVID
        
          10
          20
          30
        
      
      
        101
        ROBERT
        
          40
          50
          30
          20
          10
        
      
      
        102
        DANIEL
        
          10
        
      
    
    
    SQL>
    
  • How to write the output of RMAN commands to a log file

    Hi DBAs,

    I must only newspapers archive backup too manually by pulling the controls in the RMAN session without running any script backup.

    The orders happens this way:

    run

    {

    allocate channels ch01 type disk maxpiecesize 7000 M;

    allocate channels ch02 type disk maxpiecesize 7000 M;

    BACKUP tag ArchLogAll FILESPERSET FORMAT of 20 ' / oracledbbackupset/archive_log_bkp_2014_06_18/d_%d_s_%s_p_%p_t_%t.bkp' ARCHIVELOG

    FROM 4410 SEQUENCE AS A SEQUENCE 4599 THREAD 1 REMOVE ALL ENTRIES;

    Ch01 CHANNEL;

    OUTPUT CHANNEL ch02;

    }

    Now, I want the output of these commands to write to a log file in the location /temp/arch.log in parallel executing above commands. I don't care?

    Kind regards

    Ritu

    See the RMAN command SPOOL LOG TO

    http://docs.Oracle.com/CD/E11882_01/backup.112/e10643/rcmsynta2017.htm#RCMRF156

    Hemant K Collette

  • XML request error. ORA-00933: SQL not correctly completed command.

    Hi all

    My Version of the database: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0.

    CREATE table test (name VARCHAR2 (3), identification number);

    Insert test values ('abc', 61);

    Insert test values ('def', 46);

    Select table_name,
    column_name,
    search_string 'abc ',.
    result
    CLO, xmltable (('ora: view("'||))) table_name |' ") / RANK /' | column_name | "[ora:contains (text,' %'|)] "abc". "% ») > 0]')
    result varchar2 columns (10) path '.'
    )
    where table_name in ('TEST');

    and I get: ORA-00933: SQL not correctly completed command it points on ' * xmltable *'
    SQL> SELECT extractValue(value(t), '/CustomerInformation/Customerid') "Customerid"
      2       , extractValue(value(t), '/CustomerInformation/CustomerName') "CustomerName"
      3       , extractValue(value(t), '/CustomerInformation/Country') "Country"
      4  FROM xml_document_table x
      5     , TABLE(
      6         XMLSequence(
      7           extract(x.xml_document, '/Customer/CustomerInformation')
      8         )
      9       ) t
     10  ;
    
    Customerid            CustomerName             Country
    --------------------- ------------------------ -------------
    1                     xxxx                     4
    2                     yyyy                     5
     
    
  • A list of all the fields in the output of the command

    All,

    I want to know how to get the list of columns that you may see what I can execute select statements. It seems to be out of default for the commands, but it doesn't tell you what you can ask additional columns.

    For example, get - vm shows these 4, but I know there are more columns that he shoots.

    Name PowerState Num CPU MemoryGB

    You can direct the output of a command to the PowerShell Get-Member cmdlet to see all the properties and methods available:. For example

    Get - VM | Get-Member

  • ORA-00933: SQL not correctly completed command.

    Hello

    I get the following error:-ORA-00933: SQL not correctly completed command

    select
                (select max(x.exec_id) from log_exec x) exec_id,
                'c2uv_sys_map' table_name, 'All' upload_file_name,
                count(*) rows_ok, 0 rows_duplicate, 0 rows_rejected, 0 rows_bad, e.upload_file_id
                from c2uv_sys_map e
                where e.row_err_id=0
                group by e.upload_file_id
                UNION
                select max(x.exec_id) from log_exec x) exec_id,
                'c2uv_sys_map' table_name, 'All' upload_file_name,
                count(*) rows_ok, 0 rows_duplicate, 0 rows_rejected, 0 rows_bad, e.upload_file_id
                from c2uv_sys_map e
                group by e.upload_file_id
                UNION
                select (select max(x.exec_id) from log_exec x) exec_id,
                'c2uv_sys_map' table_name, 'All' upload_file_name,
                0 rows_ok, count(*) rows_duplicate, 0 rows_rejected, 0 rows_bad, e.upload_file_id
                from c2uv_sys_map  e
                where e.row_err_id=2
                group by e.upload_file_id
                UNION
                select (select max(x.exec_id) from log_exec x) exec_id,
                'c2uv_sys_map' table_name, 'All' upload_file_name,
                0 rows_ok, 0 rows_duplicate, count(*) rows_rejected, 0 rows_bad, e.upload_file_id
                from c2uv_sys_map  e
                where (e.row_err_id =1) or (e.row_err_id >2)
                group by e.upload_file_id
                UNION
                select (select max(x.exec_id) from log_exec x) exec_id,
                'c2uv_sys_map' table_name, 'All' upload_file_name,
                0 rows_ok, 0 rows_duplicate, 0 rows_rejected, u.no_of_bad_rows rows_bad, t.upload_file_id
                from c2uv_sys_map t right outer join chn_upload u on t.upload_file_id = u.config_id
                inner join chn_upload_config c on u.config_id = c.config_id
                inner join chc_data_filetype f on c.data_filetype_id = f.data_filetype_id
                where f.data_filetype_id = 11
                group by u.no_of_bad_rows, t.upload_file_id
    Edited by: 872435 January 6, 2012 06:09

    It seems that this parenthesis corresponds to nothing:

    select (select max(x.exec_id) from log_exec x) exec_id,
           'c2uv_sys_map' table_name,
           'All' upload_file_name,
           count(*) rows_ok,
           0 rows_duplicate,
           0 rows_rejected,
           0 rows_bad,
           e.upload_file_id
      from c2uv_sys_map e
     where e.row_err_id = 0
     group by e.upload_file_id
    UNION
    select max(x.exec_id)
      from log_exec x)         -- <-- Here
    ...
    
  • Output of the command "LAST".

    Here's my output from the command "last".

    root pts/0 wdbssts012.ihess Fri 3 Apr 18:18-19:44 (01:26)

    root tty1 Fri Apr 3 17:53 - down (02:09)

    reboot system starts 2.4.21 - 47.0.1.EL Fri Apr 3 17:34 (02:28)

    root pts/1 wdbssts014.ihess Fri Apr 3 15:51 - accident (01:43)

    root pts/0 tntssgi002.ihess Fri Apr 3 15:44-16:52 (01:08)

    According to this release, this means my ESX crashed April 3 to 15:51 local time of the server and restarted again at 17:34.

    An early response will be grately appreciated.

    Thank you

    Yes, it has crushed & restarted the Apr 3

    System engineer

    Zen Systems Sdn Bhd

    Malaysia

    www.no-x.org

  • PL/SQL Insert Row Assign PK Value

    I try to insert a row of data into a table and assign a primary key value. I want to give the first available primary key, not only the nextval in the maxval. Is there a way to do it cleanly, or will I need to create a cursor to do? If I need to create a slider or the sequence, how do I declare it in my procedure? Do I need a sequence so that I couldn't just use a loop for? Please help - it seems such a simple thing, but it has left me speechless.

    CheRenee

    Look at this,

    SQL> Create table M_MOVIES(MOVIE_ID NUMBER not null);
    
    Table created
    SQL> Alter table M_MOVIES add constraint PROD_ID_PK primary key (MOVIE_ID);
    
    Table altered
    
    SQL> Insert Into M_movies
      2    (Select level id_movies From dual connect by level <= 10);
    
    10 rows inserted
    SQL> Commit;
    
    Commit complete
    
    SQL> CREATE SEQUENCE seq_avail_id
      2  START WITH 1
      3  INCREMENT BY 1
      4  MAXVALUE 99999999
      5  /
    
    Sequence created
    
    SQL> INSERT INTO m_movies(movie_id) VALUES(seq_avail_id.NEXTVAL);
    
    INSERT INTO m_movies(movie_id) VALUES(seq_avail_id.NEXTVAL)
    
    ORA-00001: unique constraint (SYSTEM.PROD_ID_PK) violated
    
    SQL> Drop SEQUENCE seq_avail_id;
    
    Sequence dropped
    
    SQL> Select max(movie_id) from m_movies;
    
    MAX(MOVIE_ID)
    -------------
               10
    
    SQL> CREATE SEQUENCE seq_avail_id
      2  START WITH 11
      3  INCREMENT BY 1
      4  MAXVALUE 99999999
      5  /
    
    Sequence created
    
    SQL> INSERT INTO m_movies(movie_id) VALUES(seq_avail_id.NEXTVAL);
    
    1 row inserted
    

    Kind regards
    Christian Balz

  • Separate the values in a column in Discoverer

    Hi all

    I have an 'Address' column that gives the city, State, country, Zip.
    For example,.

    Address

    San Jose, CA, 95101, USA.


    I want to separate these and display in different columns as
    Zip city country
    San Jose CA 95101 USA


    Is there any function discoverer to separate these values?


    Thank you
    Gran

    Hello

    You need substr and instr to divide in a calculation to break down the field. For example,.

    LTRIM (SUBSTR (address, INSTR (address, ',', 1, 1) + 1, INSTR (address, ',', 1, 2) - INSTR (address, ',', 1, 1) - 1))

    to extract the second part.

    Alternatively, you can write your own function.

    Rod West

  • Print SQL with SQL output statements

    I am a student in learning SQL for Oracle 10 g.
    Our missions are typically a set of problems that have an SQL statement as the solution.
    We pass in the SQL statement and SQL output generated by the statement.
    I use SQL Developer to create my scripts, print my files, etc. Very convenient.
    I want to be able to do is to somehow combine the two impressions that I always generate.
    So I would like to have a report which has my SQL statement (Select * From Customers ;) and)
    the output of SQL that has generated this statement.
    Anyway is to do it with SQL Developer? Or maybe in another tool?

    Thanks for any help!

    Just this question before your scripts:

    set echo on

    Have fun
    K.

  • SQL output varies depending on the value with or without single quotes

    Hello

    My version of the database is the database Oracle 11 g Enterprise Edition Release 11.2.0.1.0 - Production PL/SQL Release 11.2.0.1.0 - Production.


    (1) when I use the query select * from hr.employee where id > = '82210' I get the below of lines


    13205 selected lines.


    2.) when I use the query select * from hr.employee where id > = 82210 I get the below of lines


    11871 selected lines.


    The ID table in hr.employee is ID NOT NULL VARCHAR2 (80).


    I don't have much knowledge in SQL so please can someone explain why this difference in output?


    Kind regards

    007





    Look at the example

    create the table test16

    (

    Identification number,

    SAL varchar2 (10),

    name varchar2 (20)

    );

    insert into test16 values (1, "2005", "ABC");

    insert into test16 values (2, '2045', 'ABC');

    insert into test16 values (3, '2065', 'ABC');

    insert into test16 values (4, '2075', 'ABC');

    insert into test16 values (5, '1705', 'ABC');

    insert into test16 values (6, '1805', 'ABC');

    insert into test16 values (7, '1920', 'ABC');

    insert into test16 values (8, '2010', 'ABC');

    insert into test16 values (9, '0999', 'ABC');

    insert into test16 values (10, '0789', 'ABC');

    insert into test16 values (11, '510', 'ABC');

    insert into test16 values (12, '455', 'ABC');

    commit;

    Select * from test16 where sal > = 200;

    All 12 rows selected because there is an implicit conversion from column sal in numbers

    Select * from test16 where sal > = "200";

    Only 7 rows selected but waited 12

    2005

    2045

    2065

    2075

    2010

    510

    455

    Only the sal of lines that begin with a 2 character or more, those who are selected.

    Another 1805,1920 sal... .are not selected

    Note: Don't store the numbers in a column varchar2.

  • Can sql RS only 1 column of return can be printed as a separate column value

    Hello
    I wonder if the result set sql returning only one column can be printed as a separate values column?

    IE.with a simple change to select empno, emp; It should be able to print.
    101,102,103

    Instead of
    EmpNo
    ----------
    101
    102
    103

    Thank you
    Jean Claude

    Here is an example with the EMP table in the Scott schema.

    select ltrim(sys_connect_by_path(empno,','),',') empno_list
      from (select e.*, row_number() over(order by empno) rno from emp e)
     where connect_by_isleaf = 1
     start with rno = 1
    connect by rno = prior rno+1
    
  • analog output while keeping the value after the program

    I use a USB 6001 output a simple analog voltage. Right now I'm still in the process of experimenting to see how to control my blood pressure when I noticed that, after I complete my program, data acquisition is always show the last analog value.

    My VI is attached. I use the stop and remove commands at the end of the program so I don't understand why he continues to keep the last value. I used a breakpoint, so I know that program happened to stop and clear commands.

    How to exit back to 0 when I close the program, assuming that there is some other way than the writing of 0 at the end of the program.

    I did not find the related items, but if it don't just answer with a link.

    I thank very you much for any assistance.

    Tommy

    The DAQ hardware is supposed to retain the last value so write a 0 before deleting the task is the right method.

  • Please, be it a while I worked with oracle, but I need to develop my self in PL/SQL. But I'm a challenge to navigate from SQL to the windows command prompt 'diary of the oracle@oel6 '. I often do that before Linux but I don't even know

    Please help

    Janet Oluwadunsin wrote:

    Thanks Steve, I appreciate your correction.

    I want to start the listener from the command prompt, I have connected successfully to sql plus, but I don't remember how I'll get my way to

    [oracle@oel6 journal] $

    at startup my interlocutor.

    I hope this helps

    And just to clarify my and other previous posts... you do NOT get to a command prompt and start your receiver from sqlplus.  sqlplus is a command-line that connects to a database and provides a user interface to the question of the sql to the database statements.  lsncrctl is another command line utility, used to send commands to the listener.  lsnrctl and sqlplus are two completely separate and distinct, all tools two started from the command line of the operating system, that have nothing to do with the other.  Neither one is a kind of 'gateway' to the other.

Maybe you are looking for