Some of the columns to pivot lines

Hello

I need some columns to pivot lines and have the remaining columns in the result.

At this point, I have already made a subquery to gather data and to keep the running time down I prefer not to do it again as a UNION would require.

A row
CUST TEST_DATE TEST_TYPE1 TEST_TYPE2 TEST_TYPE3
1 20 MARCH 09 AA BB CC

Result rows
CUST TEST_DATE TEST_TYPE
1 AA 20 MARCH 09
1 BB 20 MARCH 09
1 BB 20 MARCH 09

Suggestions please?

Thanks in advance for your help,

Lou
with t as (
           select 1 cust,to_date('20-MAR-09','dd-mon-yy') test_date,'AA' test_type1,'BB' test_type2,'CC' test_type3 from dual
          )
select  cust,
        test_date,
        case lvl
          when 1 then test_type1
          when 3 then test_type2
          else test_type3
        end test_type
  from  t,
        (select level lvl from dual connect by level <= 3)
  order by cust,
           test_date,
           test_type
/

      CUST TEST_DATE TE
---------- --------- --
         1 20-MAR-09 AA
         1 20-MAR-09 BB
         1 20-MAR-09 CC

SQL> 

SY.

Tags: Database

Similar Questions

  • Sort sort the columns number of lines n columns in the RTF PivotTable but hide them.

    Hello

    I'm trying to sort on the columns number of sort for lines n columns in the PivotTable but hide them. Any help appreciated.

    Attached model RTF, XML and output required. Thank you

    Please check your email that I have forwarded to update the model.

    by default, it performs a sort on the column, we used to pivot rows and columns. If we need custom sort, we must specify that column in the logic that was present in the C form field.

    by default, you are as below

    Custom sort

    {INDUSTRY_sort, o = a, t = n} « ; » MONTHS {Month_sort, o = a, t = n} '; SALES '; "' sum '? >

  • Transform the data in the column marked in lines

    I've already implemented Tom Kytes solution for dynamic / variant in the list that is found here and on his own works very well when passing a variable.  I'm trying to use it to decode several rows in a table.  Each row has a column of delimited data and I want to turn these data delimited by lines.

    Here is the configuration.

    create table data_source

    (upload_id number not null,

    data_source_id integer not null,

    sources varchar2 (50).

    ERROR_MESSAGE varchar2 (100)

    );

    insert into data_source (upload_id, data_source_id, sources) values (1, 1, 'a');

    insert into data_source (upload_id, data_source_id, sources) values (1,2, 'A:B:C:X');

    insert into data_source (upload_id, data_source_id, sources) values (1, 3, 'c');

    insert into data_source (upload_id, data_source_id, sources) values (1, 4, 'B');

    insert into data_source (upload_id, data_source_id, sources) values (1.5, 'Y');

    create the table data_source_lookup

    (varchar2 (10) sources non-null)

    ;

    insert into data_source_lookup (sources) values('A');

    insert into data_source_lookup (sources) values('B');

    insert into data_source_lookup (sources) values('C');

    My goal is to update the table data_source for lines where there is an invalid data source, in the example above that would be 2 and 5 lines.  I can do this individually using the in_list solution:

    Select * from table (in_list ('A:B:C:X',' :'))))

    If column_value not in (select data_source_lookup sources)

    Returns 'X' as expected.

    What I am struggling with is a method to make it through all the lines for a given loading ID:

    Update data_source

    ERROR_MESSAGE = "Source of data" is not a valid value

    where upload_id = 1 and...

    I tried to create a join cross- like this:

    Select ds.data_source_id, ds.sources, x.column_value

    DS data_source cross join (select column_value in the table (in_list (ds.sources,' :'))) x)))

    but as you can imagine passing in the function ds.sources has failed, returning "ORA-00904:"DS".» "SOURCES": invalid identifier.

    I'm sure I can solve this problem in a loop, but that seems inefficient.  Anyone know of a method by which I can pass the content of the column to the table function (in_list ()) for each line?

    For someone else it may call a function table in several lines, here's what I came with.  First of all, I changed my data to test a bit to add some very incorrect values.

    setting a day from sources set data_source = 'A:B:C:X:Y' where data_source_id = 1;

    This query will not return a list of lines that contain invalid values, including their wrong value:

    Select the rowid, sources, column_value

    de)

    Select the rowid, data_source sources)

    x cross table junction (utils.in_list (x.sources,' :'))))

    where column_value is not null

    and not exists (select null from data_source_lookup l where l.sources = column_value)

    AABk3MAAjAAAKd8AAA A:B:C:X:Y X

    AABk3MAAjAAAKd8AAA A:B:C:X:Y Y

    AABk3MAAjAAAKd8AAB A:B:C:X X

    AABk3MAAjAAAKd8AAE Y Y

    With this work, I can then modify cela a little bit to turn it back in a delimited list bad values that I can put in the error column.

    Update data_source x 2

    ERROR_MESSAGE = value

    (by selecting bad_value in)

    Select RID, "Invalid Data Source - ' |" listagg(column_value,':') within the Group (column_value control) bad_value

    de)

    Select the rowid RID, data_source sources)

    x cross table junction (utils.in_list (x.sources,' :'))))

    where column_value is not null

    and not exists (select null from data_source_lookup l where l.sources = column_value)

    (Group of RID) where rid = x 2 .rowid)

    where x 2 .upload_id = 1

    and x2.rowid in (select RID)

    de)

    Select the rowid RID, data_source sources)

    x cross table junction (utils.in_list (x.sources,' :'))))

    where column_value is not null

    and not exists (select null from data_source_lookup l where l.sources = column_value))

    ;

    It works well, and I find myself with:

    Error sources

    Source of invalid data in A:B:C:X:Y - x: y

    Invalid Data Source - X A:B:C:X

    C

    B

    Valid source of data Y - Y

  • How to control the columns of various lines

    Dear members,

    I have a few lines displayed in the region of table edge on a Page of the OFA.

    The page has 3 columns, i.e., Col1, Col2 and Col3

    I also add a line on this chart button.

    When I opened the page, by default, it displays 4 rows. Now I don't want users to update these 4 rows. But users can insert new lines by clicking on the button Add a line.

    When users click on the button to add a line, I am able to create a new line, but how do I prevent users from updating the already displayed 4 lines.

    Please help me.

    Thanks in advance.

    Kind regards

    Hello

    Define a transitional attribute and name it freezes and set the default value for Y and when the query is executed in the query process, set the value as Y and make fields read-only if the value is there.

    Add which line touches, get the value of the current line and the value of gel on the current line as N. This way only the new lines added will be editable. On save, make the value of gel to Y for all records.

    I did the same thing, and it would solve your problem.

    Kind regards
    P.D. Moorthy

  • The creation of some of the columns.

    Hello

    I would like to create 3 columns in my part of SQL

    1 count of files to task_type = 'Reception' "assorted pallets.
    2 sum of elapsed_time if task_type = 'Reception' "time (Mins).
    3 account records to task_type = 'Réception' / sum of elapsed_time if task_type = 'Reception' X 60 'reception average (per hour).

    All the info I need is a table called inventory_transaction.

    Please could you show me how I should word my SQL when creating the separate as columns above muliptle.

    Thanks in advance.

    SM.

    The column Code that animates your aggregate function in the query is missing. Also, you should post the result you expect from the sample data provided.

    in any case, both Alex and Boneist have given you appropriate advice about the error you got. No point in repeating the same point again. ;)

    Good luck!!!

    Kind regards
    JO

  • view the column and gutter lines in a document

    CS3, I was displayed and lost due to the mistroke key lines? now I can't find them

    You probably pressed Cmd (or Ctrl on Windows) +; which is the shortcut to activate the guides on or off, or you can have changed in preview mode (with no text cursor active, press W). You can also access them from the view menu, and there is a button (or two buttons if your toolboz is two columns wide) at the bottom of the tool box to control the display.

  • can I create an index on the column of duplicate lines?

    Hello

    I tried to create a unique index on an existing table, containing the duplicate lines.

    I want to create an index of type everything on this column of duplicate rows.

    If possible pls suggest me.


    Kind regards
    Vincent.

    Yes.

  • Please tell us how to remove the 'message thread function' in the column 'Object' of my Inbox.

    Hello!
    For some reason, the column of the object on the Inbox of my e-mail account now has the topics of conversation. I have no idea how the son got there - and you would appreciate the help in eliminating these threads.
    Thanks a lot for your help.

    In the main menu bar:
    View (Alt - V) - sort by - Unthreaded

  • SQL help - Need help to rotate the columns to rows

    I have a HughesNet to divide the columns into multiple lines. For example:

    EMP_DEPT

    ROWID empid1 ename1 empid2 ename2 empid2 ename2 empid4 ename4 dept4 dep3 dep2 dept1
    100001 1 'SCOTT' 10 2 'DAVE' 20 3 10 4 20 SMITH "MILLER"
    100002 1 'SCOTT' 10 2 'DAVE' 20 3 'MILLER' 20

    Note: EMP_DEPT do not always have information about the 4 employees settled for example in info only 3 employees rank 2 are there

    I need to convert and insert it into the EMPLOYEE table as follows:

    EMPLOYEE

    EmpID ename dept
    1 SCOTT 10
    2 20 DAVE
    3 MILLER 10
    4 SMITH 20

    1 SCOTT 10
    2 20 DAVE
    3 MILLER 20

    Thank you
    KeV

    Hey Kevin,

    Here's one way:

    WITH t AS (
      SELECT level i FROM dual CONNECT BY level <= 4
    )
    SELECT enty_type, enty_name, enty_id
    FROM (
      SELECT case when mod(t.i,2) = 0 then 'DEPARTMENT'
                  else 'EMPLOYEE'
             end as enty_type
           , case t.i
               when 1 then emp_name1
               when 2 then dept_name1
               when 3 then emp_name2
               when 4 then dept_name2
             end as enty_name
           , case t.i
               when 1 then emp_id1
               when 2 then dept_id1
               when 3 then emp_id2
               when 4 then dept_id2
             end as enty_id
      FROM emp
           CROSS JOIN t
    )
    WHERE enty_id IS NOT NULL
    ;
    

    Another using the MODEL clause:

    SELECT *
    FROM (
      SELECT enty_id, enty_name, enty_type
      FROM emp
      MODEL
      RETURN UPDATED ROWS
      PARTITION BY (pk)
      DIMENSION BY (0 i)
      MEASURES(
         emp_id1, emp_name1
       , emp_id2, emp_name2
       , dept_id1, dept_name1
       , dept_id2, dept_name2
       , cast(null as number(10)) enty_id
       , cast(null as varchar2(200)) enty_name
       , cast(null as varchar2(30)) enty_type
      )
      RULES (
         enty_type[1] = 'EMPLOYEE' , enty_id[1] = emp_id1[0], enty_name[1] = emp_name1[0]
       , enty_type[2] = 'EMPLOYEE' , enty_id[2] = emp_id2[0], enty_name[2] = emp_name2[0]
       , enty_type[3] = 'DEPARTMENT' , enty_id[3] = dept_id1[0], enty_name[3] = dept_name1[0]
       , enty_type[4] = 'DEPARTMENT' , enty_id[4] = dept_id2[0], enty_name[4] = dept_name2[0]
      )
    )
    WHERE enty_id IS NOT NULL
    ;
    

    Published by: odie_63 on 8 Dec. 2010 21:00

  • How to download the columns selected in obiee

    Hi all

    Available in obiee which allows to download the selected columns of a report to an excel download all feature.

    Regarding
    Prads

    .. And if you don't, you go to the Page Options > change the dashboard, click on the properties of the report, and select report links...

    Oh, and anyway, you can download "selected columns"; you will need to download the entire report. If you insist on a report that includes only some of the columns, you can build column selectors where the user can select the columns they want to see in the report, and then when they select the "Download" link, the report will only have the columns...

    Visit this link:

    Re: How to add new columns by using the multiple selection

    Edited by: David_T on June 25, 2010 10:19

  • Loading external files in Oracle - error (double quotes on the columns)

    I managed to successfully load some external files (Excel) in my Oracle database, but when I questioned the table, I see that some of the columns have quotation marks on them. No idea how to fix this problem?

    OPTIONALLY ENCLOSED BY quotes in your syntax to remove.
    http://www.morganslibrary.org/reference/externaltab.html

  • Writing a query that may require a pivot but include [month, year] in the column and RiskGrades, no aggregate?

    Hello

    new to oracle/mark. I need to write a query that will pull the customer details and on the columns, it will have the month-year: Jan2015, Feb2015... Dec2015.

    on the lines, it will contain the details of the client. the information it will provide are the categories of risk to each month.

    I create a query, but it uses a function to update and is very slow. There are approximately 3000 documents. An update of column required 15 minutes or even more. so an update of column takes 15 minutes * 9 to update until September.

    the best ways to manage this demand?

    my query is:

    UPDATE tmpRiskGrades one

    SET a.feb2015 =)

    Select l.risk_grade

    of rep_loanportfolio l

    where a.agreementno = l.agreeement_no AND l.dtuserdatetime = February 28, 2015 ")

    Certainly, that looks like a pivot base for me.  Assuming that dtuserdatetime is actually a date data type, something like that will not work in your version of non-recognition:

    Select customer_no, agreeement_no, customer_address, loan_type region,

    Max (case when dtuserdatetime = to_date (Jan 31, 2015 "," DD month yyyy ' "))

    end of the era risk_grade) jan2015,.

    Max (case when dtuserdatetime = to_date (February 28, 2015 "," DD month yyyy ' "))

    then risk_grade end) Feb2015,

    ...

    of rep_loanportfolio l

    where loan_type = "HOME LOAN" and

    account_status = 'LIVE' and

    dtuserdatetime between to_date (Jan 31, 2015 "," DD month yyyy ' ") and

    TO_DATE (31 Dec 2015 "," DD month yyyy ' ")

    Group of customer_no, agreeement_no, customer_address, region loan_type

    order of region loan_type, customer_no, agreeement_no, customer_address

    If you are on 11.2 or higher, you could look at the PIVOT keyword, which is a more concise expression of the same thing.

    John

  • A statement UPDATE changes the line if the update changes the column even value?

    HI -.

    I have a main classification and the corresponding audit table. I have a trigger. I created using the suggestion:http://www.runningoracle.com/product_info.php?products_id=211

    Now the problem that I am facing is that: if I run the same query (same value) update on the main table for n times (with the same data)... my audit table is updated with a new record every time. He is not able to determine that the value is the same.

    My goal is to load the audit table data if the value in a cell in the main table is really have changed.

    A statement UPDATE changes the line if the update changes the column even value?

    Best regards

    I have a main Table and the corresponding Audit Table. I have a trigger. I created using the suggestion:http://www.runningoracle.com/product_info.php?products_id=211

    Why?

    You try to resolve what made you what are the PROBLEM that select as the solution?

    Now the problem that I am facing is that: if I run the same query (same value) update on the main table for n times (with the same data)... my audit table is updated with a new record every time.

    Yes - it is EXACTLY what you say that you wanted to do and EXACTLY what the code does in this article.

    He is not able to determine that the value is the same.

    I think you mean that the code does NOT check if the value is the same. You can certainly change the code to do this check. But I have a question to start with your need for such a solution.

    My goal is to load the audit table data if the value in a cell in the main table is really have changed.

    OK - then modify the code to check EACH COLUMN and compare its NEW value to the OLD value and insert only the table of audit if SOME (or columns you care specifically) have changed.

    A statement UPDATE changes the line if the update changes the column even value?

    It depends on what you mean by 'change the line '. Of course to update a column with the SAME value does not change the resulting data value.

    But the physical structure of the line, the location of the pieces of line and information in the header block (YVERT, etc.) will change. And, as others have said Oracle doesn't know and doesn't care, so if the new value of a column is the same as the old value will create redo, undo and the rest.

    Start over and tell us what PROBLEM you're trying to solve. Then we can help you find the best way to solve it.

  • break the values of columns in separate lines

    Hello

    I have a query that returns the values of 4 columns of it. Of this, a column can have many values it contains separated by semocolon (-). The requirement now is if this particular column has more than one value, separated by the semocolon (-), then the query must return each of them separately as a new line and keep the rest, column values as common for each of these values of this colummn.

    For example, select...

    output:
    col1 col2 col3
    Risk of BB IE6 71 of the PACK_PWRMART file. DELETE_POSITION_WO_RISK ($FEEDINSTANCEID); PACK_PWRMART. DELETE_INSTRU_REL_POS_WO_RISK; QC 8401

    COL4
    2010-02-11 09:29:45 December 28, 2010

    Now, col3 has 3 values separated by (;). Therefore, the output of the query
    col1          col2                           col3( now split with 3 values)                                                          col4
    71     BB IE6 risk file     PACK_PWRMART.DELETE_POSITION_WO_RISK($FEEDINSTANCEID)        2/11/2010 9:29:45 AM 28-Dec-2010     
    72     BB IE6 risk file     PACK_PWRMART.DELETE_INSTRU_REL_POS_WO_RISK            2/11/2010 9:29:45 AM 28-Dec-2010     
    73             BB IE6 risk file             QC 8401                                                                                       2/11/2010 9:29:45 AM 28-Dec-2010
    The solution that I thought:

    I don't know if this can be achieved in a single SQL statement, so I thought I should write a block of code that will use the collection separate each of the value of this column and use some sort of record of object to insert the entire line in it 3 times (or the number of times as much as the values in this column) , but without success.

    Something like this:
    declare
    type feed_name is table of varchar2(4000);--feed_static.feed_description% type INDEX BY PLS_INTEGER;
    feed_nm feed_name;
    param_val feed_name;
    dat feed_name;
    feed_desc feed_name;
    str number;
    str1 varchar2(1000);
    begin
    select feed_description as "Feed Name" ,
           param_value as "Post_Proc Prarameter",
           '28-Dec-2010' as "COB date",
           ft.feed_type_description as "Feed Type"    
    BULK COLLECT INTO feed_nm,param_val,dat,feed_desc
    from feed_static fs, feed_parameter fp, feed_type ft 
    where fs.feed_id =fp.feed_id
    and fs.feed_type_id = ft.feed_type_id
    and fs.feed_type_id not in (4,15,16,25)
    and fp.param_name  = 'postproc'
    and fp.close_action_id is null
    and fs.feed_description in ('BB 0J0 risk file')--,'BB 1J1 risk file')
    order by  fs.feed_type_id,feed_description;
    FOR i IN 1..param_val.count
    loop
        select length((param_val(i))) - length(replace(param_val(i),';')) into str from dual;
               dbms_output.put_line(str); 
               for j in 1..str
                   loop
                        SELECT SUBSTR(param_val(i), 1 ,INSTR(param_val(i), ';', 1, j)-1) into str1 FROM dual;
                        dbms_output.put_line(str1); 
                        str1:=' ';
                   end loop;
    end loop;    
    end;
    But the "dbms_output.put_line (str1); does not give me o/p as required except the first value (assume thr are the 3 values of the column).
    Also I'm not sure of what I'm trying to do is in the right direction or not.

    I have not used any RECORDING still to poulate values separated again (I'm not sure about hoe to use)

    Cam anyone help me please with this code.

    Rgds,
    Aashish

    Try this:

    select feed_description as "Feed Name" ,
           param_value as "Post_Proc Prarameter",
           '28-Dec-2010' as "COB date",
           --ft.feed_type_description as "Feed Type" ,
           regexp_substr( ft.feed_type_description,'[^;]+',1,rown.seq)
    from feed_static fs, feed_parameter fp, feed_type ft, (SELECT LEVEL seq FROM DUAL
                        CONNECT BY LEVEL<=max(length(ft.feed_type_description)- length(replace(ft.feed_type_description,';'))))rown
    where fs.feed_id =fp.feed_id
    and fs.feed_type_id = ft.feed_type_id
    and fs.feed_type_id not in (4,15,16,25)
    and fp.param_name  = 'postproc'
    AND rown.seq<=(length(ft.feed_type_description)- length(replace(ft.feed_type_description,';')))
    and fp.close_action_id is null
    and fs.feed_description in ('BB 0J0 risk file')--,'BB 1J1 risk file')
    order by  fs.feed_type_id,feed_description;
    

    regexp_count started in 11g. It counts the number of models in a particular string. I replaced by length - length (repalce).
    You can replace the word 'max (length (ft.feed_type_description) - length (replace(ft.feed_type_description,';'))))' with 10 or 15, i.e. the maximum number of semicolons in the chain

  • How to convert the column lines

    I need to convert my output lines of sql for the column as a pivot to 11g

    Please give me the example of this

    check out this link

    http://nimishgarg.blogspot.com/2010/06/Oracle-pivot-data-rows-to-columns.html

    request for 10g would be

    Select *.
    (select job,
    Sum (decode(DEPTNO,10,SAL)) dept10,
    Sum (decode(DEPTNO,20,SAL)) dept20,
    Sum (decode(DEPTNO,30,SAL)) dept30,
    Sum (decode(DEPTNO,40,SAL)) dept40
    from scott.emp
    Working Group)
    order by 1;

Maybe you are looking for