Procedure to export the result of the query to an excel or csv

Hi all

I have two identical paintings

EMP_TEST OF THE EMP

ID ID NAME

1     SAM                      1        SAM

2 JOHN 2 ROCK

3 3 STEVE BRAND

I need to combine the result under the query and intent to export data to excel using a procedure

my query is

Select 'EMP_ID', E1. EMP_ID, AND. EMP_ID from emp E1,

emp_test AND WHERE E1. EMP_ID = AND. EMP_ID

UNION

Select "EMP_NAME", E1. EMP_NAME, AND. Emp E1 EMP_NAME,

emp_test AND WHERE E1. EMP_ID = AND. EMP_ID

but I get this error message

ORA-01790: expression must have same type of corresponding data

EMP_ID is a number and EMP_NAME is of type varchar.

I need any idea or suggestion on sub queries.

(1) I have to combine the result set in a single query.

(2) I need to write the procedure that will export the result of the query to an excel or csv.

Thank you.

As PR has said, there are ways that have already been explained in this forum to write in external files. For your query condition, try this.

SELECT CASE WHEN (REGEXP_LIKE (T1.ID,'[^ [: alpha:]] "")) THEN 'EMP_ID '.

ELSE "EMP_NAME' END AS COL_NAME.

T1.ID,

T2.ID

DE)

SELECT CASE WHEN ID IS NULL THEN NAME ANOTHER TO_CHAR (ID) END AS ID,

ROW_NUMBER () OVER(ORDER BY RN NULLS FIRST,ID) RN

DE)

SELECT ID, NULL,

NAME,

RN ID

FROM EMP

UNION ALL

SELECT ID,

NAME,

RN NULL

FROM EMP)) T1.

(SELECT CASE WHEN ID IS NULL THEN NAME ANOTHER TO_CHAR (ID) END AS ID,)

ROW_NUMBER () OVER(ORDER BY RN NULLS FIRST,ID) RN

DE)

SELECT ID, NULL,

NAME,

RN ID

OF EMP_TEST

UNION ALL

SELECT ID,

NAME,

RN NULL

OF EMP_TEST)) T2

WHERE T1. RN = T2. RN;

OUTPUT:

COLUMN-NAME ID ID
--------  ---------------
1 1 EMP_ID
2 2 EMP_ID
3 3 EMP_ID
SAM EMP_NAME MARK
EMP_NAME JOHN JOHN
EMP_NAME STEVE DARREN

6 selected lines.

Tags: Database

Similar Questions

  • export the query result

    Hello
    1. when I want to export the result of the query I have error ORA-00936 (missing expression). Any solution?
    2. I can copy/past the result, but no title for the columns (name ot the column heading). How to make?
    Thanks before.

    1. THE query? Sorry, I'm not psychic, but actually write to me.
    2 CTRL-SHIFT-C

    K.

  • Error while exporting the data in an Excel sheet

    Hi all

    I created a VO that is based on the query (not based on EO) and the query is as follows:

    Select f.user_name,
    f.Description,
    a.currency_code,
    a.amount_to,
    a.amount_from
    seacds.ar_approval_user_limits_nv a, seacds.fnd_user_nv f
    where a.user_id = f.user_id
    and a.document_type = 'CM '.
    order by 2;


    Based on this original Version I created a search page that searches for and returns the data in the table and the finally export standard button will export data in excel sheet.
    In this research data based on over 5 attributes. Without entering anything in the messageTextInput if I'm clicking on this button, it returns all the data in the region of the table. After that if I click on the button export, data are getting exported to the Excel sheet. It is very good.

    But if I'm looking for data by entering a value in one of the messageTextInput, it is returned from the data. But if I'm clicking on the export button then it throws the following error:

    The exception details.
    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: 27122 Houston: SQL error in the preparation of the statement. Statement: SELECT * FROM (select f.user_name,
    f.Description,
    a.currency_code,
    a.amount_to,
    a.amount_from
    seacds.ar_approval_user_limits_nv a, seacds.fnd_user_nv f
    where a.user_id = f.user_id
    and a.document_type = 'CM '.
    order by 2) QRSLT WHERE ((UPPER (CURRENCY_CODE) as UPPER(:1) AND (CURRENCY_CODE like: 2 OR CURRENCY_CODE as: 3 OR CURRENCY_CODE as: 4 OR CURRENCY_CODE as: 5))) ORDER OF DESCRIPTION asc
    at oracle.apps.fnd.framework.OAException.wrapperException (unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageErrorHandler.prepareException (unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageErrorHandler.processErrors (unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.processFormRequest (unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage (unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage (unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage (unknown Source)
    in OA. jspService(_OA.java:71)
    at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
    at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:462)
    at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)
    at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:713)
    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
    at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
    at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:122)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:111)
    to oracle.oc4j.network.ServerSocketReadHandler$ SafeRunnable.run (ServerSocketReadHandler.java:260)
    to com.evermind.util.ReleasableResourcePooledExecutor$ MyWorker.run (ReleasableResourcePooledExecutor.java:303)
    at java.lang.Thread.run(Thread.java:595)
    # # 0 in detail
    java.sql.SQLException: invalid column type
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:138)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:175)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:240)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:7895)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7572)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8183)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectAtName(OraclePreparedStatement.java:8206)

    Please give me any idea to clear this error.

    Thank you and best regards,
    Myvizhi

    Hi all

    I solved the problem... I put the property to select all of the lines as false. So now I'm able to export data.

    Thank you and best regards,
    Myvizhi

  • export the query to txt file, cannot open the help URL

    Hello
    All the
    I need export a query to txt file
    I search on this forum and found a a thread can solve this problem
    But I can't open this URL.
    < div class = "jive-body of the message" > < div class = "jive-quote" >

    http://spendolini.blogspot.com/2006/04/custom-export-to-CSV.html
    < / div >
    Can you kindly send that content on export txt to my Email?

    My email is: [email protected]
    Thank you very much.

    Saven

    item sent via gmail...

    Thank you

    Tony Miller
    Webster, TX

    There are two types of pedestrians - the living and the dead.

    If you answer this question, please mark the thread as closed and give points where won...

  • Export the library of books as a .csv file?

    I'm trying to compare my Calibre library with my library of books in iTunes 11.4. Caliber exports data .csv file, but I don't see how the same (or even a file of Excel data or numbers) to the ca. 950 books in my library of books to iTunes. I managed to 'print' a PDF (28 pages) of it, however.

    Is it possible to get a data file of the compatible spreadsheet of my books on iTunes?

    I never did anything with iBooks, but with iTunes you can actually highlight a series of lines, copy, and paste.

  • Export the result to an Excel file

    I use the attached script to export the inventory then as excel file. I used LucDtechnical of this post to store information in a CSV temp and later, save them to a XLS file. I need to perform a certain formatting in the report, as to change the size of the font of the header, adding some background colors.

    Do not the formatting as I am exporting to a CSV file. Is there another way to achieve the formatting?

    You can take a look at my post Export-Xlsx, the suite and ordered data .

  • How export (unload) result of the query without running query on sql developer

    Hello

    I want to know how export (unload) result of the query without running query on sql developer.

    I know this way.
    1. execution of query
    2. click on "Download" on the results tab
    http://i.stack.imgur.com/CQ4Qb.jpg


    Is he available unload a query result before the race?

    No, but you can do this ask the developer SQL change however, for other users can vote and add weight to the possible future implementation.

    Kind regards
    K.

  • Reruns of data to export the SQL query results grid

    I am running SQL Developer 2.1 on Windows XP. I have a long query that returns the results to the DataGrid. When I export these results, the query is executed again. Why? Is it possible to export the results without rerunning SQL?

    Should not happen. But when sqldev returns results, mind that he gets only the first 50 lines. If you do not get them all before you export, they must be obtained at the course.
    Try CTRL-END in result grid before export and see if it works.

    Hope that helps,
    K.

  • I need to return the result of a query on a stored procedure

    I need to return the result of a query to a stored procedure, I mean when I run a stored procedure it returns a result set in a select statement.
    Best regards...

    Hello.

    Do you really want a stored procedure for this?
    Why not just a script that contains the query?

    Assuming that you don't really want a stored procedure, you'll have to decide what to do with the results.
    An option is a slider.

    For example, you can write a procedure of this type to hold the query:

    CREATE OR REPLACE PROCEDURE USP_TEST
    (     out_cursor     OUT     SYS_REFCURSOR
    )
    IS
    BEGIN
         OPEN  out_cursor
         FOR     SELECT     *
              FROM     scott.emp;
    END  USP_TEST;
    /
    SHOW ERRORS
    

    You can move the cursor to another procedure for handling.

    You could test this in SQL * more by creating a variable blond:

    VARIABLE     usp_test_cursor     REFCURSOR;
    
    EXEC  usp_test (:usp_test_cursor);
    
    PRINT     :usp_test_cursor
    
  • Export the results of a query to a CSV file

    Hello

    My requirement is that I need to export the results of a query to a CSV file. Can someone please suggest a way to also include the names of columns in the CSV file?

    Thanks in advance.

    Annie

    Following code comes from asktom. I changed to include the column header. This will get your CSV file desired for a given query.

    create or replace function  dump_csv( p_query     in varchar2,
                                          p_separator in varchar2
                                                        default ',',
                                          p_dir       in varchar2 ,
                                          p_filename  in varchar2 )
    return number
    AUTHID CURRENT_USER
    is
        l_output        utl_file.file_type;
        l_theCursor     integer default dbms_sql.open_cursor;
        l_columnValue   varchar2(2000);
        l_status        integer;
        l_colCnt        number default 0;
        l_separator     varchar2(10) default '';
        l_cnt           number default 0;
    
         l_colDesc          dbms_sql.DESC_TAB;
    begin
        l_output := utl_file.fopen( p_dir, p_filename, 'w' );
    
        dbms_sql.parse(  l_theCursor,  p_query, dbms_sql.native );
    
        for i in 1 .. 255 loop
            begin
                dbms_sql.define_column( l_theCursor, i,
                                        l_columnValue, 2000 );
                l_colCnt := i;
            exception
                when others then
                    if ( sqlcode = -1007 ) then exit;
                    else
                        raise;
                    end if;
            end;
        end loop;
    
        dbms_sql.define_column( l_theCursor, 1, l_columnValue, 2000 );
    
        l_status := dbms_sql.execute(l_theCursor);
    
         dbms_sql.describe_columns(l_theCursor,l_colCnt, l_colDesc);
    
         l_separator := '';
    
         for lColCnt in 1..l_colCnt
         loop
                utl_file.put( l_output, l_separator ||  '"' || Upper(l_colDesc(lColCnt).col_name) || '"');
                   l_separator := p_separator;
         end loop;
    
         utl_file.new_line( l_output );
    
        loop
            exit when ( dbms_sql.fetch_rows(l_theCursor) <= 0 );
            l_separator := '';
            for i in 1 .. l_colCnt loop
                dbms_sql.column_value( l_theCursor, i,
                                       l_columnValue );
                utl_file.put( l_output, l_separator ||  '"' ||
                                        l_columnValue || '"');
                l_separator := p_separator;
            end loop;
            utl_file.new_line( l_output );
            l_cnt := l_cnt+1;
        end loop;
        dbms_sql.close_cursor(l_theCursor);
    
        utl_file.fclose( l_output );
        return l_cnt;
    end dump_csv;
    

    The original link is below.

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:95212348059

    Thank you
    Knani.

  • 4.0.3 export the result of grid in xlsx for different data type

    Hello

    Using SQL Dev 4.0.3.16 build 16.84 principal.

    Windows 7

    Java 1.7u80

    Run the query, click with the right button on the result of the grid:

    When you export data in xlsx format, why the numbers data type has different type of font.

    -Number / digital-> dialogue

    n.jpg

    -date and varchar2-> Calibri

    v.jpgd.jpg

    Step to reproduce:

    1 run this query

    Select 100 n, '100', to_date (1 January 2015 ',' DD-MM-YYYY "") as d

    Double;

    2. right click on the grid - export

    3. choose the Format: excel 2003 + (xlsx)

    Thank you.

    Buntoro

    This is a known behavior. And I think that there is a feature request to the SQL Developer Exchange, like the export of dates date request and not as text.

    Concerning

    Marcus

  • ORA-06504: PL/SQL: return variables of the game results or the query types do not match

    Hello!

    I have a simple object type and a proecdure in which I am trying to use it to insert into another table

    -object

    CREATE ORREPLACETYPEmt_mtg ASOBJECT

    (

    ACOL NUMBER ,

    BCOL NVARCHAR2 (100)

    );

    CREATE ORREPLACETYPEREF_MTG ASTABLEOFMt_MTG ;

    -same structure as the use of sampletbl target table in the cursor query

    create table tbl_MT_MTG

    (

    ACOL NUMBER ,

    BCOL NVARCHAR2 (100)

    );

    -procedure

    CREATE ORREPLACEINTERIORTEST_PROCEDURE1

    AS

    ref_cur sys_refcursor ;

    REFR ref_mtg ;

    BEGIN

    OPEN ref_cur FOR

    Select acol,

    BCOL

    DE sampletbl rownum<10;

    Fetch ref_cur in bulk collectintorefr;

    Insert intotbl_MT_MTG(acol,bcol)selectacol,bcol fromtable(refr);

    commit;

    CLOSE Ref_cur;

    END;

    /

    When I run this procedure fails with

    ORA-06504: PL/SQL: return variables of the game results or the query types do not match

    ORA-06512: at "TEST_PROCEDURE1", line 10

    ORA-06512: at line 2

    Any help on this please...

    Thanks to an OLD POST below

    so perfect helped me! Thank you

    Tubby

    After 5 years of more :-)

    How to store refcursor in collection How to store refcursor in collection

  • The query results reel in a file and the number of lines in a different file

    Hello

    I would like to export only the result of my query to a file. I am able to do this with several sql, but I want the number of selected lines in a different file than the output "log".

    For example:

    -------------------------------------
    Select 'TEST' for the DOUBLE;

    TEST

    + 1 row selected. +

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

    So 'TEST' should be included in the results file and ' 1 selected line"to a different log file.

    Is it possible to achieve this sql * more.

    Thank you for your time

    Rodriguez,

    Hi, Rodriguez,

    Welcome to the forum!

    Here's one way:

    COLUMN     row_cnt_col  NOPRINT     NEW_VALUE row_cnt
    
    --  You may or may not want the following settings.
    --  The 2-file output works with or without them.
    SET     FEEDBACK     OFF
    SET     VERIFY          OFF
    
    SPOOL     dept.txt
    
    SELECT     deptno, dname
    ,     COUNT (*) OVER ()     AS row_cnt_col
    FROM     scott.dept
    ;
    
    SPOOL     OFF
    
    SPOOL     dept.log
    
    SELECT     &row_cnt     AS total_rows_found
    FROM     dual;
    
    SPOOL     OFF
    

    The first SPOOL file, dept.txt, looks like this:

    `   DEPTNO DNAME
    ---------- --------------
            10 ACCOUNTING
            20 RESEARCH
            30 SALES
            40 OPERATIONS
    

    The second SPOOL file, dept.log, looks like this:

    TOTAL_ROWS_FOUND
    ----------------
                   4
    

    Taking your example, only the first query should change:

    SELECT     'TEST'               AS output
    ,     COUNT (*) OVER ()     AS row_cnt_col
    FROM     dual
    ;
    

    The second query and all the stuff set up is exactly the same.

    Published by: Frank Kulash, 27 September 2012 09:38

  • Using the procedure with multiple output variables in a query

    Hello

    We have a process that takes time, which returns 4 variables as out parameters:
    procedure calc_values(id in number, val1 out number, val2 out number, val3 out number, val4 out number) is
    The id uniquely identifies a product in our database.

    I would use it in a query (or view), in the form
    select s.id, val1, val2, val3, val4 from something s, product_table p
    where s.id = p.id
    I tried the following approach, but I'm kinda stuck

    define the type
    define an array of this type
    write a wrapper function that calls this procedure and returns the results as a table
    * the PivotTable in columns
    * join this with the product table

    It's like I'm on the wrong track, I'm struggling to retrieve the id of the product table in the wrapper function.

    Is there a better approach for this? I'm on oracle 10g

    Thank you!

    Rob

    Below is my interpretation of what you were asked to do. I don't really know what you want to do or what you need to do.

    CREATE TYPE prod_vals_def
    AS OBJECT
     (VAL1      NUMBER,
      VAL2      NUMBER,
      VAL3      NUMBER,
      VAL4      NUMBER
    );
    
    create or replace
    TYPE   prod_vals_tab
    AS TABLE OF prod_vals_def;
    
    CREATE FUNCTION pvals (p_prod_id  NUMBER)
    RETURN prod_vals_tab PIPELINED
    AS
    
      TYPE         ref0 IS REF CURSOR;
      cur0         ref0;
      out_rec      prod_vals_def
                := prod_vals_def(NULL,NULL,NULL,NULL);
    
    BEGIN
      -- CASE replacing SELECT against table I'm not going to create
      CASE p_prod_id
        WHEN 1 THEN
          out_rec.val1 := 1;
          out_rec.val2 := 2;
          out_rec.val3 := 3;
          out_rec.val4 := 4;
        WHEN 2 THEN
          out_rec.val1 := 2;
          out_rec.val2 := 3;
          out_rec.val3 := 4;
          out_rec.val4 := 5;
        WHEN 3 THEN
          out_rec.val1 := 3;
          out_rec.val2 := 4;
          out_rec.val3 := 5;
          out_rec.val4 := 6;
        WHEN 4 THEN
          out_rec.val1 := 4;
          out_rec.val2 := 5;
          out_rec.val3 := 6;
          out_rec.val4 := 7;
        ELSE
          out_rec.val1 := 0;
          out_rec.val2 := 0;
          out_rec.val3 := 0;
          out_rec.val4 := 0;
      END CASE;
      PIPE ROW(out_rec);
    END pvals;
    
    WITH s_tab AS
      (SELECT 1 AS prod_id FROM dual
       UNION ALL
       SELECT 2 AS prod_id FROM dual
       UNION ALL
       SELECT 3 AS prod_id FROM dual
       UNION ALL
       SELECT 4 AS prod_id FROM dual
      )
    SELECT s.prod_id, p.val1, p.val2, p.val3, p.val4
    FROM   s_tab s,
           TABLE(pvals(s.prod_id)) p
    
    PROD_ID  VAL1     VAL2     VAL3     VAL4
    -------- -------- -------- -------- --------
    1        1        2        3        4
    2        2        3        4        5
    3        3        4        5        6
    4        4        5        6        7     
    
  • assign the value to a selection of the result of a query control

    I want to assign a value to my controls with the result of the query.

    It works for CFINPUT TEXT, but it does not work to SELECT

    I want to know are there any way tp affect my drop-down list value based on the result of questy.

    I have CFSTOREPROC as follows:

    < cfstoredproc procedure = "PSP" >

    < cfprocparam value = '#form. "IDNumber #" CFSQLTYPE = "cf_sql_integer" >

    < name cfprocresult = resultset "spResult" = "1" >

    < / cfstoredproc >

    < type CFINPUT = 'text' id = "txtIDNumber" value = "" #spResult.IDNumber # "/ >"

    I am able to name a TEXT of ENTRY CF as above the code value,

    < select id = "lstNumber" value = "#spResult.lstNumber #" > < / select >

    but it does not affect the value of my result of the query to SELECT entry.

    Is it possible to assign a value to the query result SELECTION control?

    I tried to use JavaScript that works if I pass a number, but it does not work if I pass a query result,

    Your help is very appreciated,

    Kind regards

    Iccsi,

    @Iccsi,

    My bad!  Yes, you will either need to the CFOUTPUT tag (that you commented out in your code) but without specifying a query or change the CFLOOP query CFOUTPUT = "Notes".  If one of these should work:

    OR

    -Carl V.

Maybe you are looking for

  • Scrolling horizontal bar not scaling of any show.

    I'm working on an array of numbers, and nothing was wrong at the beginning.  Now, the horizontal scroll bar will not scroll pretty far to the left to view early columns that need to be highlighted by behind the header columns.  When scrolling further

  • Accumulation of too big EXE

    After I have an accumulation of the exe, it is 28 M. After this surge, there will be 97 m in memory. Is it possible to make the smaller exe. Thank you.

  • Peak and frequency

    Hey guys,. I am trying to solve a problem of frequency (see the file: this is just an example!). I would like to know the corresponding frequency at each Summit. I don't know weather I have good VI (see photo of png). the "output" location seems not

  • I have a galloping tmp file.

    I have a galloping tmp file. I can't remove it and I can't stop loading again and again and again. I need to reboot to clear my laptop. It makes me crazy... I downloaded, cleaned, you name it I tried, every day now...

  • Bootmgr missing and I have tried using the recovery installation window and it fails. no operating system are loaded.

    Double post merged and deleted.  Post moved from XP to Vista forum forum> Laptop HP discharged linux os, linux is the only operating system on laptop... Loading Vista missing bootmgr, the recovery option window has not repaired the file. I have no op