How the horizontal rotation the result set? (no swivel)

Hi all

Suppose that my result of the query is as follows. (Version 11g)

Select 1 id, 'a' name, 'new york' city from dual

Union all

Select 1 id, 'b' name, 'manhattan' city from dual

Union all

Select 1 id, 'c' name, 'paris' city from dual

Union all

Select 1 id, 'd' name, 'ottowa' city from dual

Union all

Select 1 id, 'e' name, 'toronto' city from dual

Union all

Select 1 id, 'f' name, 'newcastle' city from dual

Union all

Select 1 id, 'g' name, 'liverpool' city from dual

Union all

Select 1 id, 'h' name, 'manchester' city from dual;

1 in new york

1 b manhattan

1 c. paris

Ottowa 1 d

1 e toronto

1 f newcastle

Liverpool 1 g

1 h manchester

I want the following

Select 1 id, 'a' name, 'new york' city, 'b' name, 'manhattan' city, 'c' name, 'paris' city, 'd' name, 'ottowa' city, 'e' name, 'toronto' city, 'f' name, 'newcastle' city, 'g' name, 'liverpool', 'h' name, 'manchester'  from dual;

1 a new york manhattan ottowa paris b d e f g c. manchester liverpool newcastle toronto

Thank you

OR maybe you looing for:

----------

WITH dataset
     AS (SELECT 1 id, 'a' name, 'new york' city FROM DUAL
         UNION ALL
         SELECT 1 id, 'b' name, 'manhattan' city FROM DUAL
         UNION ALL
         SELECT 1 id, 'c' name, 'paris' city FROM DUAL
         UNION ALL
         SELECT 1 id, 'd' name, 'ottowa' city FROM DUAL
         UNION ALL
         SELECT 1 id, 'e' name, 'toronto' city FROM DUAL
         UNION ALL
         SELECT 1 id, 'f' name, 'newcastle' city FROM DUAL
        UNION ALL
         SELECT 1 id, 'g' name, 'liverpool' city FROM DUAL
         UNION ALL
         SELECT 1 id, 'h' name, 'manchester' city FROM DUAL
)
,resultset as (SELECT id||','||listagg(name ||','||city,',') within group (order by id) str FROM dataset group by id)
select regexp_substr(str,'[^,]+',1,1) id
,regexp_substr(str,'[^,]+',1,2) name
,regexp_substr(str,'[^,]+',1,3) city
,regexp_substr(str,'[^,]+',1,4) name
,regexp_substr(str,'[^,]+',1,5) city
,regexp_substr(str,'[^,]+',1,6) name
,regexp_substr(str,'[^,]+',1,7)city
,regexp_substr(str,'[^,]+',1,8)name
, regexp_substr(str,'[^,]+',1,9)city
, regexp_substr(str,'[^,]+',1,10)name
, regexp_substr(str,'[^,]+',1,11)city
, regexp_substr(str,'[^,]+',1,12)name
, regexp_substr(str,'[^,]+',1,13)city
, regexp_substr(str,'[^,]+',1,14)name
, regexp_substr(str,'[^,]+',1,15)city
, regexp_substr(str,'[^,]+',1,16)name
, regexp_substr(str,'[^,]+',1,17)city
from resultset

See you soon;

Manik.

Tags: Database

Similar Questions

  • How to exclude the each row of the result set XML declaration?

    Hello

    I have a table with an XMLTYPE column and would like to SELECT a set of rows. How can I exclude the each row of the result set XML declaration? My query currently looks like this, I am running through Spring JDBC:
    SELECT XMLSerialize FROM t1 WHERE XMLEXISTS('$e/Event' PASSING XMLTEXT AS "e") ORDER BY t1.time DESC myschema.event (HAPPY t1.xmltext)

    After selecting, in my application I convert each line in a string and concatenate all the rows in a large chain to analyze in a DOM model. I get a parser exception (org.xml.sax.SAXParseException: the target of the processing instruction corresponding to "[xX] [mM] [he's]" is not allowed) because there are several XML statements in my large chain. Of course, I could manually check the string on each line if it starts with the XML declaration, but it would be nicer if I could load the DB does not add it in the first place. Is there a way?

    Thank you!
    -Daniela

    Hello

    Some options that I can think of:

    SELECT XMLSerialize(CONTENT
     XMLtransform(t1.xmltext,
      xmltype('
     
     
    ')
     )
    )
    FROM myschema.event t1
    WHERE XMLEXISTS('$e/Event' PASSING XMLTEXT AS "e")
    ORDER BY t1.time DESC
    ;
    

    or quite simply,.

    SELECT XMLSerialize(CONTENT
      extract(t1.xmltext,'/')
    )
    FROM myschema.event t1
    WHERE XMLEXISTS('$e/Event' PASSING XMLTEXT AS "e")
    ORDER BY t1.time DESC
    ;
    
  • How to test a procedure returns the result set

    Hello

    I have a following code:

    {color: #0000ff} create or replace the TYPES of PACKAGING
    AS
    type cursorType is ref cursor;
    end;

    create or replace PROCEDURE GetAllCategories (p_cursor in the Types.cursorType)
    AS
    Start
    Open p_cursor for SELECT * CATEGORY;
    end; {color}

    I would like to test the procedure of * {color: #000000} visualization output resultset {color} *. How can I do with SQL Developer?
    In fact, when select RUN in SQL Developer, I got the following code:

    DECLARE
    P_CURSOR types.cursorType;
    BEGIN

    GetAllCategories (P_CURSOR = & gt; P_CURSOR);
    END;

    When I run it, it is successful but there is no result set displayed. However if I execute SELECT * FROM category only in the SQL Editor, I see the result set in the grid. Then where the result set did when he went through the procedure?

    Thanks in advance for any help.

    Published by: CarbonFiber Sep 22, 2008 20:52

    Is a simple way with sqlplus

    SQL> create or replace package types
      2  as
      3     type cursortype is ref cursor;
      4  end;
      5  /
    
    Package created.
    
    SQL> create or replace procedure getallemp(p_cursor in out types.cursortype )
      2  as
      3  begin
      4     open p_cursor for select * from emp;
      5  end;
      6  /
    
    Procedure created.
    
    SQL> var lcursor refcursor
    SQL>
    SQL> exec getallemp(:lcursor)
    
    PL/SQL procedure successfully completed.
    
    SQL> print lcursor
    
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO        DIV
    ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- ----------
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20         10
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30         10
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30         10
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20         10
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30         10
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30         10
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10         10
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20         10
          7839 KING       PRESIDENT            17-NOV-81       5000                    10         10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30         10
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20         10
    
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO        DIV
    ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- ----------
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30         10
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20         10
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    10         10
    
    14 rows selected.
    

    Thank you
    Knani.

  • Help with the query to select only one record from the result set in double

    Hello

    Please help with the query. Version of Oracle database we use is 10g R2.

    I have a vision that is duplicated IDS, but they are used across the different functions. See below examples of data. Please help me with a query to select only one record (based on ID regardless of the area) from the bottom of the result set of duplicate records. For what is the point of view is there unique records, given the combination of the fields ID, Org, DF, dry, Sub-Sec

    ID
    Org
    DF
    Sec Sub-Sec

    (163)CQCPDMCPDMHD(163)PCENGENGENG(163)CQASICASICIS8888TSTACTACTAC(163)TSHEHESW6789CQINFOINFOFOS6789PCSECSYSSECSYSINFO16789TSSECSYSSECSYSINFO29009PCBMSBMSBMS1

    My result set must eliminate the duplicate identifiers regardless of whoever we choose of the result set. (I mean without distinction Org, DF, s, Sub-s). My expected result set should be.

    ID
    DSB

    DF
    SEC
    Sub-Sec
    (163)CQCPDMCPDMHD8888TSTACTACTAC6789CQINFOINFOFOS9009PCBMSBMSBMS1


    Thank you

    Orton

    Hello

    This sounds like a job for ROW_NUMBER:

    WITH got_r_num AS

    (

    SELECT id, DSB, df, s, sub_sec org

    ROW_NUMBER () OVER (PARTITION BY ID.

    ORDER BY org

    ) AS r_num

    OF view_x

    )

    SELECT id, DSB, df, sub_sec s,

    OF got_r_num

    WHERE r_num = 1

    ;

    He is a Top - N query example, where you choose the elements of N (N = 1 in this case) from the top of an ordered list.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) to your sample data and the results desired from these data.  (I know that you said that you were a view selection.  Just for this thread, pretending it is a picture and post simple CREATE TABLE and INSERT statements to simulate your point of view).
    Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.  (I didn't quite understand the explanation above.  I don't know why you want to

    ID ORG DF DRY SUB_SEC

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

    1234 CQ DPRK DPRK HD

    and is not

    1234 IS CQ ASIC, ASIC

    or

    TS 1234 IT IT SW

    or

    1234 CQ ASIC ASIC HD

    )
    If you change the query at all, post your modified version.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • AF:inputListOfValues sets the value of the first item in the result set when using enter key or tab and component value autosubmit = true

    I use JDev 11.1.1.6 and when I type in a value in an af:inputListOfValues element and press enter or the tab key, it will replace the value I entered with the first element in the set of results LOV. If enter a value, simply click on the component af:inputListOfValues it works correctly. If I use the popup and find a value it works properly as well. I have a programmatic view object that contains a single transitional attribute (this is the view object that is used to create the list of the components of the value of) and then I have another object from view based on entities which defines one of its attributes in a list of the attribute value. I tried to use a base object view of entity to create the LOV to and everything works as expected, so I don't know if this is a bug when using programmatic view objects or if I need more code in the VOImpl. In addition, it seems after that first of the value being replaced by the first value in the result set that it will work correctly as well. Here are some excerpts of important code.

    Also, it seems that this does not work only if the text entered in the component af:inputListOfValues would have only a single game, returned in the result set. For example, given the result defined in code: Brad, Adam, Aaron, Fred, Charles, Charlie, Jimmy

    If we get into Cha, the component works as expected

    If we register A, the component works as expected

    If we get Jimmy, the component does not work as expected, and returns the first value of results IE. Brad

    If we get Fred, the component does not work as expected, and returns the first value of results IE. Brad

    I also checked that I get the same behavior in JDev 11.1.1.7

    UsersVOImpl (programmatic view with 1 transitional attribute object)

    import java.sql.ResultSet;
    
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    
    import oracle.adf.share.logging.ADFLogger;
    
    import oracle.jbo.JboException;
    import oracle.jbo.server.ViewObjectImpl;
    import oracle.jbo.server.ViewRowImpl;
    import oracle.jbo.server.ViewRowSetImpl;
    
    // ---------------------------------------------------------------------
    // ---    File generated by Oracle ADF Business Components Design Time.
    // ---    Wed Sep 18 15:59:44 CDT 2013
    // ---    Custom code may be added to this class.
    // ---    Warning: Do not modify method signatures of generated methods.
    // ---------------------------------------------------------------------
    
    public class UsersVOImpl extends ViewObjectImpl {
    
        private static ADFLogger LOGGER = ADFLogger.createADFLogger(UsersVOImpl.class);
        private long hitCount = 0;
    
        /**
         * This is the default constructor (do not remove).
         */
        public UsersVOImpl () {
        }
    
        /**
         * executeQueryForCollection - overridden for custom java data source support.
         */
        protected void executeQueryForCollection (Object qc, Object[] params, int noUserParams) {
    
             List<String> usersList = new ArrayList<String>();
             usersList.add("Brad");
             usersList.add("Adam");
             usersList.add("Aaron");
             usersList.add("Fred");
             usersList.add("Charles");
             usersList.add("Charlie");
             usersList.add("Jimmy");
    
             Iterator usersIterator = usersList.iterator();
             setUserDataForCollection(qc, usersIterator);
             hitCount = usersList.size();
             super.executeQueryForCollection(qc, params, noUserParams);
    
        } // end executeQueryForCollection
    
        /**
         * hasNextForCollection - overridden for custom java data source support.
         */
        protected boolean hasNextForCollection (Object qc) {
    
             Iterator usersListIterator = (Iterator)getUserDataForCollection(qc);
             if (usersListIterator.hasNext()) {
         
                 return true;
    
             } else {
    
                 setFetchCompleteForCollection(qc, true);
                 return false;
    
             } // end if
    
        } // end hasNextForCollection
    
        /**
         * createRowFromResultSet - overridden for custom java data source support.
         */
        protected ViewRowImpl createRowFromResultSet (Object qc, ResultSet resultSet) {
    
             Iterator usersListIterator = (Iterator)getUserDataForCollection(qc);
             String user = (String)usersListIterator.next();
             ViewRowImpl viewRowImpl = createNewRowForCollection(qc);
    
             try {
    
                 populateAttributeForRow(viewRowImpl, 0, user.toString());
    
             } catch (Exception e) {
    
                 LOGGER.severe("Error Initializing Data", e);
                 throw new JboException(e);
    
             } // end try/catch
    
             return viewRowImpl;
    
        } // end createRowFromResultSet
    
        /**
         * getQueryHitCount - overridden for custom java data source support.
         */
        public long getQueryHitCount (ViewRowSetImpl viewRowSet) {
             return hitCount;
        } // end getQueryHitCount
    
        @Override
        protected void create () {
    
             getViewDef().setQuery(null);
             getViewDef().setSelectClause(null);
             setQuery(null);
    
        } // end create
    
        @Override
        protected void releaseUserDataForCollection (Object qc, Object rs) {
    
             Iterator usersListIterator = (Iterator)getUserDataForCollection(qc);
             usersListIterator = null;
             super.releaseUserDataForCollection(qc, rs);
    
        } // end releaseUserDataForCollection
    
    } // end class
    
    

    <af:inputListOfValues id="userName" popupTitle="Search and Select: #{bindings.UserName.hints.label}" value="#{bindings.UserName.inputValue}"
                                                  label="#{bindings.UserName.hints.label}" model="#{bindings.UserName.listOfValuesModel}" required="#{bindings.UserName.hints.mandatory}"
                                                  columns="#{bindings.UserName.hints.displayWidth}" shortDesc="#{bindings.UserName.hints.tooltip}" autoSubmit="true"
                                                  searchDesc="#{bindings.UserName.hints.tooltip}"                                           
                                                  simple="true">
                              <f:validator binding="#{bindings.UserName.validator}"/>                       
    </af:inputListOfValues>
    
    
    
    

    I found a solution to this problem. It seems that, when using a view object programmatic that has a transient as its primary key attribute, you need to override the methods in the ViewObjectImpl so that he knows how to locate the line related to the primary key when the view object records are not in the cache. That's why it would work properly sometimes, but not always. Here are the additional methods that you must override. The logic you use in the retrieveByKey would be on a view view object database object and would be different if you had a primary key consisting of multiple attributes.

    @Override
    protected Row[] retrieveByKey (ViewRowSetImpl viewRowSetImpl, Key key, int i) {
        return retrieveByKey(viewRowSetImpl, null, key, i, false);
    }
    
    @Override
    protected Row[] retrieveByKey (ViewRowSetImpl viewRowSetImpl, String string, Key key, int i, boolean b) {
    
        RowSetIterator usersRowSetIterator = this.createRowSet(null);
        Row[] userRows = usersRowSetIterator.getFilteredRows("UserId", key.getAttribute(this.getAttributeIndexOf("UserId")));
        usersRowSetIterator.closeRowSetIterator();
        return userRows;
    
    }
    
    @Override
    protected Row[] retrieveByKey (ViewRowSetImpl viewRowSetImpl, Key key, int i, boolean b) {
        return retrieveByKey(viewRowSetImpl, null, key, i, b);
    }
    
  • get the result set in CSV

    How can I get a result set of a table as a comma-separated value? I saw there are dbms_utility.table_to_comma but don't know how to use it.

    For example,
    Select column_name from user_tab_columns where table_name = "TAB1".

    I want to get the result as col1, col2, col3

    I'm using Oracle 11 g.

    Your help is very appreciated. :)

    Hello

    in oracle 11, you can use:

    select
      LISTAGG(column_name,',') WITHIN GROUP (ORDER BY COLUMN_ID) CSV
    
    from
      user_tab_columns
    
    where
      table_name = 'PBCATCOL'
    
    ;
    
    CSV
    ---------------------------------------------------------------------------------------------------------------------------------------------
    PBC_TNAM,PBC_TID,PBC_OWNR,PBC_CNAM,PBC_CID,PBC_LABL,PBC_LPOS,PBC_HDR,PBC_HPOS,PBC_JTFY,PBC_MASK,PBC_CASE,PBC_HGHT,PBC_WDTH,PBC_PTRN,PBC_BMAP,PBC_INIT,PBC_CMNT,PBC_EDIT,PBC_TAG             
    
                                                                                                                                           
    

    Kind regards

    Peter

  • Get spaces empy in the result set

    Hello

    We are migration CF 5 to 9. App works great in CF5. but when we run the same code in CF9, for all sets of results, we get the empty sapce for each field.

    Ex:

    CF5: field1: order_id, value = "OL123456".

    CF9: field1: order_id, value = "OL123456".

    We get the empty sapce for each field in the result sets. I know that we can use the topping, but we have so many pages in the application and we cannot do that. can someone help how to solve this problem. I am using the database Ingres and connection with another datasource in CF Admin.

    Srinivas

    I used the query of queries and the problem is solved.

  • Hotkey of the worksheet area of writing in the result set

    Y at - it a keyboard shortcut to switch between writing in the SQL worksheet and navigate (or copy,...) in the result set of a query run?

    That would make my job easier everyday!

    @Chris

    ALT + PagegDown in version 4.0

    No no not a nav of Ko to this v3.2 and earlier versions, has been saved as a bug.

  • Combine queries to get the result set with max Y

    Hello
    I use forms 6i and db 10.2.0.1.0

    With the query below
    Select ufam_usrgrp,ufam_filegrp,ufam_read,ufam_write,ufam_overwrite,ufam_delete from usr_file_access_master
    Where ufam_ecode = '0004108';
    the result set is
    UFAM_USRGRP     UFAM_FILEGRP    UFA UFA UFA UFA
    --------------- --------------- --- --- --- ---
    MGMNT           CV              Y   Y   Y   Y
    EMPLOYEE        GENERAL         Y   N   N   N
    EMPLOYEE        PERSONAL        Y   N   N   N
    Another query
    Select uul_usrgrp, ufl_file_grp,ufl_read,ufl_write,ufl_overwrite,ufl_delete from usr_usrgrp_lnk,USRGRP_FILEGRP_LINK
    Where usr_usrgrp_lnk.uul_usrgrp = USRGRP_FILEGRP_LINK.UFL_USR_GRP
    and usr_usrgrp_lnk.uul_ecode = '0004108'
    gives the result
    UUL_USRGRP      UFL_FILE_GRP    UFL UFL UFL UFL
    --------------- --------------- --- --- --- ---
    MGMNT           GENERAL         Y   Y   Y   Y
    EMPLOYEE        GENERAL         Y   Y   N   N
    MGMNT           CV              Y   N   N   N
    I need to combine these two queries to get a separate result set with maximum Y

    Like here "MGMNT CV" is repeated in both the result set, but the first has more, then it should come from the combined result set. reverse-case also the same (such as "EMPLOYEE GENERAL")

    So I want to combine the queries so that I get the result as set below
    UserGroup       FileGroup       Rd Wrt Owrt Del
    --------------- --------------- --- --- --- ---
    MGMNT           GENERAL         Y   Y   Y   Y
    EMPLOYEE        GENERAL         Y   Y   N   N
    MGMNT           CV              Y   Y   Y   Y
    EMPLOYEE        PERSONAL        Y   N   N   N
    Please help me to combine these queries

    Published by: Divya on August 14, 2011 21:24
    Changed the result set and the last exit

    NOT TESTED!

    select y.uul_usrgrp,
           y.ufl_file_grp,
           greatest(ufl_read,nvl(ufam_read,' ')) ufl_read,
           greatest(ufl_write,nvl(ufam_write,' ')) ufl_write,
           greatest(ufl_overwrite,nvl(ufam_overwrite,' ')) ufl_overwrite,
           greatest(ufl_delete,nvl(ufam_delete,' ')) ufl_delete
      from (select ufam_usrgrp,ufam_filegrp,ufam_read,ufam_write,ufam_overwrite,ufam_delete
              from usr_file_access_master
             Where ufam_ecode = '0004108'
           ) x,
           (select uul_usrgrp, ufl_file_grp,ufl_read,ufl_write,ufl_overwrite,ufl_delete
              from usr_usrgrp_lnk,USRGRP_FILEGRP_LINK
             Where usr_usrgrp_lnk.uul_usrgrp = USRGRP_FILEGRP_LINK.UFL_USR_GRP
               and usr_usrgrp_lnk.uul_ecode = '0004108'
           ) y
     where y.uul_usrgrp = x.ufam_usrgrp(+)
       and y.ufl_file_grp = x.ufam_filegrp(+)
    

    Concerning

    Etbin

    Edited by: Etbin on 14.8.2011 13:08
    deleted by group

  • Remove duplicates from the result set

    Here's a challenge question that I was playing with a my free time during the work.

    I assume you have the basic HR example somewhere around (I hope is not in production).

    Let's say you want to get employees from the employees table whose name is similar to another employee last name.
    The easiest way is to join the two tables with a join condition that checks for the name and employee id. Here's what I came with.

    *************

    Select e1.last_name, e1.first_name b, e2.last_name c, e2.first_name d
    employees employees join e1 e2
    on (e1.last_name = e2.employee_id <>e2.last_name and e1.employee_id)
    order by one;

    ************

    The above query returns 10 rows. The first and the second are essentially the same. It is similarly, 3 & 4, 5 & 6, 7 and 8 and 9 and 10. The question is: is there a way that allows me to get rid of using only sql duplicate rows from the result set of this query. I sat on it for 15 minutes and I couldn't know. I'll try to watch my completed work once again.

    Example:

    SQL> column a format a10
    SQL> column b format a10
    SQL> column c format a10
    SQL> column d format a10
    SQL>
    SQL>
    SQL> select e1.last_name a , e1.first_name b, e2.last_name c, e2.first_name d
      2  from employees e1 join employees e2
      3  on ( e1.last_name = e2.last_name and e1.employee_id != e2.employee_id)
      4  where e1.employee_id < e2.employee_id
      5  order by a;
    
    A          B          C          D
    ---------- ---------- ---------- ----------
    Cambrault  Gerald     Cambrault  Nanette
    Grant      Kimberely  Grant      Douglas
    King       Steven     King       Janette
    Smith      Lindsey    Smith      William
    Taylor     Jonathon   Taylor     Winston
    
    SQL>
    
  • Ask... How to reach the result sets in order?

    Let me give a few examples of data first to give an idea of what I am working with:

    Oracle: 10g
    --Table xTable
    
    NAME             DESC_ID
    ALAN                   2 
    AMY                    3
    BILL                    5
    BOB                     7
    CARL                   1
    CHRIS                  8
    DAN                    4
    DEREK                 6  
    So what I try to do is right out of names (ALAN, CHRIS, DAN) in ascending order (according to out of name) and then all the names (AMY, BILL, BOB, CARL, DEREK) in ascending order (according to out name)... and I want all of this in a single result set. So basically the first set of names in alphabetical order, followed by the rest of the names in alphabetical order.

    I want the output to look exactly like this:
    NAME       DESC_ID     
    ALAN               2
    CHRIS                8
    DAN                  4
    AMY                  3
    BILL                   5
    BOB                    7  
    CARL                  1
    DEREK                6  
    I tried the following, but it doesn't seem to work
    select distinct a.name, a.desc_id
    from xTable,
    (select distinct name, desc_id
    from xTable
    where DESC_ID  in (2,8,4)
    order by name
    ) type1,
    (select distinct name, desc_id
    from xTable
    where DESC_ID  in (1,3,5,6,7)
    order by name
    ) type2
    where desc_id in (type1, type2);
    The code above seems terribley unefficent and apparently not at the exit of the things in the order I want. Any ideas?

    Published by: user652714 on January 5, 2010 11:23

    Published by: user652714 on January 5, 2010 11:28

    If you have a known list of DESC_ID you could do something like this:

    SQL> WITH xTable AS
      2  (
      3          SELECT 'ALAN'   AS NAME, 1 AS TYPE_ID, 2 AS DESC_ID FROM DUAL UNION ALL
      4          SELECT 'AMY'    AS NAME, 2 AS TYPE_ID, 3 AS DESC_ID FROM DUAL UNION ALL
      5          SELECT 'BILL'   AS NAME, 2 AS TYPE_ID, 5 AS DESC_ID FROM DUAL UNION ALL
      6          SELECT 'BOB'    AS NAME, 2 AS TYPE_ID, 7 AS DESC_ID FROM DUAL UNION ALL
      7          SELECT 'CARL'   AS NAME, 2 AS TYPE_ID, 1 AS DESC_ID FROM DUAL UNION ALL
      8          SELECT 'CHRIS'  AS NAME, 1 AS TYPE_ID, 8 AS DESC_ID FROM DUAL UNION ALL
      9          SELECT 'DAN'    AS NAME, 1 AS TYPE_ID, 4 AS DESC_ID FROM DUAL UNION ALL
     10          SELECT 'DEREK'  AS NAME, 2 AS TYPE_ID, 6 AS DESC_ID FROM DUAL
     11  )
     12  SELECT  NAME
     13  ,       DESC_ID
     14  FROM    xTable
     15  ORDER BY
     16          (CASE
     17                  WHEN DESC_ID IN (2,8,4)         THEN 1
     18                  WHEN DESC_ID IN (1,3,5,6,7)     THEN 2
     19          END)
     20  ,       1
     21  /
    
    NAME               DESC_ID
    ----- --------------------
    ALAN                     2
    CHRIS                    8
    DAN                      4
    AMY                      3
    BILL                     5
    BOB                      7
    CARL                     1
    DEREK                    6
    
    8 rows selected.
    

    Another option would be to use the UNION, but he strikes the table twice instead of once as described above:

    SQL> WITH xTable AS
      2  (
      3          SELECT 'ALAN'   AS NAME, 1 AS TYPE_ID, 2 AS DESC_ID FROM DUAL UNION ALL
      4          SELECT 'AMY'    AS NAME, 2 AS TYPE_ID, 3 AS DESC_ID FROM DUAL UNION ALL
      5          SELECT 'BILL'   AS NAME, 2 AS TYPE_ID, 5 AS DESC_ID FROM DUAL UNION ALL
      6          SELECT 'BOB'    AS NAME, 2 AS TYPE_ID, 7 AS DESC_ID FROM DUAL UNION ALL
      7          SELECT 'CARL'   AS NAME, 2 AS TYPE_ID, 1 AS DESC_ID FROM DUAL UNION ALL
      8          SELECT 'CHRIS'  AS NAME, 1 AS TYPE_ID, 8 AS DESC_ID FROM DUAL UNION ALL
      9          SELECT 'DAN'    AS NAME, 1 AS TYPE_ID, 4 AS DESC_ID FROM DUAL UNION ALL
     10          SELECT 'DEREK'  AS NAME, 2 AS TYPE_ID, 6 AS DESC_ID FROM DUAL
     11  )
     12  SELECT  NAME
     13  ,       DESC_ID
     14  FROM
     15  (
     16          SELECT  NAME
     17          ,       DESC_ID
     18          ,       1 AS ORD_COL
     19          FROM    xTable
     20          WHERE   DESC_ID IN (2,8,4)
     21          UNION
     22          SELECT  NAME
     23          ,       DESC_ID
     24          ,       2 AS ORD_COL
     25          FROM    xTable
     26          WHERE   DESC_ID IN (1,3,5,6,7)
     27  )
     28  ORDER BY ORD_COL
     29  ,       NAME
     30  /
    
    NAME               DESC_ID
    ----- --------------------
    ALAN                     2
    CHRIS                    8
    DAN                      4
    AMY                      3
    BILL                     5
    BOB                      7
    CARL                     1
    DEREK                    6
    
    8 rows selected.
    
  • How to add additional data in the result set of cfquerry?

    Hi all

    I'm new to cold fusion it please help me

    I'm using the tag cfquery for running a select query and get the name of the system and the system is the...

    But I want an id system and additional system name to add to the result of this query with to change the database ...

    Please anyone suggest me... IT is URGENT

    Thanks in advance
    Sainaba

    UH... - What is a line or two columns?

    Whatever it is, there are functions to achieve is: queryAddRow() or queryAddColumn().  Take a look @ query functions:

    http://livedocs.Adobe.com/ColdFusion/8/htmldocs/functions-pt0_16.html#1099653

    --

    Adam

  • Concatenate the result set into a SQL string

    Hi, I need help with the concatenation of a result set in order to avoid the duplication of data.

    I have 3 tables:

    SCRIPT
    ID - number PK
    DATE - day
    TITLE - Varchar2

    AUTHOR
    A_ID - number PK
    A_Name - Varchar2

    SCRIPT_AUTHOR
    ID - number - PK, FK of Script.ID
    A_ID - number PK, FK of Author. A_ID


    I need the list of all authors for each script on a single line, for the moment I have the following SQL code:

    Select S.Title, SA. A.ID
    SCRIPT S, SCRIPT_AUTHOR SA
    WHERE SCRIPT.ID = SCRIPT_AUTHOR.ID


    and as expected it's returning a dataset as follows:-give me 2 lines in this case for a script:

    S.TITLE, SA. A_ID
    1, 1
    1, 2

    What I'm really after is a result set that combines the two authors in this case a file: 1, 1:2, so I don't have 1 line by script.
    Scripts can have many authors, and I want to do it for a lot of scripts at a time.

    I hit a blank on how to do it, is it possible to do it with SQL?

    Thank you very much

    p.s. help: Oracle Database 10g Enterprise Edition release 10.2.0.3.0

    Hello

    This is called 'aggregation of chain.
    [AskTom.oracle.com | http://asktom.oracle.com/pls/asktom/f?p=100: 11:0:P11_QUESTION_ID:2196162600402] shows several ways to do so.

    I recommend the first, the function defined by the user STRAGG, that you can copy from this page.

    Once you have installed STRAGG, your query is simply

    Select       S.Title
    ,       STRAGG (SA.A.ID)     AS sa_id_list
    FROM       SCRIPT     S
    ,       SCRIPT_AUTHOR SA
    WHERE       SCRIPT.ID = SCRIPT_AUTHOR.ID
    GROUPB BY s.Title;
    

    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 the results of research of sorting in Windows 8

    Is there a way to sort the search results in Windows 8?  I know I could use the search option in the file manager, but even on my fast new machine it takes forever.  Windows 8 seems to indicate that the drive is indexed.   Things happen quickly when I use the search option from the main screen of Windows 8, but I see no way to sort what is returned.

    How do you get good results from the quick search, sorted as you want in Windows 8.

    Is there a way to sort the search results in Windows 8?  I know I could use the search option in the file manager, but even on my fast new machine it takes forever.  Windows 8 seems to indicate that the drive is indexed.   Things happen quickly when I use the search option from the main screen of Windows 8, but I see no way to sort what is returned.

    How do you get good results from the quick search, sorted as you want in Windows 8.

    Hello

    The key for the search results is to ensure that indexing is configured correctly.

    I don't know of anyway to sort the results in the research of the start screen. You will see some sorting by category, for example when you are searching for a file name. At the top of the results window, you will see everything, music, Documents, pictures, videos, etc., you can click to select a category.

    Here are some links to how-to articles on research.

    How to search

    Learn to search for applications, files and settings using the charm of the search in Windows.

    Indexing and search: frequently asked questions

    Get answers to questions about Windows Search, including what files are indexed, how to add or remove index locations and how to troubleshoot indexing.

    Search for files in file Explorer

    Learn how to perform a search using the search box in the file Explorer and how to refine the search using the Search Tools tab.

    Find everything you need with the charm of the research

    Search for applications, settings, and files on your PC, or inside an application that you have installed, all the charm of the research.

    Concerning

  • Is a cursor variable determined by the result set persistence pause feature?

    My world of PL/SQL is upside down: I'm expecting cursor set persistence any operation of inner loop can affect the result. This does not work as expected with an aggregation as subquery (see sal_dept), but adds little by little upward in determining the value of the slider by a function (see sel_debt_funct). What is the reason for this behavior? Bug feature?

    Facts: Oracle 10.2.0.4
    CREATE OR REPLACE FUNCTION get_sal_dept(
        pdeptno IN emp.deptno%TYPE
    )
        RETURN emp.sal%TYPE
    IS
        lnreturn  emp.sal%TYPE;
    BEGIN
        SELECT SUM(sal)
        INTO   lnreturn
        FROM   emp
        WHERE  deptno = pdeptno;
    
        RETURN lnreturn;
    END get_sal_dept;
    /
    
    BEGIN
        FOR r_emp IN (SELECT empno
                            ,ename
                            ,sal
                            ,emp.deptno
                            ,sal_dept
                            ,get_sal_dept(emp.deptno) sel_debt_funct
                      FROM   emp
                            ,(SELECT   deptno
                                      ,SUM(sal) sal_dept
                              FROM     emp
                              GROUP BY deptno) x
                      WHERE  emp.deptno = x.deptno)
        LOOP
            UPDATE emp
            SET sal = sal * 1.33
            WHERE  empno = r_emp.empno;
    
            DBMS_OUTPUT.put_line(r_emp.ename
                                 || ': '
                                 || r_emp.sal
                                 || ' Total Deptno: '
                                 || r_emp.deptno
                                 || ' by inline aggr:'
                                 || r_emp.sal_dept
                                 || ' by function:'
                                 || r_emp.sel_debt_funct
                                );
        END LOOP;
    
        ROLLBACK;
    END;
    /
    
    DROP FUNCTION get_sal_dept
    /
    Result:

    CLARK: 2450 Deptno Total: 10 by aggr:8750 inline by function: * 8750 *.
    KING: 5000 Deptno Total: 10 by inline function aggr:8750: * 9558.5 *.
    MILLER: 1300 Deptno Total: 10 by inline function aggr:8750: * 11208.5 *.
    JONES: 2975 Deptno Total: 20 by inline aggr:10875 by function: * 10875 *.
    FORD: 3000 Deptno Total: 20 by inline function aggr:10875: * 11856.75 *.
    ADAMS: 1100 Deptno Total: 20 by inline function aggr:10875: * 12846.75 *.
    ...
    ...

    Edited by: user577229 the 07.06.2011 09:27

    Published by: BluShadow on June 8, 2011 08:29
    addition of {noformat}
    {noformat} tags                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

    If I understand your point, the key concept to understand here is related to "* statement-level Read consistency and coherence of reading at the level of transactions."

    From the Manual:
    + "If a SELECTION list contains a function, then the database applies consistency of reading to the statement-level to the level of the SQL statement executed in the PL/SQL function, rather than the parent level SQL code. For example, a function can access a table whose data are changed and committed by another user. For each execution of the function, SELECT a snapshot consistent new reading is established. » +

    These two concepts are well explained in the "Oracle® Database Concepts":
    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14220/consist.htm#sthref1955

  • Failed to get the result set for Get_Search_Results CRMI

    Hi all

    Face with the Null pointer exception while showing the result of the RIDC "GET_SEARCH_RESULTS" Server

    So I can't get the real result of the Content server

    Here is my code:

    ClientManager IdcClientManager = new IdcClientManager();
    Customer IdcClient = clientManager.createClient ("idc://kcsezapp01:4444"); ")
    UserContext IdcContext = new IdcContext ("weblogic", "welcome1");
    HdaBinderSerializer serializer = new HdaBinderSerializer ("UTF-8", client.getDataFactory ());

    If (!) () userContext is nothing))
    {
    DataBinder binding = client.createBinder ();
    binder.putLocal ("IdcService", "GET_SEARCH_RESULTS");
    binder.putLocal ("QueryText", "dDocAuthor < start > 'pra'");

    client.sendRequest (binder, userContext);
    serializer.serializeBinder (System.out, binding);
    System.out.println ("userContext is:" + userContext);
    System.out.println ("dataBinder is:" + linking);
    Resp ServiceResponse = client.sendRequest (userContext, binder);
    System.out.println ("the answer is:" + RESP);
    DataBinder serverBinder = resp.getResponseAsBinder ();
    serializer.serializeBinder (System.out, serverBinder);
    ResultSet DataResultSet = serverBinder.getResultSet("GET_SEARCH_RESULTS");
    for (DataObject dataObject: resultSet.getRows ())
    {
    System.out.println ("" Content ID: "+ dataObject.get ("dDocName") +"\t"+" review: ' "+ dataObject.get ("dRevLabel") +"\t"+" title of the content item: "+ dataObject.get ("dDocTitle")");
    System.out.println ("author is:" + dataObject.get ("dDocAuthor"));
    }
    }

    }

    Prashant_AP wrote:

                   ResultSet DataResultSet = serverBinder.getResultSet("GET_SEARCH_RESULTS");

    Shouldn't this read "resultSet DataResultSet = serverBinder.getResultSet("SearchResults");"?

Maybe you are looking for

  • Pavillion A10 23 - QXT: bluetooth for wireless SoundSticks speakers connection

    I have a harman karden soundsticks wireless set.  I can successfully pair it with the HP, but I have no sound.  The pc shows they are connected and bluetooth speakers light is also on, so there should be sound.  The pair of speakers with a mac book p

  • Satellite L450D - cannot install display driver

    I downloaded the latest display driver for Satellite L450D. He gets in the treatment of the winbatch message then it clears and nothing else happens. I downloaded the file 4 times and the same thing happens. Ant help appreciated.

  • HP envy 4 ultrabook heating problem

    I am facing heating problem with my new HP envy Ultrabook 4 when I used my laptop on the lap for 15 min or any surface. I am not happy with my Ultrabook, according to the specifications of HP Ultrabook has technology cool sense.

  • X 1 or X 220: Please notify a buying decision

    I am trying to decide between X 1 and X 220. I studied the form and I am well informed of the differencs - display size and type, processor options, choice of battery capacity and so on. How to choose between the two? A machine lends itself to some m

  • How to start a timer in labview, when a signal crosses a threshold of voltage

    Hello Please could someone help to find a way to start a timer when an event occurs? (like when a signal crosses a threshold of voltage) Thus, I would ask that help me cope with the following question: I'm acquiring a signal from an acquisition of da