SQL query, generate several lines in a value in a field

I use the Oracle database. Imaging I have a table with a row as follows

col1 |  col2. COL3

"Str1" | "Str2". 4

The value of col3 = 4 is expected to generate 4 rows as follows:

col1 |  col2. COL3

"Str1" | "Str2". 1

"Str1" | "Str2". 2

"Str1" | "Str2". 3

"Str1" | "Str2". 4

After several hours in front of the screen and stil no chance - how do I create such a select query?

It will work

Select * from test_table:

COL1 COL2 COL3

str1 str2 2

strA, strb 4

STRX deltas 8

WITH t(col1,col2,col3) AS
        (
        select col1,col2,col3 from test_table
         union all
         select col1,col2,col3-1 from t where col3>1)
SELECT *
  FROM t
  order by col1,col3;

OUTPUT:

COL1 COL2 COL3

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

str1 str2 1

str1 str2 2

strB Stra 1

strA, strb 2

strA, strb 3

strA, strb 4

deltas STRX 1

STRX deltas 2

deltas STRX 3

STRX deltas 4

STRX deltas 5

STRX deltas 6

STRX deltas 7

STRX deltas 8

See you soon,.

Manik.

Tags: Database

Similar Questions

  • How to find the sql query generated by BI Publisher

    I'm looking for the physical sql query generated by BEEP when I send parameters as part of the data model.

    Of course, this can be noted in newspapers...

    Can anyone tell me the location of newspapers?

    Thanks in advance

    Have a look here http://gerardnico.com/wiki/dat/bip/log
    I explain a bit how you can get the newspaper.

    See you soon
    Nico

  • SQL query generated by insertion/update of data vi?

    Hello!

    I'm new to LabView, now rated as my company's management plans to buy licenses for several developers. I'm now playing with the database connectivity toolkit and try to insert/updated updated data sets. Everything is good with simple tables, but when I try to execute relatively complex queries are often mistakes LabView diagnosed everything as "syntax error in Update statement" or something like that with no specific details.

    Is it possible to read the actual SQL queries generated by these vi or is there a (preferably free) tool to monitor all SQL queries called by my LabView program?

    Here is the link I promised last night. It includes a review of the issues with the CSD and why it is not necessary. There is also a link with some drivers that allow you to do what you need to do and are free - and a brief tutorial on the access to databases.

    Mike...

  • Updated several lines with different values

    Hello!
    I have a problem. I need to update more than 1000 lines with different values. How can I do?
    For exsample I have table:
    ID; color, date,
    1 red
    2 green
    3 white

    I need to update the date field.

    Update table
    Set date = '01.02.03'
    where id = 1

    Update table
    Set date = '01.03.03'
    where id = 2


    Maybe it's how to update multiple rows in a single request?

    Sorry for my bad English.
    Thank you!

    Hello

    You can try this

    UPDATE TABLE SET DATE = CASE
                        WHEN ID = 1 THEN TO_DATE('01-02-03','DD-MM-RR')
                        WHEN ID = 2 THEN TO_DATE('01-03-03','DD-MM-RR')
                        END
    

    see you soon

    VT

  • Question: Is it possible to query a record datacard on the value of the field (REST API)?

    Hi everyone :-)

    URL: / data/Objetpersonnalise / {id}? count = {number} & page = {page} &Search = {}, & orderBy = {orderBy} & lastUpdatedAt = {lastUpdatedAt}

    Can we get a result based on a search query on the value of the field?

    Thank you!

    ADI

    Hello Adi,

    You should be able to query the value of a CDO field via the name of the database field.

    Example: CDO field "City" is the name of the city of '1 '.

    Your query: / data/Objetpersonnalise / {id}? Search = Ville1 = Berlin

  • Grouping query gives several lines

    friends...

    can someone check this query and tell me where I am wrong... I have to get a single line for each record... but I'm getting mutiple lines... in fact... I wrote this application in vb6 to ms access, but if you give a solution in oracle, I can change to ms access sql.
    "select [stdentry.sno],[stdentry.branch],[stdentry.stdname],[stdentry.amtobepaid]," _
    & "iif([feesdetail.paytype]='DD',sum([feesdetail.paidamt]),0) as totpaid," _
    & "iif([feesdetail.paytype]='CASH',sum([feesdetail.paidamt]),0) as totpaid1 " _
    & "from stdentry,feesdetail where " _
    & "([feesdetail.delstat]='N') and [stdentry.sno]=[feesdetail.sno] and [stdentry.refundstat]='N' " _
    & "group by [stdentry.sno],[stdentry.branch],[stdentry.stdname],[stdentry.amtobepaid],[feesdetail.paytype]"
    Thanks and waiting with someone.

    This is an ORACLE SQL and PL/SQL forum... Better, you ask your question in an appropriate forum...

    You can check this too

    "select [stdentry.sno],[stdentry.branch],[stdentry.stdname],[stdentry.amtobepaid]," _
    & "sum(iif([feesdetail.paytype]='DD',[feesdetail.paidamt],0)) as totpaid," _
    & "sum(iif([feesdetail.paytype]='CASH',[feesdetail.paidamt],0)) as totpaid1 " _
    & "from stdentry,feesdetail where " _
    & "([feesdetail.delstat]='N') and [stdentry.sno]=[feesdetail.sno] and [stdentry.refundstat]='N' " _
    & "group by [stdentry.sno],[stdentry.branch],[stdentry.stdname],[stdentry.amtobepaid]"
    
  • generate several lines of each row in a table

    Hi all, consider the following data
    with data1 as
    (
      select 1 id, 0 cust_sh, null mx_sh, 123 cust_coll from dual union all
      select 2 id,0 cust_sh, 0 mx_sh, 0 cust_coll from dual union all
      select 3 id,456 cust_sh, 890 mx_sh, 123 cust_coll from dual 
    ),
    data2 as
    (
      select 'cust_sh' col_nm, 'ABC' nm from dual union all
      select 'mx_sh' col_nm, 'BDC' nm from dual union all
      select 'cust_coll' col_nm, 'HGR' nm from dual 
    )
    what I'm trying to do here is to join the two tables sort and produce this output
    id  nm         amt
    =====================
    1   HGR        123
    3   ABC        456
    3   BDC        890
    3   HGR        123
    That's how I get this result. Data1 has lines with the ID and the columns with quantities such as cust_sh, etc.
    data2 bearing the name of the column in data1 under col_nm and an additional column as nm.

    for each line of Data1, I should take the amount column, look in database2 and the data1 amount is greater than 0.
    then display the output.

    for example, to get data1 row1. cust_sh is set to 0, so we don't look this column in Database2. mx_sh is set to null, which is not greater than 0, then us none.
    cust_coll has the value 123 so we wait for this column in Database2. This is the third row in Database2. Therefore, view us the id and the amt of Data1 and data2 nm.

    for line two of Data1, all after id columns are 0. don't have no need to display the output. only when the amount is greater than zero, we watch in Database2.

    third row, cust sh has value 456 so we expect in database2 and we found in the first row. mx_sh has a value of 890 (greater than 0) so again once we look at Database2 and display the output.

    can someone help me with a query that produces the output above?

    Thanks in advance

    OK, two more options:

    WITH pivot_data1 AS (
      SELECT id, 'cust_sh' as col_nm, cust_sh as amt
      FROM data1
      WHERE cust_sh > 0
      UNION ALL
      SELECT id, 'mx_sh', mx_sh
      FROM data1
      WHERE mx_sh > 0
      UNION ALL
      SELECT id, 'cust_coll', cust_coll
      FROM data1
      WHERE cust_coll > 0
    )
    SELECT d1.id
         , d2.nm
         , d1.amt
    FROM pivot_data1 d1
         JOIN data2 d2 ON d2.col_nm = d1.col_nm
    ;
    
    WITH pivot_data1 AS (
      SELECT id
           , case i when 1 then 'cust_sh'
                    when 2 then 'mx_sh'
                    when 3 then 'cust_coll'
             end as col_nm
           , case i when 1 then cust_sh
                    when 2 then mx_sh
                    when 3 then cust_coll
             end as amt
      FROM data1
           CROSS JOIN ( SELECT level i FROM dual CONNECT BY level <= 3 )
    )
    SELECT d1.id
         , d2.nm
         , d1.amt
    FROM pivot_data1 d1
         JOIN data2 d2 ON d2.col_nm = d1.col_nm
    WHERE d1.amt > 0
    ;
    
  • How to generate several lines from a single line

    Hi, using Oracle 11 g R2.

    Looking for a way to display the result of a query where a column value is a text similar to the following field. There is only 1 row.

    create table testlist (col1 varchar2 (50))

    insert into testlist values (' ' 845, 999, ABC ")

    The values are always separated by commas. Looking for display the result as follows

    845

    999

    ABC

    Hello

    Since you have only 1 row in the table, you can do this:

    SELECT REGEXP_SUBSTR (col1

    , '[^,]+'

    1

    LEVEL

    ), Element

    OF testlist

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

    , '[^,]+'

    )

    ;

    Output:

    AGENDA

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

    845

    999

    ABC

  • Dynamic SQL query returning (problem with list of value)

    Hi, I have problems with my request. I want to do where statement based on my selectlist, but the problem is that I could not write the correct string in my where condition.

    : P61_STATUS has this following display, return value

    Bewerber Bewerber
    PRA_Kandidat PRA_Kandidat
    abgelehnt abgelehnt
    angenommen angenommen
    Thema-Thema
    join online
    Staaten Staaten
    Sky sky
    our our
    DECLARE
      q varchar2(4000);
      list_betreuer htmldb_application_global.vc_arr2;
      list_semester htmldb_application_global.vc_arr2;
      list_status htmldb_application_global.vc_arr2;
    
    BEGIN
    
     -- variable to store the list
     list_betreuer := HTMLDB_UTIL.STRING_TO_TABLE(:P61_BETREUER);
     list_semester := HTMLDB_UTIL.STRING_TO_TABLE(:P61_SEMESTER);
     list_status := HTMLDB_UTIL.STRING_TO_TABLE(:P61_STATUS);
    
     -- Query begins
     q:= 'select p1.name, p1.vorname , a1.tel, a2.tel, '; 
     q:= q||'ab.thema, ab.status, ab.typ, s.bezeichnung, p2.name ';
     
     q:= q||'from person p1, person p2, adresse a1, adresse a2, ';
     q:= q||'zuordnungp_a zpa1,zuordnungp_a zpa2, ';
     q:= q||'abschlussarbeit ab, semester s ';
    
     q:= q||'WHERE ab.SEMESTER = s.OBJECTID (+) ';
     q:= q||'AND ab.STUDENT = p1.OBJECTID (+) ';
     q:= q||'AND ab.BETREUER = p2.OBJECTID (+) ';
    
     q:= q||'and p1.objectid = zpa1.person (+) ';
     q:= q||'and zpa1.adresse  = a1.objectid (+) ';
     q:= q||'and zpa1.art (+)= ''Privat'' ';
    
     q:= q||'and p1.objectid = zpa2.person (+) ';
     q:= q||'and zpa2.adresse  = a2.objectid (+) ';
     q:= q||'and zpa2.art (+)= ''Geschäft'' ';
    
    
     -- Loop for betreuer list
     FOR i in 1..list_betreuer.count
     LOOP
        IF i = 1 THEN
        q:= q||'AND (ab.betreuer = '||list_betreuer(i);
        ELSE
        q:= q||' OR ab.betreuer  = '||list_betreuer(i);
        END IF;
     END LOOP; if (list_betreuer.count>0)THEN q:= q||')'; END IF;
    
      -- Loop for semester list
     FOR i in 1..list_semester.count
     LOOP
        IF i = 1 THEN
        q:= q||'AND (ab.semester = '||list_semester(i);
        ELSE
        q:= q||'OR ab.semester = '||list_semester(i);
        END IF;
     END LOOP; if (list_semester.count>0)THEN q:= q||')'; END IF;
     
     -- Loop for status list
     FOR i in 1..list_status.count
     LOOP
        IF i = 1 THEN
        q:= q||'AND (ab.status = '||list_status(i)||'';
        ELSE
        q:= q||'OR ab.status = '||list_status(i)||'';
        END IF;
     END LOOP; if (list_status.count>0)THEN q:= q||')'; END IF;
     
      htp.p(q);
     return q;
     
    END;
    result
    select p1.name, p1.vorname , a1.tel, a2.tel, ab.thema, ab.status, ab.typ, s.bezeichnung, p2.name from person p1, person p2, adresse a1, adresse a2, zuordnungp_a zpa1,zuordnungp_a zpa2, abschlussarbeit ab, semester s WHERE ab.SEMESTER = s.OBJECTID (+) AND ab.STUDENT = p1.OBJECTID (+) AND ab.BETREUER = p2.OBJECTID (+) and p1.objectid = zpa1.person (+) and zpa1.adresse = a1.objectid (+) and zpa1.art (+)= 'Privat' and p1.objectid = zpa2.person (+) and zpa2.adresse = a2.objectid (+) and zpa2.art (+)= 'Geschäft' AND (ab.status = abgegeben) 
    the problem is in this summary
    q:= q||'AND (ab.status = '||list_status(i)||'';
    This statement produce this following statement
    ab.status = abgegeben
    But what I need, is this statement
    ab.status = 'abgegeben';
    How can I get this statement?

    Thank you very much

    To use double quotes:

    q:= q||'AND (ab.status = '''||list_status(i)||'''';
    
  • Popup2 in SQL don't Report not to the values of the fields in table

    Hi all

    Can someone help me with this instruction box in the pop-up window 2.

    Instead of the values behind the transmitted fields the literal text of 'A.Metric' & 'A.Month' are being passed in the new page instead.

    A.Metric has a value of 10 and A.Month has the value of 1 May 2008.
    ----------------------------------------------------------------------------------------------------------------------
    WHEN PARSING IS NOT NULL THEN
    "< a href ="javascript:popUp2(''e) "
    || ' f ? p = & APP_ID.:305: & SESSION. : & DEBUG. ::'
    || "P305_METRIC_TYPE, P305_METRIC_MONTH:A.METRIC_TYPE, A.MONTH.
    || (', 890, 460); style = "text-decoration: underline;" color: black; do-size: 90% ">"
    || "< img src =" #APP_IMAGES #notes.jpg ">"
    || "< /a >" END "analysis."
    ----------------------------------------------------------------------------------------------------------------------

    Frank

    Well, first of all try with | «, » || So tell me if you have the error, please do - send your entire query (also remove the quotes of the alias of the analysis of the column - they are not mandatory).

    Ben

  • Query generates duplicate values in successive lines. I can null out them?

    I have had very good success (thanks to Andy) to obtain detailed responses to my questions posted, and I wonder if there is a way in a region report join query that produces lines with duplicate values, I cannot suppress (replace) printing of duplicate values in successive lines. In the event that I managed to turn the question into a mess unintelligible (one of my specialities), let me give an example:

    We try institutions undergraduate that an applicant has participated in the list and display information on release dates, gpa and major (s) / according to decision-making. The problem is that there may be several major (s) / minor (s) for a given undergraduate institution, so the following is produced by the query:

    Knox College hard 01/02 01/06 4,00 knitting
    Knox College hard 01/02 01/06 4,00 cloth repair
    Advanced University 02/06 01/08 3.75 Clothing Design
    Really advanced U 02/08 01/09 4,00 sportswear
    Really advanced U 02/08 01/09 4,00 basketball burlap

    I want it to look like this:

    Knox College hard 01/02 01/06 4,00 knitting
    Tissue repair
    Advanced University 02/06 01/08 3.75 Clothing Design
    Really advanced U 02/08 01/09 4,00 sportswear
    Burlap tennis shoe

    * (Edit) Please note that the repair of fabric and lines tennis shoe repair should be positioned properly in a table, but unfortunately had space here for a reason suppresed any. *

    Under the tuteage of Andy, I would say the answer is probably javascript one loop in the DOM, you are looking for the innerHTML of specific TDs in the table, but I want to confirm that, or Apex provides it a box I can check which will produce the same results? Thanks to the guy to advance and sorry for all the questions. We were charged to use Apex for our next project and learn it using it, as the training budget is non-existent this year. I love ;) unfunded mandates

    Phil

    Published by: Phil McDermott on August 13, 2009 09:34

    Hi Phil,

    JavaScript is useful, because the feature break column in the report attributes (which would be my first choice if poss).

    If you need to go beyond 3 columns, I would say something in the SQL statement itself. This means that the sort would probably have to be controlled, but it is doable.

    This is a pretty old thread on the subject: Re: grouping reports (non-interactive) -with an example here: [http://htmldb.oracle.com/pls/otn/f?p=33642:112] (I used a custom template for the report, but you don't need to go that far!)

    This uses the features of LAG in SQL to compare the values on line for values on the line before - ability to compare these values allows you to determine which ones to show or hide.

    Andy

  • A map of OWB (service line) SQL query

    If I trace a session, run a map OWB (base line), the trace file contains the actual SQL query?

    The problem with me is that when I execute this rank - based OWB card, is throw me an error CursorFetchMapTerminationRTV20007, BUT (most time consuming) when I take on the intermediate SQL insert query, it works very well (and also in a very short time)

    The executing State = COMPLETE

    message = text ORA-06502: PL/SQL: digital or value error: character string buffer too small

    CursorFetchMapTerminationRTV20007 = message text

    N ° of task errors = 0

    N ° task warnings = 2

    N ° errors = 1

    Since this card OWB (truncate insert) is the line in function of where I can't back-end of the generated pl/sql package request OWB so I was wondering if I trace the session, check the trace file, maybe I'll able to see the exact SQL query generated. But I wanted to confirm the same.

    Yes, the real run SQL in session will be in the trace file.

  • Eliminate the duplicate based on the condtion in Select of SQL query.

    Hi all

    I write the SQL query where I have to select values based on the condition in the column.

    Lets say I have 3 columns position, description, used, there are different values in the position but for some positions of the column description of the lines is the same and if column Description is the same and employee is null then that there should be only one row returned and if the description is the same but the employee column is not null then it should be several lines.

    I can't use Group by that we have around 35 columns in the select query.

    Please suggest any Solution.

    Hi Michael,

    I adds a column to the t2 to get the good understanding of my needs.

    Level
    Employee From Date to_date
    1 Test2 21.03.2014 21.04.2014
    2 Test4 21.02.2014 20.03.2014
    2 Test1 21.03.2014 21.04.2014
    2 Test3 21.04.2014
    3 MgrTest 21.03.2014

    Now, the result should look like this.

    Level
    Employee From Date TO Date
    1 Test2 21.03.2014 21.04.2014
    2 Test3 21.04.2014
    2 Test1 21.03.2014 21.04.2014
    3 Mgrtes 21.03.2014
    4

    There was an addition more as if this day is not null for the given level, then the query must return a single line of balnk more with the same position, I am reached using any Union and works very well I'm stuck with the point above.

  • Help in the Search Condition in the SQL query

    Hi gurus,

    I had the table with 3 columns
    col1           col2             col3
    123        johns123     edwin321s
    seenu       janu      satya123reset
    3456       kris         123stest
    
    In single SQL query i want to print the value based on the '123' is  
    
    123,john123,
    satya123reset,
    123test
    
    or to print the records starts with 's' like 
    s123
    seenu,satya123reset
    stest
    Thanks in advance

    Published by: SeenuGuddu on October 15, 2009 21:55

    Published by: SeenuGuddu on October 15, 2009 21:55

    Published by: SeenuGuddu on October 15, 2009 22:07

    Hello

    Not sure you mean exactly, but maybe you could do something like:

    MHO%xe> with t as ( -- generating your sample data:
      2  select '123' col1, 'johns123' col2, 'edwin321s' col3 from dual union all
      3  select 'seenu', 'janu', 'satya123reset' from dual union all
      4  select '3456', 'kris', '123stest' from dual
      5  )
      6  --
      7  -- actual query:
      8  --
      9  select rtrim ( case when col1 like '%123%' or col1 like 's%' then col1||', '  end
     10         ||      case when col2 like '%123%' or col2 like 's%' then col2||', '  end
     11         ||      case when col3 like '%123%' or col3 like 's%' then col3||', '  end
     12         , ', ')
     13  from   t;
    
    RTRIM(CASEWHENCOL1LIKE'%123%'ORC
    --------------------------------
    123, johns123
    seenu, satya123reset
    123stest
    

    You mention:

    or print the records begins by a ' as

    However the output desired is not begin with s for 's123' and "stest"... you can adjust your specification or your output...

  • Generate the Trace file to a sql query

    Hi all

    I want to generate a trace for a sql query file so that I can generate a .out file corresponding I need to check the performance of an application before using it.
    Anyone can guide me please how to do this.
    I know how do to generate a trace for a concurrent program, but right now, I want to track for a simple sql query.

    Kind regards
    Ankur

    Hello
    Agreed. but I thought that if OP do not have access to metalink then?

    In any case I not substitute me your answer.

    Oops. Sorry I did not read the lines below.

    You can turn simple trace for this particular session.
    Oracle will generate trace files (.trc) for each session where the value of SQL_TRACE = TRUE and write them to the USER_DUMP_DEST destination. That you can use tkprof to read the generated trace file.

    Kind regards
    Taj

    Published by: Mohammed Taj on July 14, 2009 10:11

Maybe you are looking for

  • 31.1.1 Thunderbird download dictionaries. I'm going crazy... Help me please clarify again!

    It's driving me crazy... Over the years, I had many versions of Thunderbird and I know how go to Options... Composition... Spelling... Download dictionaries... etc, but after that I have chosen a dictionary and go in the big blue 'Download Now' butto

  • Equium A200-15i: cannot see wireless network adapter

    Hi all. I tried to install the drivers on my laptop wireless without a bit of luck.My network card works, and I can connect to the internet via ethernet. But wireless doesn't work at all. I checked under network adapters and Device Manager, it shows

  • CSV files

    How are Hello everyone, you? I'm working on a software to make measurements using my drone of railroad. My drone generate csv files (such as it is attached). The first column corresponds to the distance that generate the encoder, the second colum is

  • Windows Defender won't turn on.

    I don't know what happened, but my Windows Defender just turn off by itself. I can't activate it. The Windows Security Center always give me the same answer. I'm really frustrated here. Please help me!

  • The Windows 7 XP Mode will not be loaded an XP application

    Successfully, I downloaded & installed XP on my new laptop mode of Toshiba. I made a file transfer & my old Toshiba settings to my new but only some of the files transferred. Now, I'm trying to install xp in XP Mode, but when I try to get the program