Sql query join with transpose

i have two tables table A and table B, both these tables are associated with id column . And the table B might have
variant properties for each id i.e as shown in the below example id "1" having 4 properties and id "2" having 7
properties and id "3" having 6 properties . is it possible to create output as shown below with varient properties like this .
if at all will it create any performance issues
Table A                                                       
id,      Name     ,Hiredate
1,     archana          ,1/1/2002                                             
2,     sita          ,1/2/2002                                             
3,     rama           ,1/3/2003                                             
Table B                                                       
id,      properties,     value
1,     phone,          40256489                                             
1,     location,     delhi                                             
1,     job,          IT                                             
1,     sal,          3000                              
2,     phone,          40256488                                             
2,     location,     mumbai                                             
2,     job,          Marketing                                             
2,     sal,          5000                                             
2,     deptno,      10                                             
2,     emailid,      [email protected]                                             
2,     dob,          1-1-1600               
3,     phone,          40256483                                             
3,     location,     chennai                                             
3,     job,          insurance agent                                             
3,     gender,          male                                             
3,     company,      lic                                             
3,     emailid,      [email protected]                                             
out put                                                        
id,     Name,     Hiredate,     phone, location,      job,     sal,     deptno,      emailid, dob, gender , company
1,     archana,1/1/2002,     40256489, delhi,      IT,     3000,     ,          ,          , ,
2,     rama,     1/2/2002,     40256488, mumbai,     Marketing,     5000,     10 ,     [email protected], 1-1-1600,     ,      
3,     sita,     1/3/2003,     40256483, chennai,     insurance agent,     , [email protected],          , male,     lic
in 11g i can use pivot , but how to achieve this in 10g ( 10.2.0.4.0 )
Edited by: user7955917 on May 23, 2012 8:28 AM

create table table_a(
    id          number,
    name        varchar2(20),
    hiredate    date);
insert into table_a values(1, 'archana', to_date('01/01/2002', 'dd/mm/yyyy'));
insert into table_a values(2, 'sita', to_date('01/02/2002', 'dd/mm/yyyy'));
create table table_b(
    id          number,
    property    varchar2(40),
    value       varchar2(40)
insert into table_b values(1, 'phone', '40256489');
insert into table_b values(1, 'location', 'delhi');
insert into table_b values(2, 'phone', '40256488');
insert into table_b values(2, 'job', 'Marketing');
select a.id,
       a.name,
       a.hiredate,
       max(case when b.property = 'phone' then b.value else null end) as phone,
       max(case when b.property = 'location' then b.value else null end) as location,
       max(case when b.property = 'job' then b.value else null end) as job     
from table_a a,
     table_b b
where a.id = b.id
group by a.id,
         a.name,
         a.hiredate;

Similar Messages

  • How to numberformat when using sql:query alogn with c:forEach JSTL tags

    Is there anyway to format the numeric values returned from the database when using <sql:query> alogn with <c:forEach> tags
    Here is my jsp code
    <sql:query..../>
    <c:forEach var="row" items="${queryResults.rows}">
    <tr>
    <td><c:out value="${row.COL1}" /></td>
    <td><c:out value="${row.COL2}" /></td>
    </tr>
    </c:forEach>
    Col1 values are numeric without any formats Eg: 1000, 10000, 1000000 etc.
    how can i format them to 1,000 , 10,1000 , 100,000 etc

    It is polite to mention what your answer was. These posts are not just here for you to ask questions, but to be used as a resource for other people to find answers. Saying "I solved it" with no details helps noone.
    I presume you discovered the JSTL <fmt:formatNumber> tag?

  • SQL Query Result with Random Sorting

    Hi Experts,
    My Oracle Version : Oracle9i
    I have three tables which are given below,
    Table Name:     check_team
    team_id      team_code
    100          A
    101          B
    102          C
    103          D
    Table Name:     check_product
    product_id     product_code
    1          XXX
    2          XYZ
    Table Name:     check_team_products
    tprod_id     tprod_team_id     tprod_product_id
    1          100          1
    2          100          2
    3          101          1
    4          101          2
    5          102          1
    6          102          2
    7          103          1
    8          103          2
    Required Output First Time:
    team_id   team_code   product_id   product_code
    100       A           1             XXX
    101       B           2             XYZ
    102       A           1             XXX
    103       B           2             XYZ
    Required Output Second Time:
    team_id   team_code   product_id   product_code
    100       B           2             XYZ
    101       A           1             XXX
    102       B           2             XYZ
    103       A           1             XXXI need the result as Required Output specified above and also the result has to be random too.. Can someone help me in writing a SQL Query to get results as that?
    Added Oracle Version

    So, is it something like this you want?
    SQL> ed
    Wrote file afiedt.buf
      1  with check_team as (select 100 as team_id, 'A' as team_code from dual union all
      2                      select 101, 'B' from dual union all
      3                      select 102, 'C' from dual union all
      4                      select 103, 'D' from dual)
      5      ,check_product as (select 1 as product_id, 'XXX' as product_code from dual union all
      6                         select 2, 'XYZ' from dual)
      7      ,check_team_products as (select 1 as tprod_id, 100 as tprod_team_id, 1 as tprod_product_id from dual union all
      8                               select 2, 100, 2 from dual union all
      9                               select 3, 101, 1 from dual union all
    10                               select 4, 101, 2 from dual union all
    11                               select 5, 102, 1 from dual union all
    12                               select 6, 102, 2 from dual union all
    13                               select 7, 103, 1 from dual union all
    14                               select 8, 103, 2 from dual)
    15  --
    16  -- end of test data
    17  --
    18  select team_id, team_code, product_id, product_code
    19  from (
    20        select t.team_id, t.team_code, p.product_id, p.product_code
    21              ,row_number() over (partition by team_id order by dbms_random.random()) as rn
    22        from check_team t join check_team_products tp on (tp.tprod_team_id = t.team_id)
    23                          join check_product p on (p.product_id = tp.tprod_product_id)
    24       )
    25* where rn = 1
    SQL> /
       TEAM_ID T PRODUCT_ID PRO
           100 A          2 XYZ
           101 B          1 XXX
           102 C          2 XYZ
           103 D          1 XXX
    SQL> /
       TEAM_ID T PRODUCT_ID PRO
           100 A          2 XYZ
           101 B          1 XXX
           102 C          2 XYZ
           103 D          1 XXX
    SQL> /
       TEAM_ID T PRODUCT_ID PRO
           100 A          1 XXX
           101 B          2 XYZ
           102 C          1 XXX
           103 D          1 XXX

  • SQL query slow with call to function

    I have a SQL query that will return in less than a second or two with a function in-line selected in the "from" clause of the statement. As soon as I select that returned value in the SQL statement, the statement takes from anywhere from 2 to 5 minutes to return. Here is a simplified sample from the statement:
    This statement returns in a second or 2.
    select A.pk_id
    from stu_schedule A, stu_school B, stu_year C, school_year D,
    (select calc_ytd_class_abs2(Z.PK_ID,'U') ytd_unx
    from stu_schedule Z) II
    where B.pk_id = A.fk_stu_school
    and C.pk_id = B.fk_stu_year
    and D.pk_id = C.year
    and D.school_year = '2011';
    if I add this function call in, the statement runs extremely poor.
    select A.pk_id,
    II.ytd_unx
    from stu_schedule A, stu_school B, stu_year C, school_year D,
    (select calc_ytd_class_abs2(Z.PK_ID,'U') ytd_unx
    from stu_schedule Z) II
    where B.pk_id = A.fk_stu_school
    and C.pk_id = B.fk_stu_year
    and D.pk_id = C.year
    and D.school_year = '2011';
    Here is the function that is called:
    create or replace FUNCTION calc_ytd_class_abs2 (p_fk_stu_schedule in varchar2,
    p_legality in varchar2) return number IS
    l_days_absent number := 0;
    CURSOR get_class_abs IS
    select (select nvl(max(D.days_absent),'0')
    from cut_code D
    where D.pk_id = C.fk_cut_code
    and (D.legality = p_legality
    or p_legality = '%')) days_absent
    from stu_schedule_detail B, stu_class_attendance C
    where B.fk_stu_schedule = p_fk_stu_schedule
    and C.fk_stu_schedule_detail = B.pk_id;
    BEGIN
    FOR x in get_class_abs LOOP
    l_days_absent := l_days_absent + x.days_absent;
    END LOOP;
    return (l_days_absent);
    END calc_ytd_class_abs2;

    Query returns anywhere from 6000 to 32000 rows. For each of those rows a parameter is passed in to 4 different functions to get ytd totals. When I call the functions in the in-line view but do not select from them in the main SQL, the report (oh, this is Application Express 4.0 interactive reports, just an FYI) runs fast. The report comes back in a few seconds. But when I select from the in-line view to display those ytd totals, the report runs extremely slow. I know there are the articles about context switching and how mixing SQL with PL/SQL performs poorly. So I tried a pipeline table function where the function for the ytd totals populate the columns of the pipeline table and I select from the pipeline table in the SQL query in the interactive report. That seemed to perform a little worse from what I can tell.
    Thanks for any help you can offer.

  • Problem in executeQuery(SQL query sentence with a ' );

    for example:
    String strName="";
    //here strName is searching key value.
    String strQueryString="SELECT * FROM Authors WHERE name='" strName "'";
    ResultSet rs=st.executeQuery(strQueryString);
    if strName value is "yijun_lee",that will return all information which the name columns value is "yijun_lee" with SQL Query sentence SELECT * FROM Authors WHERE name='yijun_lee'
    but if strName value is "yijun ' lee",that value contains a '.that will error!
    how to do?
    thanks very much!

    You could parse <strName > and insert another ' for each '
    A concrete example would be SELECT * FROM Authors WHERE name='yijun '' lee'HTH

  • SQL query result with HTML Data in output

    Hello,
    I have a SQL table , in one column I store HTML data. I need to query the table and get the HTML data in the columns that have 'HREF'. The output shows as grid on the sql management studio, however when I export it to excel, the HTML data does not get copied
    correctly, since there are HTML tags etc.
    How can I export the report correctly from SQL ?

    Hello,
    The HTML data is stored in a column with datatype as nvarchar(max). Sample data in the column is shown below. It is with formatting etc and is rendered as is on the web page. the business wants to generate a quick report so that they can see the pages that
    have links displayed. I can do that by querying the columns that have a 'HREF' in the text.
    Can I get the exact HREF values using just sql query? There can be more than one links on a page.
    Also, If I just want to copy the whole column and paste it on excel, how can I do that? If I copy the data below and paste, it does not get copied in one cell.. it spreads across multiple cells, so the report does not make any sense.
    <br />
    <table border="0" cellpadding="0" cellspacing="0" style="width: 431pt; border-collapse: collapse;" width="574">
    <tbody>
    <tr height="19" style="height: 14.25pt; ">
    <td height="19" style="border: 0px blue; width: 431pt; height: 14.25pt; background-color: transparent;" width="574"><a href="https:"><u><font color="#0066cc" face="Calibri">ax </font></u></a></td>
    </tr>
    </tbody>
    <colgroup>
    <col style="width: 431pt; " width="574" />
    </colgroup>
    </table>

  • SQL Query execution with LISTAGG

    Hello,
    I am trying to get some data using LISTAGG functionality.
    I have below query with works fine with the table, but not with the rowsource which is based on same table.
    SELECT COL1,LISTAGG(COL3, ',') WITHIN GROUP (ORDER BY COL2) AS fieldName FROM IOP_Sample_RS GROUP BY COL1it gives parsing error
    line 1:22: expecting "FROM", found '('col 22 is '(' of LISTAGG function.
    One more Question
    Does UNION, MINUS works with RSQL in IOP?
    Thanks,
    Sumant Chhunchha.
    Edited by: Sumant on Jun 15, 2011 5:04 AM

    LISTAGG, UNION, MINUS is not supported with RSQL, instead you can massage your SQL query to load data into IOP and then use a simple RSQL query.

  • ORA-06502 on  'SQL query' report with sort in 'Report Attributes'

    Hi All,
    We get the next error if we set sorting on a column in a 'Report' based on a 'SQL query'. Removing the sort, error disappeares:
    failed to parse SQL query:
    ORA-06502: PL/SQL: numeric or value error: NULL index table key value
    Any suggestions?
    Erik

    Erik,
    Thanks, this explains it. By specifying the request as part of your URL you run into the recently uncovered issue. The request you're setting is REMFROMLIST and ADD2LIST. You probably either have links that include those requests or you have branches where you specify them. Either way, in order to get reports sorting to work, you'll have to make sure that the request strings are not part of your URL. This is a work-around and the upcoming HTML DB patch release will solve this issue.
    One way of avoiding this is to have computations on the previous pages that set a napplication level or page level item to the REMFROMLIST and ADD2LIST values and then you can use those items for your conditions that are currently evaluating those strings.
    Hope this helps and sorry for the inconvenience,
    Marc

  • SQL query problem with sorting

    Hi,
    I have question regarding sql query . Right now I am getting the results like this if i use this sql query
    select ID,Name,Desc,Priority from emp order by Priority ;
    Priority is varchar field. I don't want to change the Priority field and cannot add a new column in the table. Because i don't have permission to do that.
    ID Name Desc Priority
    =============================================
    234 paul paul desc Highest
    3452 mike mike desc High
    4342 smith smith desc Low
    6565 kelly kelly desc Low
    9878 nate nate desc Medium
    3223 deb deb desc High
    ============================================
    I need a query to get the results like that.
    ID Name Desc Priority
    =============================================
    234 paul paul desc Highest
    3452 mike mike desc High
    3223 deb deb desc High
    9878 nate nate desc Medium
    4342 smith smith desc Low
    6565 kelly kelly desc Low
    ============================================
    If any one knows about this one, please let me know.
    Thanks,
    Bala

    You are aware that there are differences in the SQL implementation between Sqlserver and Oracle? You could try something like this, if there's a INSTR function:
    ORDER BY INSTR('Highest,High,Medium,Low,', Priority || ',')You may have to change the "Priority || ," to a "Priority + ','), if string concatenation is done differently in sqlserver. Don't know about the ('), maybe you need (").
    C.

  • SQL Query issue with large varchar column

    I have a SQL Query (PL/SQL function body returning SQL query) which contains a large varchar column. Even if I substring the column to 30chars when it displays on the page it wraps. I have tried putting nowrap="wrap" for the HTML table cell attributes and it still wraps. I have tried setting the width attributes on the column even though it's not an updateable column. Does anyone have any ideas on how prevent this from wrapping. In some cases 1 line will take up 3 because of this wrapping issue and it's not nice to look at. It seems that the column is somewhere set to a fixed width, which is less than 30 characters, and anything beyond this fixed width wraps.

    Hi Netha,
    Can you please provide the DDLs of three tables you are using,
    Also post us how many rows you are getting output for this query? 
    select * from dim.store st where
    st.store_code = 'MAUR'
    also try to run and update statement on this table as below and execute your query
    update dim.store
    set store_code
    = ltrim(rtrim(store_code))
    where
    store_code = 'MAUR'
    once you run this update, then run your query.  Let us know the result.

  • SQL Query problems with Mysql - possible Java bug

    I have a query that works fine on mysql, but does not work in my jsp page.... my db connection and all that jazz is fine.
    select somefields from table order by (integerfield / doublefield)
    two notes... the query works without the order by. And the query works with the order by when I'm working directly with the db. Any ideas? This is driving me nuts!!!!
    Thanks,
    Tyson

    Nevermind, just a dumb mistake... finally figured it out.

  • SQL query join help

    I have two tables DEVICE and CONTACT. The tables are joined DEVICE_ID to CONTACT_ID. I want to print device_ID and the corresponding contact info with the lowest CONTACT.PRIORITY.
    SQL> describe DEVICE;
    DEVICE_ID              NOT NULL VARCHAR2(50)
    SQL> describe CONTACT;
    CONTACT_ID               NOT NULL VARCHAR2(50)
    CONTACT_TYPE             NOT NULL VARCHAR2(4)
    PRIORITY                 NOT NULL DOUBLE PRECISION
    LASTNAME                 NOT NULL VARCHAR2(30)
    FIRSTNAME                NOT NULL VARCHAR2(80)
    SQL> SELECT a.DEVICE_ID, b.LASTNAME,b.PRIORITY from DEVICE a, CONTACT b where a.DEVICE_ID = 'DEVICEA' and a.DEVICE_ID=b.CONTACT_ID(+);
    DEVICE_ID              LASTNAME    FIRSTNAME PRIORITY CONTACT_TYPE
    DEVICEA                CONTACT1     GN               1 ROUT
    DEVICEA                CONTACT2     Hans             2 ROUTHow do I print just one record with the lowest CONTACT.PRIORITY?
    Thanks
    Ravi

    rmalghan wrote:
    Thanks Frank, Sundar and Sean. I got the below 3 to work. Two questions. My DEVICE table has 31936 records.
    1. The first one returned 30207, 2nd 31936 records and 3rd one 30348. Since the 2nd one result looks like what I expected, the 1st and 3rd one seem to be missing some records. For troubleshooting, I tried to limit the query for a few devices, but can't seem to figure why the difference. Any suggestions? The 2nd query is not checking for CONTACT_TYPE = 'ROUT', so it's not surprising that it returns more rows.
    The 3rd query is effectively doing an inner join. The condition "WHERE c.rnum = 1" is being applied after the join, so it rejects all the rows that were added because of the outer join (that is, where all the columns from c are NULL). You probably meant:
    LEFT OUTER JOIN got_rnum c ON  d.DEVICE_ID     = c.CONTACT_ID
                               AND c.rnum          = 1; without a WHERE clause.
    2. Is there benefit in terms of efficiency. The 2nd one does seem to run faster so I am guessing that is the best. Any comments?
    SELECT a.DEVICE_ID, b.LASTNAME,b.FIRSTNAME,b.PRIORITY
    FROM DEVICE a, CONTACT b
    where
    a.DEVICE_ID=b.CONTACT_ID(+) and
    b.CONTACT_TYPE = 'ROUT' and
    b.PRIORITY = (select min(b1.PRIORITY ) from CONTACT b1 where b1.CONTACT_ID = b.CONTACT_ID);
    30207 rows selected (10.12 seconds)
    SELECT DEVICE_ID, LASTNAME, PRIORITY
    FROM (
    SELECT a.DEVICE_ID, b.LASTNAME, b.PRIORITY, ROW_NUMBER() OVER (PARTITION BY a.DEVICE_ID ORDER BY b.PRIORITY) row_num
    from DEVICE a, CONTACT b
    where a.DEVICE_ID=b.CONTACT_ID(+))
    WHERE row_num = 1;
    31936 rows selected (6.68 seconds)
    WITH got_rnum AS (
    SELECT LASTNAME, FIRSTNAME, PRIORITY, CONTACT_TYPE, CONTACT_ID,
    ROW_NUMBER () OVER ( PARTITION BY  CONTACT_ID ORDER BY priority) AS rnum
    FROM contact
    where CONTACT_TYPE = 'ROUT'
    SELECT d.DEVICE_ID, c.LASTNAME, c.FIRSTNAME, c.PRIORITY
    FROM device d
    JOIN got_rnum c ON d.DEVICE_ID     = c.CONTACT_ID(+)
    WHERE c.rnum = 1;
    30348 rows selected (9.07 seconds)
    Timing that way isn't very accurate. Whichever one you run first is apt to be slower, because the data is less likely to be cached in memory.
    The 2nd query has only 3 columns in the result set. That probably doesn't change the speed much, but you should fix it anyway.

  • SQL Query join problem

    Hi,
    I have two tables in my db, the patient table holds details of patients, the contact table holds details of contacts related to the patient.
    patient table
    patientid - primary key - int
    patient name - varchar
    contact table
    contactid - primary key - int
    patientid - foreign key from patient table - int
    incontact - foreign key from paient table to relate contacts - int
    My contact table has the following data:
    contactid patientid incontact
    2              19           21
    2               19          22
    I can retrieve data for the patients that have been in contact with patientid 19, by using the following join:
    SELECT * FROM PATIENT
    LEFT JOIN incontact
    ON incontact.incontact = patient.patientid
    WHERE incontact.patientid = 19
    However, can you please tell me how I can get data from the patients table where the incontact is 21?
    So I can get contacts from patients and patients from contacts?
    Thankyou

    Thanks very much for your replies again.
    Basically, I have a table of patients, and I would like to link them to each other, many to many.
    I populate the incontact table, which stores the original posted patientID, and the new generated patientID. I populate the DB with the code below.
    <cfquery name="update" datasource="staffdirectory">
    SET NOCOUNT ON
    INSERT INTO patient (title,firstname,surname,gender,DOB,telephone,address1,address2,address3,town,postcode
    VALUES ('#title#','#firstname#','#surname#','#gender#',#createodbcdate(createdate(startyear, startmonth, startday))#    ,'#telephone#','#address1#','#address2#','#address3#','#town#','#postcode#
    SELECT @@Identity AS newid   
    SET NOCOUNT OFF
    </cfquery>
          <cfquery name="insert" datasource="staffdirectory">
      INSERT INTO incontact (related,incontact)
    VALUES (#patientid#,#update.newid#)
    </cfquery>
    This works fine and I can get all related patients by usingthe following query:
    SELECT * FROM patient
    LEFT JOIN incontact
    ON patient.patientid  = incontact.related
    WHERE  incontact.incontact = #patientid#
    MY problem occurs when I want to find related patients from the related column, the reverse relationship. I use this seperate query:
    SELECT * FROM patient
    LEFT JOIN incontact
    ON patient.patientid  = incontact.incontact
    WHERE  incontact.related= #patientid#
    Is there a way I can combine both queries, or is there a better way I can achieve the same result?
    Many thanks again

  • SQL query validation with XML?

    Hi
    Is there anything out there that will validate an SQL statement (validate meaning the SQL statement 'will run') using XML?
    I want to make a servlet that takes SQL and adds it to a java class that will in turn do a bunch of magical things. However
    I need the SQL to be validated before it gets written to the class.
    XML seems like it would be a useful tool to accomplish this but I fear the
    document would be friggen huge and run slow as hell.
    I guess in essence it would be like creating an SQL compiler completely
    out of XML.
    Does something like this exist or is this solution just to broad to realistically consider?

    There is no kind of relashionship between SQL and XML. Moreover, with RDBMs having different flavors of SQL, how can you expect an XML parser to be able to tell you that your query will run on Oracle but non on SQL Server?

  • Sql Query Plan with ROWNUM

    Oracle 10g:
    I have a table with index, when I run that query on that index it's fine. I get into problem if I add ROWNUM in that query, query slows down from 1 sec to 30 sec. I don't know why. for eg:
    select * from (select * from A where b = 1) where ROWNUM < 1000 becomes very slow:
    Query Plan for select * from A where b = 1 (Query is just an example):
    Rows     Plan     
    208912     SELECT STATEMENT      
    208912     SORT ORDER BY      
    208912     HASH JOIN RIGHT OUTER      
    408     INDEX FULL SCAN PK_BAD_ACK_TASK     
    208912     HASH JOIN RIGHT OUTER      
    16     INDEX FULL SCAN PK_INFORMATIONAL_TASK     
    208912     HASH JOIN RIGHT OUTER      
    1     INDEX FULL SCAN PK_SYSTEM_ERROR_TASK     
    208912     HASH JOIN RIGHT OUTER      
    1     INDEX FULL SCAN PK_REJECTED_TRANSMISSION     
    208912     HASH JOIN RIGHT OUTER      
    1     INDEX FULL SCAN PK_ONHOLD_TASK     
    208912     HASH JOIN RIGHT OUTER      
    329465     INDEX FAST FULL SCAN PK_FAILED_MESSAGE     
    208912     TABLE ACCESS FULL TASK     
    Query when I add ROWNUM (slow query as mentioned above):
    Rows     Plan     
    999     SELECT STATEMENT      
    <NULL>     COUNT STOPKEY      
    208912     VIEW      
    208912     SORT ORDER BY STOPKEY      
    208912     HASH JOIN RIGHT OUTER      
    408     INDEX FULL SCAN PK_BAD_ACK_TASK     
    208912     NESTED LOOPS OUTER      
    208912     NESTED LOOPS OUTER      
    208912     NESTED LOOPS OUTER      
    208912     HASH JOIN RIGHT OUTER      
    329465     INDEX FAST FULL SCAN PK_FAILED_MESSAGE     
    208912     HASH JOIN RIGHT OUTER      
    16     INDEX FULL SCAN PK_INFORMATIONAL_TASK     
    208912     TABLE ACCESS FULL TASK     
    1     INDEX FAST FULL SCAN PK_ONHOLD_TASK     
    1     INDEX FAST FULL SCAN PK_REJECTED_TRANSMISSION     
    1     INDEX FAST FULL SCAN PK_SYSTEM_ERROR_TASK

    user628400 wrote:
    Oracle 10g:
    I have a table with index, when I run that query on that index it's fine. I get into problem if I add ROWNUM in that query, query slows down from 1 sec to 30 sec. I don't know why. for eg:Some notes:
    * When using ROWNUM the cost based optimizer switches to a FIRST_ROWS_N mode, this might explain the significant difference in the execution plan
    * Try to get a more meaningful output using DBMS_XPLAN.DISPLAY
    * Since you're already on 10g, try to compare the actual cardinalities to the estimates using DBMS_XPLAN.DISPLAY_CURSOR with the "ALLSTATS LAST" option and the GATHER_PLAN_STATISTICS hint.
    See e.g. here for more information how to do it: http://jonathanlewis.wordpress.com/2006/11/09/dbms_xplan-in-10g/
    This way you should be able to tell where the optimizer assumptions go wrong so that it thinks that the second one is better than the first one
    A simple remedy you might want to try that should get you back to plan 1 is the following:
    select * from (
    select ROWNUM as rn, a.* from (select * from A where b = 1 ORDER BY<your_order_criteria>) a
    where rn < 1000;Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/
    Edited by: Randolf Geist on Jan 11, 2009 9:33 PM
    Added the obvious sort ORDER BY

Maybe you are looking for

  • Collection Authorization

    Dear SAP friends, There is a field "collection authorization" in the Customer and Vendor master data, under the payment transactions. What is the function of this field? If we check this, how will it work? What else to do for this? Points will be ass

  • HT2513 Can you publish a calendar using an ipad?

    Can I publish a calendar from my ipad?

  • HT4623 I keep getting a no service signal and it keeps running

    I weep getting a no signal in the upper left hand corner. I have wifi but it won't connect.

  • Hide 'Portal Favorites' iView

    Hi Guys,   I know to hide the Portal Favourites iView on everypage, you can: Content Admin > Portal Conten » Portal Users » Standard Portal Users » FrameworkPage (Edit Object) » InnerPage (Edit) » Portal Favorites (uncheck the visible checkbox) It di

  • Yahoo! Messenger weirdness

    Ever since I updated to 10.4.11, there have been a few small things that are weird, but I'm most annoyed at what is happening with my chat window in Y!M Version 3 Beta. The new chat text is added to the bottom of the body of text, but then it doesn't