Generate CSV with pl.sql column names

Hi guys,.

Well, I am back after a long hiatus in this form, was occupied by SAP BI project.

Now do some oralce - sap project, well here, I needed to generate a CSV of many many queries,

I can do via sql, but I tot it would be better to write a package or a common procedure to generate csv files

ex, if I pass the query to the proceudre it should generate csv on the server directory file, later I send these file to the users concerned.

The e-mail part is later, but first of all is to have a package of generic to launch and run the query n generate the csv file.

I guess this should be possible using native dynamic sql and utl_ package, but I don't know how to get the columns name,

If one has implemented this please explain me the way,.

ex:
Select emp,mgr, empno from emp;

emp mgr empno
 1    1    123
  2   1    234

something like that
hope my question is clear 

Maybe try this

http://asktom.Oracle.com/pls/asktom/asktom.download_file?p_file=6551135514501758779

Tags: Database

Similar Questions

  • How to create Table View with even a column name but another Table?

    Hi all

    I have the problem to create a tableview with the same column name, but in the other table.

    Table I: -.

    Table - PAC051MPROFORMA

    Column - MNR, visitid

    Table - PAC051TPROFORMA
    Column - MNR, visitid

    Table - PAC052MTRANSBILL
    Column - MNR, visitid

    Then, I want to create a table for this table. It comes to my SQL

    Pacviewproforma CREATE VIEW (MNR, visitid, MNR, visitid, MNR, visitid)

    Like some PAC051MPROFORMA.mrn, PAC051MPROFORMA.visitid, PAC051TPROFORMA.mrn, PAC051TPROFORMA.visitid, PAC052MTRANSBILL.mrn, PAC052MTRANSBILL.visitid

    where

    * (a.PAC051MPROFORMA.mrn = PAC051TPROFORMA.mrn) *.
    and
    * (a.PAC051TPROFORMA.mrn = PAC052TRANSBILL.mrn) *.

    SQL return this error ORA-00957 =: duplicate column name

    Can I change this SQL for

    Pacviewproforma CREATE VIEW (MNR, visitid)

    Like some PAC051MPROFORMA.mrn, PAC051MPROFORMA.visitid, PAC051TPROFORMA.mrn, PAC051TPROFORMA.visitid, PAC052MTRANSBILL.mrn, PAC052MTRANSBILL.visitid

    where

    * (a.PAC051MPROFORMA.mrn = PAC051TPROFORMA.mrn) *.
    and
    * (a.PAC051TPROFORMA.mrn = PAC052TRANSBILL.mrn) *.
    This time this error return = ORA-01730: number of column names specified invalid

    What should I do?

    Thank you...

    Hello

    SQL> CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
      2  As Select
      3  PAC051MPROFORMA.mrn,
      4  PAC051MPROFORMA.visitid,
      5  PAC051TPROFORMA.mrn,
      6  PAC051TPROFORMA.visitid,
      7  PAC052MTRANSBILL.mrn,
      8  PAC052MTRANSBILL.visitid
      9  from PAC051MPROFORMA,PAC051TPROFORMA,PAC052MTRANSBILL
     10  where
     11  (PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)
     12  and
     13  (PAC051TPROFORMA.mrn=PAC052MTRANSBILL.mrn);
    CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
                                             *
    ERROR at line 1:
    ORA-00957: duplicate column name
    

    Please give different names to each column.

    Something like that...

    SQL> CREATE OR REPLACE VIEW pacviewproforma (MPROFORMA_mrn,MPROFORMA_visitid,TPROFORMA_mrn,TPROFORMA
    _visitid,MTRANSBILL_mrn,MTRANSBILL_visitid)
      2  As Select
      3  PAC051MPROFORMA.mrn,
      4  PAC051MPROFORMA.visitid,
      5  PAC051TPROFORMA.mrn,
      6  PAC051TPROFORMA.visitid,
      7  PAC052MTRANSBILL.mrn,
      8  PAC052MTRANSBILL.visitid
      9  from PAC051MPROFORMA,PAC051TPROFORMA,PAC052MTRANSBILL
     10  where
     11  (PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)
     12  and
     13  (PAC051TPROFORMA.mrn=PAC052MTRANSBILL.mrn);
    
    View created.
    
    SQL> DESC  pacviewproforma;
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     MPROFORMA_MRN                                      NUMBER
     MPROFORMA_VISITID                                  NUMBER
     TPROFORMA_MRN                                      NUMBER
     TPROFORMA_VISITID                                  NUMBER
     MTRANSBILL_MRN                                     NUMBER
     MTRANSBILL_VISITID                                 NUMBER
    

    ORA-01730: number of column names specified invalid

    The list of the nmae column you specified for the CREATE VIEW must correspond with the list of SELECTION in the view.

    Twinkle

  • Question PLSQL with variable compound column names

    Hello gentlemen,


    I'm new to PLSQL and I would like to display some values of columns, which are listed in the defined variable in dbms.output. I created under code, which I think it could work, but I guess that it is far from correct.


    DECLARE
    v_TEMP_QUERY VARCHAR2
    (1000 BYTE);
    v_TEMP_VALUE VARCHAR2
    (1000 BYTE) := 'FILTER_01, FILTER_02';

    BEGIN  
    FOR v_TEMP_LOOP IN
    (v_TEMP_QUERY := 'SELECT DISTINCT ' || v_TEMP_VALUE || ' FROM CW_PAGE_COMPONENT_TEMPL WHERE COMPONENT_TEMPL_ID = 10000034642';
    EXECUTE IMMEDIATE v_TEMP_QUERY; )
    LOOP
    DBMS_OUTPUT
    .PUT_LINE (v_TEMP_LOOP.v_TEMP_VALUE);
    END LOOP;
    END;


    Thanks in advance for your help and advice on this issue and sincerely,

    Sebastian

    OK, first of all, you're confused concepts here.

    cursor loop FOR waiting for a slider must be provided, and yet you offer an assignment statement and a command immediately execute for it.  Syntax is not valid.

    Secondly, you force the way of the use of dynamic SQL, which is generally bad practice.  This use of the SQL is rarely necessary, because it often indicates that functional requirements, database design, or design/code enforcement has not examined properly... the first question is "why don't you know the names of the columns to select.  With dynamic columns in your query, you need some kind of dynamic code to manage the results of the query, you will not be able to reference the columns directly by name.

    Thirdly, the DBMS_OUTPUT package doesn't make "blank".  This may sound pedantic, but it's a common mistake that people make.  There is no fill data dbms_output buffer.  It relies on call code/interface to read the contents of the output buffer and display it in fact (for example, in SQL * more you use SQL * Plus the command "set serveroutput we ' to achieve)

    In general, in a well designed where application you know your columns you would only make...

    Start
    I'm in (select distinct filter_01, filter_02 from vw_page_component_templ where component_templ_id = 10000034642)
    loop
    dbms_output.put_line (i.filter_01 | ',' | i.filter_o2);
    end loop;
    end;

    If the columns are dynamic, then you have three options:

    (1) create a ref and pass cursor who back, extracting the content for example

    sys_refcursor getRc function returns (in numbers, in colnames templ_id varchar2) is
    RC sys_refcursor;
    Start
    Open rc for ' select distinct ' | colnames |' from vw_page_component_templ where component_teml_id =: 1' using templ_id;
    return rc;
    end;

    In SQL * more:

    var r refcursor; -It creates a variable in SQL * Plus ref cursor type
    Start
    : r: = getRc (10000034642, ' filter_01, filter_02');
    end;
    /
    print r;      -It's SQL * command to retrieve the cursor open and display the results

    (2) create an object and collection of the right structure to receive the results and use execute immediate to select IN this structure.

    (I will not show in this way, because it is absolute rubbish, and if you know the columns that you want to create the object and the collection, then you should not use dynamic SQL in the first place)

    (3) use the DBMS_SQL package to run the query and retrieve the data from the column in position rather than example:

    create or replace procedure run_query (p_sql IN VARCHAR2) is
    v_v_val varchar2 (4000);
    number of v_n_val;
    date of v_d_val;
    number of v_ret;
    c number;
    number d;
    whole col_cnt;
    Boolean f;


    rec_tab dbms_sql.desc_tab;
    number of col_num;
    v_rowcount number: = 0;
    Start
    -create a slider
    c: = dbms_sql.open_cursor;
    -analyze the SQL statement in the cursor
    DBMS_SQL. Parse (c, p_sql, dbms_sql.native);
    -run the cursor
    d: = dbms_sql.execute (c);
    --
    -Describe the columns that are returned by the SQL statement
    DBMS_SQL. DESCRIBE_COLUMNS (c, col_cnt, rec_tab);
    --
    -Local variables Bind to return to the different columns according to their types
     
    dbms_output.put_line (' number of columns in the query: ' | col_cnt);
    1.col_cnt j
    loop
    case rec_tab (j) .col_type
    When 1 then dbms_sql.define_column (c, j, v_v_val, 2000); -Varchar2
    When 2 then dbms_sql.define_column (c, j, v_n_val);      -Number
    12. When can dbms_sql.define_column (c, j, v_d_val);     -Date
    on the other
    DBMS_SQL.define_column (c, j, v_v_val, 2000);  -Any other type of return as varchar2
    end case;
    end loop;
    --
    -Display columns are returned...
    dbms_output.put_line ('- Columns-');
    1.col_cnt j
    loop
    dbms_output.put_line (rec_tab (j) .col_name |') -' || case rec_tab (j) .col_type when 1 then 'VARCHAR2 '.
    When 2 then 'NUMBER '.
    When 12 can "DATE".
    "Otherwise, 'Other' end);
    end loop;
    dbms_output.put_line('---');
    --
    -This part generates the DATA
    loop
    -Retrieves a row of data using the cursor
    v_ret: = dbms_sql.fetch_rows (c);
    -Output when no more line
    When the output v_ret = 0;
    v_rowcount: = v_rowcount + 1;
    dbms_output.put_line (' line: ' | v_rowcount);
    dbms_output.put_line('---');
    -Extract the value of each column of the row
    1.col_cnt j
    loop
    -Fetch each column to the correct data type according to the description of the column
    case rec_tab (j) .col_type
    When 1 then dbms_sql.column_value (c, j, v_v_val);
    dbms_output.put_line (rec_tab (j) .col_name |': ' | v_v_val);
    When 2 then dbms_sql.column_value (c, j, v_n_val);
    dbms_output.put_line (rec_tab (j) .col_name |': ' | v_n_val);
    12. When can dbms_sql.column_value (c, j, v_d_val);
    dbms_output.put_line (rec_tab (j) .col_name |': ' | to_char (v_d_val,' DD/MM/YYYY HH24:MI:SS'));))
    on the other
    DBMS_SQL.column_value (c, j, v_v_val);
    dbms_output.put_line (rec_tab (j) .col_name |': ' | v_v_val);
    end case;
    end loop;
    dbms_output.put_line('---');
    end loop;
    --
    -Close the cursor, now we're done with it
    DBMS_SQL.close_cursor (c);
    END;
    /

    SQL > run_query exec ('select ename, empno, sal, deptno from emp where deptno = 10');
    Number of columns in the query: 4
    -Columns-
    EMPNO - NUMBER
    ENAME - VARCHAR2
    DEPTNO - NUMBER
    SAL - NUMBER
    -------------
    Line: 1
    --------------
    EMPNO: 7782
    ENAME: CLARK
    DEPTNO: 10
    SAL: 2450
    --------------
    Row: 2
    --------------
    EMPNO: 7839
    ENAME: KING
    DEPTNO: 10
    SAL: 5000
    --------------
    Row: 3
    --------------
    EMPNO: 7934
    ENAME: MILLER
    DEPTNO: 10
    SAL: 1300
    --------------

    PL/SQL procedure successfully completed.

    As you can see with this method, you can extract the column details, including the name and data etc. types and then extract each line and extract the data from the column position.

    Of course, this is quite complex, so it would be a last resort.

  • apex5 pre-release - url filter applies to the two IRs with the same column name

    I've implemented 2 interactive reports on the same page, one on EMP (static id Throne) and the other on DEPT (deptir static id). Both the DEPTNO column. If I create the following filter via the URL: IR [throne] EQ_DEPTNO:20, the filter is applied to the two interactive reports.

    Screenshot from 2015-03-29 08:30:33.png

    Hello

    Please let us know. It has the same root cause as your other reported problem. It's bug #20764255, which has already been identified and corrected on our development environment. A fix will be released in our production release.

    Concerning

    Patrick

    Member of the APEX development team

    My Blog: http://www.inside-oracle-apex.com

    APEX Plug-Ins: http://apex.oracle.com/plugins

    Twitter: http://www.twitter.com/patrickwolf

  • Need help query view with the 'Level' column name

    Hello world

    I use Oracle DB 10 g

    I have this request
    SELECT  count(per_id) 
    FROM    XXITS_EMP_MSTR_V
    WHERE   per_id = 213214 
    AND     Level='Technical Staff / Officer'
    XXITS_EMP_MSTR_V is a view created by someone else.

    I get the error "ORA-01788: CONNECT BY clause in this query block" for the the above statement.
    Is it possible that I can always get the result without changing the view?

    Any help is appreciated...

    Thank you
    Elmer

    Elmer says:
    Hello world

    I use Oracle DB 10 g

    I have this request

    SELECT  count(per_id)
    FROM    XXITS_EMP_MSTR_V
    WHERE   per_id = 213214
    AND     Level='Technical Staff / Officer'
    

    Place the level with quotes

    AND "Level" = 'Technical Staff / Officer'
    

    Make sure that the case is used correctly when using double quotes.

  • ERROR DUPLICATE COLUMN NAME

    I get an error of duplicate column name to submit using automatic processing of line.

    I have a few items on the page with the same column name, but they appear under certain conditions. Even if I put in them NEVER occurs again.

    I would understand that you still can't duplicate names even if the elements are conditional?

    If this is the case, then Ill have to do with javascript or something. Pain cos apart from that, my form is quite clean

    Thanks for the help of anyones :-)

    Colin

    Since your sql does not deal with conditional columns, you don't CAN NOT use the same column name several times... Unless you write your own DML to manage updates/inserts & removes...

    Thank you

    Tony Miller
    Webster, TX

  • Oracle: Nested joins/sub-requetes: odd column names and an unexplained error

    The following query works fine. It is a series of nested joins to give me a kind of main table:

    SELECT *

    FROM proj_trainer k

    JOIN

    (

      SELECT *

      FROM proj_breeder i

      JOIN

      (

      SELECT *

      FROM proj_jockey g

      JOIN

      (

      SELECT *

      FROM proj_horses e

      JOIN

      (

      SELECT *

      FROM proj_results c

      JOIN

      (

      SELECT *

      FROM proj_race_details a

      JOIN proj_meet b

      ON a.meet_id = b.meet_id

      ) d

      ON c.race_id = d.race_id

      ) f

      ON e.horse_id = f.horse_id

      ) h

      ON g.jockey_id = h.jockey_id

      )j

      ON i.breeder_id = j.breeder_id

    ) l

    ON k.trainer_id = l.trainer_id;

    It works very well with a strange feature, that is not my main problem. Some columns are back with weird codes such as "QCSJ_C000000001300001". Don't know why, or if it comes to my real problem.

    The real problem is that when I add just a subquery join more I get:

    ORA-00904: "N"."RACE_ID": invalid identifier

    Here is the same code with the additional nested block (the one on the very outside)

    SELECT *

    FROM proj_entry m

    JOIN

    (

      SELECT *

      FROM proj_trainer k

      JOIN

      (

      SELECT *

      FROM proj_breeder i

      JOIN

      (

      SELECT *

      FROM proj_jockey g

      JOIN

      (

      SELECT *

      FROM proj_horses e

      JOIN

      (

      SELECT *

      FROM proj_results c

      JOIN

      (

      SELECT *

      FROM proj_race_details a

      JOIN proj_meet b

      ON a.meet_id = b.meet_id

      ) d

      ON c.race_id = d.race_id

      ) f

      ON e.horse_id = f.horse_id

      ) h

      ON g.jockey_id = h.jockey_id

      )j

      ON i.breeder_id = j.breeder_id

      ) l

      ON k.trainer_id = l.trainer_id

    ) n

    ON n.race_id = m.race_id AND n.horse_id = m.horse_id;

    I felt as if I was on the hill with it and then the last line was wrong somehow, despite having virtually the same structure as all previous blocks. I also used the race_id and the horse_id above in the code so that they work.

    I also tried this on the last line:

    ON n.race_id = m.race_id AND n.horse_id = m.horse_id;

    and a few other variations, with supports etc...

    Hello

    I can't reproduce the problem, so I can't say with certainty. It might have to do with the same column names which occur in several tables.

    Why do you need nested views online?  Why not simply join all tables directly, like this?

    SELECT *- or display the columns that you really need

    OF proj_race_details one

    JOIN proj_meet b ON b.meet_id = a.meet_id

    JOIN proj_resuls c ON c.race_id = b.race_id - or a.race_id

    ...

    JOIN proj_trainer k WE k.trainer_id = i.trainer_id - or else

    JOIN proj_entry m ON m.race_id = k.race_id - or else

    AND m.horse_id = k.horse_id - or else

    ;

    I guess just the tables that contain columns; for example, I can't tell what you posted if proj_race_details or proj_meet contains race_id.  If I guessed wrong, use the correct table alias.  Are eligible all the column names with the correct alias.

  • Change the column names in the Table of snapshot?

    Now when you create a snapshot - a table is created using names of columns like C_PRODUCT_MEMBER_CAPTION or C_MEASURES_MEASURE_NAME

    Is it possible to format these column names when creating the table?
    As a measure named "Expéditions" would create a name of column 'Deliveries' and not 'C_MEASURES_SHIPMENTS '.

    I am aware that MDX can Member alias names such as:

    WITH MEMBER [Measures]. [New name] [MEASURES]. [Really long name that I want to change]

    But it would not always remove the prefix "C_MEASURES_".

    Thank you
    John

    John,

    Don't believe it's possible - tables snapshot always end with the crazy column names. I my experience, the raw snapshot tables (almost) always need to be post-processed, which is where you'd of beautiful readable columns.

  • Create table works, create materialized view only - long column names?

    Hello.

    I have no probs creating a table as well: -.
    CREATE TABLE blah
    (
    DEVICE_ID
    )
    in select
    "Device_ID" AS DEVICE_ID
    "of"sum" Device"@ed_link_3
    where "Device_ID" < 5;


    But when I try to create a materialized view:
    Blah1 CREATE MATERIALIZED VIEW
    (
    DEVICE_ID
    )
    < various materialized view parms >
    in select
    "Device_ID" AS DEVICE_ID
    "of"sum" Device"@ed_link_3
    where "Device_ID" < 5;

    It fails with errors: -.
    ORA-04052: error occurred when searching to the top of the remote object Aggregate.Device@ED_LINK_3
    ORA-01948: length of the name of the identifier (31) exceeds maximum (30)

    Is there a way to get around this?
    Is the problem with the columns of the remote table of device, which I do NOT need to import to have column names that are longer than 30 characters?

    For now, I want only the Device_ID column which is a simple 9 characters long.

    Oh, and the remote database is MySQL.
    I'm uncomfortable with the < parms of materialized view > as they work fine when I choose a different remote table with only short column names.

    Thank you.

    To my knowledge, you have the option
    (a) create view (with shortened column names or only with desired columns if they are already less than 30 char limit) side of mysql
    (b) use dbms_passthrough to force the analysis to be done on mysql (as in the example provided by SY here use dbms_passthrough to create a view )
    However, I prefer to stick to one), because with dbms_passtrhough, you retrieve row by row.

    Best regards

    Maxim

  • [SQL * Loader] ORA-01747 on column name 'INDEX '.

    Hello

    I use SQL * Loader to load the test data for the CSV files. I have a column whose name is "INDEX". SQL * Loader works very well under Linux (Red Hat 6 - Client Oracle 11.2.0.1.0) but I encounter ORA-01747 launch my Workstation Windows (Oracle Server 11.2.0.1.0).

    For more information, I target the same instance (Red Hat 6 - Oracle Server 11.2.0.1.0).

    You have an idea how to solve the problem (without renaming the column )?

    Thanks for any help you can provide.

    I finally find the solution surrounding the column name with double quotes ("") within the control file. Thank you to remember the format of "protector".

  • SSRS 2012 export to CSV with no data by generating coma separated with an empty value

    I have a report that have no data due to parameter motor (both have true noheader configuration).

    In SSRS 2005 its generate empty csv file and for SSRS 2012 his record still generate with coma and an empty value, something like this:

    ,,,,

    Those that were generated by Server (SSRS 2005 and 2012 SSRS), tnot different heres in the rsreportserver.config file to make segment.

    If I exported the csv file to SQL Server Data Tools for Visual Studio 2012, it generated an empty file (which is correct).

    Anything I missed here?

    Just realized, its due to my 2012 SSRS is the RTM version and its due to SSRS bugs has been fixed on SP2 + CU3

    https://support.Microsoft.com/en-us/KB/3002049

  • Write a SQL query with lines in columns

    All the

    I need help in writing a SQL query with lines in columns, let give u an example...

    drop table activity;

    CREATE TABLE 'ACTIVITY '.

    (

    "PROJECT_WID" NUMBER (22.0) NOT NULL,

    VARCHAR2 (150 CHAR) "PROJECT_NO."

    VARCHAR2 (800 CHAR) 'NAME '.

    );

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1683691, '10007', 12-121');

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1684994, '10008', 12-122');

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1686296, '10009', 12-123');

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (2225222, '9040', 12-124');

    drop table lonet;

    CREATE TABLE 'LONET.

    (

    VARCHAR2 (150 CHAR) "NAME."

    NUMBER OF THE "ROOT."

    VARCHAR2 (150 CHAR) "ENTRYVALUE".

    );

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1683691, "LDE");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1683691, 'LME');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1683691, 'ICE');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1683691, 'IKE');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1686291, "QTY");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1686291, 'MAX');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1684994, "MTE");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1684994, 'MAC');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMT', 1684994, 'NICE');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMR', 1684994, 'RAY');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1686296, "CAQ");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("PAP", 1686296, "QAQ");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("VANESSA", 1686296, "THEW");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("ANDR", 1686296, "REYL");

    commit;

    Link: activity.project_wid = lonet.root

    look like output

    Project_wid Project_no NAME GAC NAM BAG RAC
    16836911000712-121LDELMELCELKE
    16849941000812-122MTEnullnullMAC
    16862961000912-123nullnullCAQQAQ
    2225222904012-124nullnullnullnull

    two problems, in that I am running

    1. I dono how simply we can convert rows to columns

    2. for root = 1683691, there are double NAM and RAC in lonet table... ideally these data should not be there, but since its here, we can take a MAX so that it returns a value

    3. There are undesirables who should be ignored

    Once again my thought process is that we join the activity and 4 alias table lonet.

    ask for your help in this

    Thank you

    Hello

    This is called pivoting.

    Here's a way to do it:

    WITH relevant_data AS

    (

    SELECT a.project_wid, a.project_no, b.SID

    , l.name AS lonet_name, l.entryvalue

    Activity one

    LEFT OUTER JOIN lonet l.root = a.project_wid l

    )

    SELECT *.

    OF relevant_data

    PIVOT (MAX (entryvalue)

    FOR lonet_name IN ("GAC" IN the gac

    "NAM" AS nam

    'BAG' IN the bag

    "RAC" AS cars

    )

    )

    ORDER BY project_wid

    ;

    Output:

    PROJECT_WID PROJECT_NO GAC NAM BAG RAC NAME

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

    1683691 12 - 10007 121 LDE LME LCE LKE

    1684994 MAC MTE 10008 12-122

    1686296 12 - 10009 123 QAC QAQ

    2225222 9040 12 - 124

    To learn more about swivel, see the FAQ in the Forum: Re: 4. How can I convert rows to columns?

    Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!

  • Necessary emergency with a request: fill date of prior art on the column name

    Hello

    Can you please help me with the query. I would be grateful for your time and your help.

    I have the query and the following output. Basically, the query selects a date, a table and counties received documents based on the current date, day-1, - 2 days-, 3 days-4 days-5 days and especially 5 days. It's the query I wrote. Now the requirement has slightly changed and described below.

    Current query:

    SELECT SUM (CASE WHEN TRUNC (SYSDATE) TRUNC ( )File_Date() = 0 PUIS 1 AUTRE 0 FIN) Zéro ,

    SUM (CASE WHEN TRUNC (SYSDATE) TRUNC ( )File_Date() = 1 PUIS 1 AUTRE 0 FIN)   One ,

    SUM (CASE WHEN TRUNC (SYSDATE) TRUNC ( )File_Date() = 2 PUIS 1 AUTRE 0 FIN) Two ,

    SUM (CASE WHEN TRUNC (SYSDATE) TRUNC ( )File_Date() = 3 ALORS 1 SINON 0 FIN) Trois ,

    SUM (CASE WHEN TRUNC (SYSDATE) TRUNC ( )File_Date() = 4 PUIS 1 AUTRE 0 FIN) Quatre ,

    SUM (BOX WHEN TRUNC (SYSDATE) TRUNC (File_Date) = 5 THEN 1 ELSE 0 END) Five ,

    SUM (CASE WHEN TRUNC (SYSDATE) TRUNC ( )File_Date() > 5 PUIS 1 AUTRE 0 FIN) OverFive ,

    COUNTY (*) Total

    DE DOCUMENT_TABLE

    OUTPUT:

    Zero

    One

    Two

    Three

    Four

    Five

    More than five

    Total

    3

    6

    3

    6

    10

    50

    100

    178

    Now the desired output:

    The column name must be the date, for example the column name, we're Sysdate, two column name is Sysdate-1 day and the result would look like:

    OUTPUT:

    17/12/2014

    16/12/2014

    15/12/2014

    14/12/2014

    13/12/2014

    12/12/2014

    More than five

    Total

    3

    6

    3

    6

    10

    50

    100

    178

    Hi, just try below as you say it's urgent

    Select sysdate, sysdate-1, sysdate-2, sysdate-3,-4, etc of daul sysdate

    Union

    your query

    (you must ensure for the same type of data)

    are you using oracle report or just in the sql query. If the reports, then you can manage very easily with the introduction of a formula column.

  • How to export data to excel that has 2 tables with the same number of columns and the column names?

    Hi everyone, yet once landed upward with a problem.

    After trying many things to myself, finally decided to post here...

    I created a form in form builder 6i in which clicking on a button, the data gets exported to the excel sheet.

    It works very well with a single table. The problem now is that I cannot do the same with 2 tables.

    Because the tables have the same number of columns and the columns names.

    Here are the 2 tables with column names:

    Table-1 (MONTHLY_PART_1) Table-2 (MONTHLY_PART_2)
    SL_NOSL_NO
    MODELMODEL
    END_DATEEND_DATE
    U-1U-1
    U-2U-2
    U-4U-4
    ..................
    ..................
    U-20U-20
    U-25U-25

    Given that the tables have the same column names, I get the following error :

    402 error at line 103, column 4

    required aliases in the SELECT list of the slider to avoid duplicate column names.

    So how to export data to excel that has 2 tables with the same number of columns and the column names?

    Should I paste the code? Should I publish this query in 'SQL and PL/SQL ' Forum?

    Help me with this please.

    Thank you.

    Wait a second... is this a kind of House of partitioning? Shouldn't it is a union of two tables instead a join?

    see you soon

  • SQL: REGEXP_SUBSTR CSV with string delimiter

    Hello

    I would like to create a function to split a CSV file with string using REGEXP delimiter.

    Because the REGEXP function does not deal with NULL values, in the first place, I use a REGEXP_REPLACE:

    SELECT REGEXP_REPLACE (' ' ' ';) "2011-12-30 15:33:15 '; "" 116 "; » « ; » 1 » ; "" ANSWER "; "" SIP/SDX20016-b6ec9c10 '; (""', '("") + ',' 'NULL' ') FROM dual;

    Result:

    'NULL '; "2011-12-30 15:33:15 '; "" 116 "; "' NULL '; » 1 » ; "" ANSWER "; "" SIP/SDX20016-b6ec9c10 '; "' NULL '.

    If I can deal with the empty columns.

    Then I apply this REGEXP:

    SELECT REGEXP_SUBSTR (' 'NULL';) "2011-12-30 15:33:15 '; "" 116 "; "' NULL '; » 1 » ; "" ANSWER "; "" SIP/SDX20016-b6ec9c10 '; ("' NULL ' ',' [^(";")] +', 1, level)-LOOSE COLLECTION ltab_SplittedTelList
    OF the double
    CONNECT REGEXP_SUBSTR (' 'NULL';) "2011-12-30 15:33:15 '; "" 116 "; "' NULL '; » 1 » ; "" ANSWER "; "" SIP/SDX20016-b6ec9c10 '; » NULL » ', ' [^ « ; »] +', 1, level) IS NOT NULL;

    Result:

    NULL VALUE

    2011-12-30 15:33:15

    116

    NULL VALUE

    1

    REPLIED

    SIP/SDX20016-b6ec9c10

    NULL VALUE

    Very good, but if I put a delimiter column ';' in the middle of a string, for example in the middle of the date, I had my date cut in two.

    I can't find the correct model for my REGEXP.

    Jump, it is possible to do it with REGEXP.

    Thanks in advance,

    Greg.

    Hi, Greg.

    Here's a way to do it in pure SQL:

    WITH got_str AS

    (

    SELECT "' ';'" 2011 12-30; 15:33:15 '; 116. " » « ; » 1 » ; "" ANSWER "; "" SIP/SDX20016-b6ec9c10 '; ' ' ' ' ' AS str

    OF the double

    )

    SELECT THE LEVEL

    , REGEXP_SUBSTR (' ";' |") Str | ';"'

    , '";" ((([^"]*"[^;]) *[^"])*)'

    1

    LEVEL

    NULL

    1

    ) AS sub_str

    OF got_str

    CONNECT BY LEVEL<= 1="" +="" regexp_count="" (="">

    , '";"'

    )

    ;

    Note that I added one; after 2011-12-30.

    Output:

    LEVEL SUB_STR

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

    1

    2 on 12-30-2011; 15:33:15

    3 116

    4

    5 1

    6 ANSWERED

    7 SIP/SDX20016-b6ec9c10

    8

    As always, the solution depends on your version.  It works in Oracle 11.2.

    Your message, it seems that you do this in PL/SQL.  The above query will work in PL/SQL, of course, but it might be simpler to use the code of procedure.  Parse the string from left to right, followed the quotation marks and semicolons.  If you find a semicolon, and the total number of quotes spent so far is the same, then you have found the beginning of a new secondary channel.

Maybe you are looking for

  • Why my iTunes uses a random filename as album art?

    Hello world I use iTunes (most recent) 12.4 and I wanted to add some radio stations online to a my new playlist of radio Stations of Radio Stations have worked so I waited until there was no work. Now my iTunes chose a random file (PDF) as the album

  • Upgrade Windows 8.1 on my W520

    Since the upgrade to windows 8.1, I have I had a problem where I couldn't run modern applications of Windows 8. Whenever I click on any of the applications, she looks like in his starts with the usual "flip 360 animation", and then immediately close.

  • Stop acquiring both

    Hello I have a data acquisition and control Rs-232 all in a while loop. The biggest problem is that it takes a while when I press on cancel or stop button to stop really. How can I configure this to the highest priority or as an interruption stop but

  • Compatible hard drives for the Presario 6350US with XP operating system

    Hi all.  Great support so far! Replaced the motherboard with a purchased on eBay, and it works very well. In my quest continues for speed and "new and improved", and because it is now 11 years old, I am looking to replace my old hard drive.  Any sugg

  • NEMA OUTDOOR FOR CISCO AP 3702

    Hello! One of my clients want to settle and NEMA (enclosure) for cisco AP 3702 OUTDOOR, but I can´t find the part number to order it! Can someone tell me if there is a reference number? I found http://www.terra-wave.com/cisco-3702e/http :// www.terra