How to get the result of a single line in several columns

I have a scenario where I asked five different columns in a table and it would still look back one line.

So, for example: the query would be
 Select user1, user2, user3, user4 from table1 where tblkey= 2 
So, this would mean 1 row with the value of their respective areas.

In my code, I have a common function I can call to send an email to the list of people (User1, User2, user3, user4).

So rather than call this function each time for each user, is there a way I can display the output to 4 different rows and use the loop For to call this function only once.

In this way, the loop For running 4 times (if not nulls for all users) and call this function of e-mail.

Really, I'd appreciate if someone could give me an idea of this scenario.

Thank you
AR

If the number of columns is fixed you may be able to use this:

SELECT  DECODE
        (
                RN
        ,       1,USER1
        ,       2,USER2
        ,       3,USER3
        ,       4,USER4
        )       AS USERS
FROM    TABLE1
CROSS JOIN (SELECT ROWNUM RN FROM DUAL CONNECT BY ROWNUM <= 4)
WHERE   TBLKEY = 2

This UN-pivot results.

Here's an example of it in action:

SQL> CREATE TABLE TABLE1
  2  (
  3          TBLKEY  NUMBER
  4  ,       USER1   VARCHAR2(1)
  5  ,       USER2   VARCHAR2(1)
  6  ,       USER3   VARCHAR2(1)
  7  ,       USER4   VARCHAR2(1)
  8  );

Table created.

SQL> INSERT INTO TABLE1
  2  SELECT  ROWNUM
  3  ,       SUBSTR(OBJECT_NAME,1,1)
  4  ,       SUBSTR(OBJECT_NAME,2,1)
  5  ,       SUBSTR(OBJECT_NAME,3,1)
  6  ,       SUBSTR(OBJECT_NAME,4,1)
  7  FROM    ALL_OBJECTS
  8  WHERE ROWNUM <= 10;

10 rows created.

SQL> SELECT * FROM TABLE1 WHERE TBLKEY = 2;

              TBLKEY USER1      USER2      USER3      USER4
-------------------- ---------- ---------- ---------- ----------
                   2 I          _          U          S

SQL> SELECT  DECODE
  2          (
  3                  RN
  4          ,       1,USER1
  5          ,       2,USER2
  6          ,       3,USER3
  7          ,       4,USER4
  8          )       AS USERS
  9  FROM    TABLE1
 10  CROSS JOIN (SELECT ROWNUM RN FROM DUAL CONNECT BY ROWNUM <= 4)
 11  WHERE   TBLKEY = 2
 12  /

USERS
-------------------------
I
_
U
S

HTH!

Published by: Centinul on February 24, 2010 11:21

Tags: Database

Similar Questions

  • How to get the values in a single line, without the help of the union

    Hello

    I have a table with the structure and the following data

    EmpID address phoneno emailid
    1001 xyz
    1001 1234234
    1001 [email protected]
    1002 23434
    1002 [email protected]
    1003 abcd
    1003 [email protected]
    1004 [email protected]



    I need to get a result in this format.


    EMP id address phoneno emailid
    1001 xyz 1234234 [email protected]
    1002 23434 [email protected]
    1003 abcd [email protected]
    1004 [email protected]


    I can do this by using the union, but who gives a performance of questions with a large table. I want to do it using any other way using lead or something, but with the relative to data complexity, I couldn't do it.

    Can someone help me please?


    Natarajan

    Published by: Nikita on December 3, 2009 15:50
    Select employee_id, max(address), max(phone), max(email)
    from emp
    group by employee_id;
    

    Max

  • How to get the value of a particular tag to a column (clob)

    Hi friends,

    How to get the value of a particular tag to a column (clob), which has an XML value?

    Thanks in advance.

    Kind regards
    Sirot Chauvet

    You are welcome, if you got your answer to the question as such brand

  • How to get the result of the query?

    I'm looking to get output something like this...

    If a profile exists on the Pb, I need Exists in the colum

    PROFILE_A EXISTS

    PROFILE_B DOES NOT EXIST

    PROFILE_C EXISTS

    Select distinct profile

    decode (profile, "PASSWORD_PROFILE", "EXISTS", 'THERE is NO') 'STATUS '.

    of dba_profiles;

    How to get the above result? Anyone?

    In the first query, you can add any profile you want to check, and then try the below

    WITH qry1 AS (SELECT profile 'PROFILE_A' FROM dual

    UNION ALL

    SELECT "PROFILE_B" FROM double

    UNION ALL

    SELECT 'DEFAULT' double)

    SELECT the profile

    CASE WHEN EXISTS (SELECT 1 FROM dba_profiles dp

    WHERE dp.profile = q1.profile)

    THEN "EXISTS."

    OTHERWISE "NOT EXIST".

    The END as status

    OF qry1 q1;

    OUTPUT:-

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

    SQL > WITH qry1 AS (SELECT profile 'PROFILE_A' FROM dual

    2. ANY TRADE UNION

    3. SELECT 'PROFILE_B' FROM dual

    4 UNION ALL

    5. SELECT 'DEFAULT' double)

    6. SELECT profile,

    7 CASE WHEN EXISTS (SELECT 1 FROM dba_profiles dp

    8 WHERE dp.profile = q1.profile)

    9 THEN 'EXISTS '.

    10. OTHERWISE "NOT EXIST".

    11 FINISSENT AS status

    Qry1 q1 12;

    PROFILE STATUS

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

    PROFILE_A DOES NOT EXIST

    PROFILE_B DOES NOT EXIST

    DEFAULT VALUE IS

  • How to get the results of the UK instead of the default USA?

    I live in the United Kingdom and would like to be able to search for UK results. for example, Amazon UK results when I search a product, etc.
    with the option of a search in the world so I don't get the results I want

    To add plugins to search for sites such as Amazon.co.UK and Google.co.uk to Firefox, open this page in Firefox and then search or click the sites that interest you: http://mycroft.mozdev.org/

    When you click on one of the listed search plugins, Firefox will ask you if you want to install it.

    After that, you can open the Firefox Add-ons Manager and click on disable one of the search engine integrated you want to use.

  • How to get the result of the test of CVI DLLs in teststand!

    I write a driver dll to test a source, I want to get the tension of world SERVERS (the instrument of the RS) and I used to call DLLs that written by CVI, teststand

    My question is what is the best way I can get the result of the test and show the user to teststand. the code below is fair? When I used to call this dll document, teststand

    "" I just get the result by setting in TS.this is a good meathod, and what should you do in teststand, I put the "outputVoltageV" point to an object?

    /*===========================================================================*/
    / * Function: read voltage/current output * /.
    / * End: this function returns the output and actual output voltage * /.
    / * current instrument.                                      */
    /*===========================================================================*/
    ViStatus _VI_FUNC rsngsm_datReadOutput (ViSession instrSession,
    ViPReal64 outputVoltageV, ViPReal64 outputCurrentA, ViPBoolean statusPeakCurrent)
    {
    ViStatus rsngsm_status = VI_SUCCESS;
    Bruno buf [BUFFER_SIZE];
    ViInt32 retCnt;
       
    FMT (buf, "%s<>
    If ((rsngsm_status = viWrite (instrSession, buf, NumFmtdBytes (), & retCnt))<>
    Return rsngsm_status;
           
    If ((rsngsm_status = viRead (instrSession, buf, 50, & retCnt))<>
    Return rsngsm_status;
    If (Scan (buf, "%s > %f [p2];")) %f [p2]; %i [b2] ", outputVoltageV, outputCurrentA, statusPeakCurrent). = 3)
    Return rsngsm_status;
           
    Return rsngsm_status;
    }

    sean_tan,

    Yes, you just pass a value of digital TestStand (e.g.; locals.number).

    If you use the adapter of the ICB, it might make more sense that you can use the Flexible DLL adapter for this type of function, that you do not use the standard settings of tTestData and tTestError. While TestStand will correctly recognize the function prototype, you want to make sure you that include the type library of your function Panel (you will need to create one if you have not already done so) in settings target of LabWindows / CVI-> type library.

    I hope this helps.

    -Jack

  • How to display the results of a MySql query in multiple columns?

    Hi, I know how to display PHP/MySq

    l of the results in a single column, but I'm really stuck to show

    Ying the results of several columns in DW CS4.

    Can someone help me with a code example? I'm new to php/mysql. Thank you

    Are you asking how to rotate the query results? Do a search for a horizontal loop. If this isn't what you're asking, please provide more details.

  • How to get the 6th element of a C.V. value column

    Hi all

    I use Oracle Business Intelligence 11.1.1.7.131017.

    I have a column with the following formula: C.V. ("Tickets". "Number of tickets"), but since we want to only show the values advocated by the past 6 months and which is an accumulative column, we added the rank function in the filter and placed as: grade (C.V. ("Tickets". " Number of tickets')) < = 6 and for the final formula, we need the minimum value that is placed in 6th place...

    My problem is how to get the value assigned to this position?

    Here's the column values:

    30719 (value I pretend-> min)

    31357

    32025

    32595

    33652

    34616 (I also use this value-> max)

    Any idea on how to get the value placed on tier 6?

    Thanks for the help and have a good week.

    Kind regards

    Frederico.

    I found a solution (poor, but it works)...

    As a minimum I want is always located in the row = 6 I put a case when row = 6, then returns the value I'm pretending, else return 0, so after that I need only the max of all values, as they are 0 or the value that I'm pretending, like this:

    MAX (CASE WHEN (GRADE (C.V. ("Tickets". "Number of tickets')) = 6) THEN of C.V. (FILTER ("Tickets"." Number of tickets' using 'status '. ((("" Resolved "="Resolvido")) END ELSE 0)

    I want to thank you all for the help, normally I post in the forum of the ADF but its good to know I can get a lot of support here as well...

    Many thanks to all,

    Frederico.

  • How to get the result of the assessment?

    According to Adobe Captivate online help, "use the assessment mode when you want to test how the user has understood a procedure. You can set a score for every correct click. "

    But how the person who makes the assessment of the result (score/percentage) GET?

    Go to the Quiz settings and select the option to show the Score at the end of the Quiz.

    A new Quiz results slide is added at the end of your quiz so that learners can see their quiz results.

  • Not sure how to get the result that I need.

    Hi all

    I'm not a very good programmer, but I'm learning so please bear with me.

    My problem is that I need to be able to create a page that we can imput two dates and get all the items in our database which are equal or between imputted dates and be sent to the page.

    The part of sql is not my problem, but I'm not sure on how to create the page with in the date boxes.

    As it is now I have created the page, but it is retreving all elements of my table and comes it a grid of smiple and the output how many entries table for this is manageable.

    So, if someone can help me or point me in the right direction that would be great.

    Thnaks

    Pat

    Basis of a form.

    Basis of a SQL clause

    
      SELECT aField,bField,cField
      FROM aTable
      WHERE aDateField BETWEEN
               AND
              
    
    

    There is much for you to learn and understand to make a function and a business page.  But you should get at least close to return results.

  • How to get the result

    Hi all

    Let me explain my requirment.

    I created a custom workflow where the order goes to the approver for counterpart he can accept or reject that.

    If the notification that the approver receives have a result with approve and reject values. The notification activity, I've written a procedure that will update the database columns that are based on the result.

    But how do we get this result value

    I need something like below

    x_result: result of get value =
    If x_result = "Approve" then
    Update of table with approved status
    on the other
    Update of table with the status rejected

    Kind regards
    Kumar.

    Use the RESULT attribute

    x_result: = Wf_Notification.GetAttrText (, 'RESULT');

  • How to get the list in a single column in a query

    Hello.

    I wonder if there is a way to get a query (no pl/sql code) a list of columns with a separator between them.

    I know I can get that without separators with an expression of cursor:
    SQL> with test_table as (
      2  select 1 col1, 'a' col2 from dual
      3  union
      4  select 1 col1, 'b' col2 from dual
      5  union
      6  select 1 col1, 'c' col2 from dual
      7  union
      8  select 2 col1, 'a' col2 from dual
      9  union
     10  select 2 col1, 'c' col2 from dual
     11  union
     12  select 2 col1, 'd' col2 from dual
     13  union
     14  select 2 col1, 'z' col2 from dual
     15  )
     16  select col1, cursor (select b.col2 from test_table b where b.col1 = a.col1 order by b.col2) col2_list from test_table a
     17  group by col1
     18  /
    
          COL1 COL2_LIST
    ---------- --------------------
             1 CURSOR STATEMENT : 2
    
    CURSOR STATEMENT : 2
    
    C
    -
    a
    b
    c
    
             2 CURSOR STATEMENT : 2
    
    CURSOR STATEMENT : 2
    
    C
    -
    a
    c
    d
    z
    But the result I want is (by using the separator ';'):
          COL1 COL2_LIST
    ---------- --------------------
             1 a;b;c
             2 a;c;d;z
    I don't know how to manage a cursor expression without using a pl/sql function block. Can it be done using analytical functions?

    Thanks in advance.

    Hello

    This is called 'aggregation of chain.
    This site:

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

    shows different ways to do this, including the SYS_CONNECT_BY_PATH solution which gave Blushadow.

    I got a lot of use of the first solution on this page, the function defined by the user STRAGG, that you can copy.

    Once you have installed STRAGG, your query is simply

    SELECT    col1
    ,         STRAGG (col2)     AS col2_list
    FROM      test_table
    GROUP BY  col1;
    

    The query above do not put items in a particular order.

    On Oracle 10 (and more) you can have a similar function, the WM_CONCAT (property WMSYS), already installed.
    WM_CONCAT is not documented, so you can't use it in your Production applications.

  • How to get the color of a single pixel?

    Hi all.

    Part of my application is transparent. The other party is not.

    But I would like to have 'match' colors (is not very pretty orange to pink, but it's a matter of personal taste, I guess).

    That's why I need now to a background color.

    That's what I had in mind:

    Because we cannot get information about the currently active theme, I can do a screen capture and extract a single pixel of interest and get its color information. If it is green (for example) - I'll tryto use more Brown colors in my application.

    So basically, is it possible to get the color of a pixel in a bitmap (or something?)

    My last resort would be to save the Bitmap image to a file and then read that file.

    Bitmap.getARGB (int [] argbData, int offset, int scanLength, int x, int y, int width, int height)
    Gets the raw data ARGB region of this Bitmap and stores it in the table provided.

  • How to get the result on the same page

    How to capture the data entered by the user on the page and fill in the result.

    for example: -.

    Data: -.

    fieldA = abc

    fielsb = efg

    Feildc = SMC

    result = abc-efg-chd

    I intend to write this logic in controller...

    If one of you having same logic please give me... Thanks a lot guys!

    Edited by: user11929230 (Pavan) October 14, 2009 08:46

    Pavan,

    I take a simple example, I hope it's clear your doubts.

    In Jdev create 3 new MessageTextInput with VO no attribute.

    Let's say it would be item1 and item2, item3

    And if I click on save button I want to concatenate the value of item1 and item2 in item3. As A and B in item3 in so AB

    Now in the ProcessFormRequest controller I'll write.

    If (pageContext.getParameter ('save')! = null)
    {
    String a = pageContext.getParameter ("item1"); Item1 here is the Id of the item that you created in JDEV
    String b = pageContext.getParameter ("item2");

    Txt OAMessageTextInputBean = (OAMessageTextInputBean) webBean.findChildRecursive ("item3");
    txt.setText(pageContext,a+"-"+b);
    }

    Thank you
    -Anil

  • How to get the result of these data

    Hi all

    I have a following data. And I need the output as follows.

    If one of the Intr_num is missing so I need the output to be formatted the next row.

    I tried this using the row_number() but could not able to achieve the result. Is there any other function or analysis features to use.

    with t as 
    (
      select 10001 id, 5004 Intr_num from dual union all
      select 10002,5005 from dual union all
      select 10003,5006 from dual union all
      select 10004,5007 from dual union all
      select 10006,5009 from dual union all
      select 10007,5010 from dual union all
      select 10010,5013 from dual union all
      select 10011,5014 from dual union all
      select 10012,5015 from dual union all
      select 10013,5016 from dual union all
    )
    select * from t;
    
    OUTPUT:
    
    Intr_num
    5004 - 5007
    5009 - 5010
    5013 - 5016
    
    
    

    Kind regards

    SID

    Hello

    ROW_NUMBER is the right function to use:

    WITH got_dif AS

    (

    SELECT intr_num

    , intr_num - ROW_NUMBER () OVER (ORDER BY intr_num) AS dif

    T

    -WHERE... - If you need any filtering, put it here

    )

    SELECT MIN (intr_num) | ' - '

    || MAX (intr_num) AS intr_num_range

    OF got_dif

    GROUP BY dif

    ORDER BY dif

    ;

Maybe you are looking for