Your estimated performance of a very simple SQL query

Hi there..
Sometimes it seems hard to find answers for the most simple questions so I hope you can help me and be overbearing ;)
I am going to have a table with a few million records in it, 30-40 columns of which 80% has data, indexes on maybe 10 columns (certainly the columns I am querying), less than ten thousand new records a day with a variety of different column values and using Oracle 10 or 11.
I am going to be running a single SQL SELECT statement quite regularily against these records to retrieve all records whose value of a single column is the same (and specified in my WHERE clause)
It will be a query like this; SELECT * FROM person where city = 'Amsterdam' AND
The column 'city' will have a simple index on it. 4-8 records will have the same value (e.g. there will only be up to 8 rows where city is 'Amsterdam' in the above example) which means that with 5 million records I will probably have between 625,000 and 1,250,000 "sets" that I am querying and retrieving per SQL. Thed atatype could be varchar or number - not sure yet.
I will retrieve the same data a lot but generally also access all the other data on a regular basis.
How should I expect this to perform? Always fast I imagine because will there will be any table scans do we think? I don't have to think about partitioning of too regular statistic calculation or anything? Anything to watch out for?
Any feedback would be greatly appreciated.
Thanks a lot in advance.
Daniel

It's impossible to tell without seeing a true structure and indexes etc.
It sounds ok at a first read. High selectivity, low cardinality, low skewing. Obviously, ensuring stats are up to date on a reasonably regular basis is a good idea, especially with 10,000+ records added daily. I would expect it to perform ok.

Similar Messages

  • Simple SQL Query and Parameters and LOV

    Newbie and trying to work thru building a simple sql query with a single table query and use a parameter and lov.
    Can anyone point me to an example.
    simple query:
    select cust_id, name_desc, name_add1, name_add2, name_city
    from customer_table
    where cust_id = :cust_parm
    This works in straight sql and in the query builder by prompting for the customer ID. When building a parameter using LOV or search, it doesn't seem to detect the variable.
    Thanks..
    DD

    If you are using version 11g, then as soon as you save the query in the data model, it should notice the parameter and ask if you want to add the parameter to the data model. What version of BIP are you using?
    What happens if you exclude the parameter from the query and simply hard-code the criteria? Can you generate XML data?
    From your wording, it sounds like you're trying to create a parameter from the LOV dialog. LOVs and parameters are totally distinct. After each are created separately, then you configure the parameter to use the LOV.

  • Simple SQL query statement is needed

    I need a simple SQL query to fetch records which is existed in all the departments.
    for example: i want to list the employees which are existed in each and every department.. not sure how should i get those.. will anyone help me please.. thanks in advance

    I think it would be wise to go to the following training:
    Oracle Database <version> : Introduction to SQL
    You will get the information you are looking for in five days. You can go find a tutorial on ANSI SQL, as advised by this board for free, to fix your immediate problem with a simple query. But, I personally recommend a more formal class specific to Oracle, as you will also get information about PL/SQL, and you get the benefit with working with other DBA/programmers when you are learning. This will solve your immediate issue, and any future issues with the language.
    You can find it in the Education section of the Oracle website.

  • Performance of OBIEE report whereas SQL query behind it executed in 1-2 min

    Facing lot of performance issues in OBIEE reports, whereas SQL query behind the report fetch data in 2-3 minutes. Reprot take around 1-2 hrs. Can anyone help to resolve this please?

    (my 2c worth)... if the physical query runs for a reasonably short time but the report takes much longer to return it suggests the rendering process (ie. pivot view) is lagging.
    To test this theory, go into Answers and remove all views from the request and leave a simple table view on the compound view. Run the report and the report should return around the same time the physical request takes to run because the table view is a very raw, un aggregated rendering process. Table views are nice and fast. If that works then you can focus on tuning your other views, ie. Pivot view. I've seen a simple pivot view take minutes to render what looks like a simple report because the underlying recordset is quite large.
    I hope this helped. another quick trick you could try is applying aggregation in the formulas to aggregate things at the physical sql level so the returning result set isn't 5,000. depends what you're up to with the end report.
    Edited by: user8300108 on 25-Feb-2010 04:40

  • Very Slow SQL query - Fast in SSMS

    We have a very simple query that executes instantly in SSMS, returning about 45,000 rows.  Whenever I run the same query on a CFM page it takes about 47 seconds to execute.
    I've tried reindexing, turning it into a stored procedure, etc.. but nothing seems to help.   My other queries are also running a little slower, but not nearly as noticeable because they are smaller queries.
    I have an additional CF10 server that seems to run the query perfectly fine on a test page.
    The query is pretty much this:
    Select X,Y,Z
    FROM TABLE
    WHERE BLAH BLAH BLAH
    Can someone offer me some advice on what can cause this or how to find the issue?
    Thanks!

    Just an update.  It ended up being "something" to do with the CF machine, although still not sure what exactly.
    Ended up solving the issue by installing CF on identical hardware and patching to the same windows and CF versions.   The site is now running like a champ and loading pages in less than 1 second.
    Steve, I have a dynamic filter that I run a query of query on the 45k rows to generate.  Once the first option is selected, it takes the distinct rows from the original query were x = selection and there can be 10-12 sub options to narrow down inside of that data.  It seems to load much faster this way than by returning to SQL server each time a response is selected.
    Thanks for your suggestions.  Hopefully we don't have the issue again... whatever it was.

  • Simple SQL query SQL developer takes it, The wizzard of XE does not

    Hello everybody
    I wrote this simple query which SQL developer runs fine, but when I try to launch a Report based on this sql query it tells me invalid sql statement. That is true, it may be invalid because this IF clause in there..but SQL developer seems to be very tolerant or understands more...
    the reason I wrote that is because obviously if there are no bosses, ie = 0 then i would get an error when dividing it by 0, so I put that 0 just to select the good ones
    if count (bosses) >0
    select company, postcode,
    sum( bosses/staff)
    from evaluation
    group by company, postcode
    Thank you very much
    Alvaro

    oh yes (blushed in shame as how dumb i looked like) i knew about the denominator 0 and infinite as as result i just didnt notice my zero was on the numerator :(
    however, i run the query and i got this message in sql developer
    Error starting at line 1 in command:
    select company, postcode,
    case when staff != 0 then sum( bosses/staff) end
    from evaluation
    group by company, postcode
    Error at Command Line:2 Column:10
    Error report:
    SQL Error: ORA-00979: not a GROUP BY expression
    00979. 00000 - "not a GROUP BY expression"
    *Cause:   
    *Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Zimbra login is very slow - SQL query takes 35+ seconds

    Hi,
    my Zimbra login process remains very slow, 35-40 seconds with only a single user using it. I have Beehive set up as directory synchronized, with about 6500 users in it. However, I and a couple of colleagues the only ones making any use of it for testing. With just one person logging in, the following SQL query takes about 35 seconds to execute:
    SELECT /*+ LEADING(rf rf_pp) USE_NL(rf_pp) INDEX_ASC(@rf_connect_by rf@rf_connect_by (ws_real_folders.parent_eid ws_real_folders.eid)) */ RF.ENTERPRISE_ID AS
    ENTERPRISE_ID, RF.SITE_ID AS SITE_ID, RF.ENTITY_TYPE AS ENTITY_TYPE, RF.EID AS EID, RF.LOCK_ID AS LOCK_ID, RF.CACHE_ID AS CACHE_ID, RF.CACHE_TS AS
    CACHE_TS, RF.CACHE_SQ AS CACHE_SQ, FLOOR(RF.SECURE_CHECK/10) AS ACCESS_TYPES, RF.PARENT_ENTITY_TYPE AS PARENT_ENTITY_TYPE, RF.PARENT_EID AS
    PARENT_EID, RF.NAME AS NAME, RF.OWNER_ENTITY_TYPE AS OWNER_ENTITY_TYPE, RF.OWNER_EID AS OWNER_EID, RF.CREATED_ON AS CREATED_ON,
    RF.CREATOR_ENTITY_TYPE AS CREATOR_ENTITY_TYPE, RF.CREATOR_EID AS CREATOR_EID, RF.MODIFIEDON AS MODIFIED_ON, RF.MODIFIED_BY_ENTITY_TYPE AS
    MODIFIED_BY_ENTITY_TYPE, RF.MODIFIED_BY_EID AS MODIFIED_BY_EID, RF.VISIBILITY AS VISIBILITY, CASE WHEN (BITAND(:B13 , :B12 ) = :B12 ) THEN CAST(MULTISET(
    SELECT METADATA_CEN
    FROM OCS_ENTITY_METADATA_CENS_2_V META
    WHERE META.ENTITY_EID = RF.EID ) AS OCS_COLLAB_ID_TBL_T) ELSE CAST(NULL AS OCS_COLLAB_ID_TBL_T) END AS METADATA_CENS, CASE WHEN
    RF_PP.LAST_ACCESSED IS NULL THEN 'N' WHEN RF.MODIFIEDON > RF_PP.LAST_ACCESSED THEN 'U' ELSE NVL(RF_PP.RELATIVE_STATUS, 'N') END AS CHANGE_STATUS,
    RF.PROPERTIES AS PROPERTIES_CLOB, RF_PP.PROPERTIES AS VIEWERPROPERTIES_CLOB, RF.DESCRIPTION AS DESCRIPTION
    FROM (
    SELECT /*+ QB_NAME(rf_connect_by) no_connect_by_cost_based */ RF.ENTERPRISE_ID ENTERPRISE_ID, :B4 SITE_ID, :B3 ENTITY_TYPE, RF.EID EID, RF.LOCK_ID LOCK_ID,
    RF.ORA_ROWSCN CACHE_ID, RF.CACHE_TS CACHE_TS, RF.CACHE_SQ CACHE_SQ, RF.PARENT_TYPE PARENT_ENTITY_TYPE, RF.PARENT_EID PARENT_EID, RF.NAME
    NAME, RF.OWNER_TYPE OWNER_ENTITY_TYPE, RF.OWNER_EID OWNER_EID, RF.CREATED_ON CREATED_ON, RF.CREATOR_TYPE CREATOR_ENTITY_TYPE,
    RF.CREATOR_EID CREATOR_EID, RF.MODIFIED_ON MODIFIEDON, RF.MODIFIED_BY_TYPE MODIFIED_BY_ENTITY_TYPE, RF.MODIFIED_BY_EID MODIFIED_BY_EID,
    RF.VISIBILITY VISIBILITY, RF.PROPERTIES PROPERTIES, RF.DESCRIPTION DESCRIPTION, RF.IS_HIDDEN IS_HIDDEN, LEVEL LEVEL_NUM, COALESCE (
    (SELECT :B10 * 10 + 1
    FROM AC_ENTITIES AEI
    WHERE RF.EID = AEI.EID AND ( 1 = DECODE(AEI.SENSITIVITY_EID, :B9 , 1, 0) AND 1 = DECODE(AEI.OWNER_EID, :B8 , 1, 0) AND 1 = DECODE(AEI.AT_READ, :B7 , 1, 0) AND 1 =
    DECODE(AEI.AT_DISCOVER, :B6 , 1, 0) AND 1 = DECODE(AEI.LOCAL_ACL_ID, :B5 , 1, 0) ) ) ,
    (SELECT ACV.ACCESS_TYPES * 10 + ACV.IS_ALLOWED
    FROM AC_CHECK_ONE_OF_V ACV
    WHERE ACV.EID = RF.EID ) ) SECURE_CHECK
    FROM WS_REAL_FOLDERS RF
    WHERE RF.IS_HIDDEN = :B2 START WITH RF.PARENT_EID = :B1 CONNECT BY PRIOR RF.EID = RF.PARENT_EID ) RF, WS_RF_PRVT_PROPERTIES RF_PP
    WHERE RF.EID = RF_PP.EID (+) AND :B11 = RF_PP.VIEWER_EID (+) AND 1 = BITAND(RF.SECURE_CHECK, 1) ORDER BY RF.LEVEL_NUMIt has ID atrvjdrmz2v6d in Enterprise Manager, and I've tried tuning it with the SQL tuning advisor in EM. I did the statistics gathering mentioned in another thread yesterday, to see if that helped - doesn't seem liked it. I'm running Database 11.1.0.6 and Beehive 1.5.1 in the build from the day it released.
    Any hints? I'll post this to MetaLink as well, unless someone has some immediate idea what's wrong :-)

    No speedup, the 35-40 seconds is for normal logins - and it's very consistent, at least if the database is otherwise idle. Immediately logging out and back in gives me the same wait, and the same query shows up in the Enterprise Manager interface.
    It seems it might be related to Workspaces - from EM:
    "PL/SQL Source (Line Number)          BEE_CODE.WS_REAL_FOLDER_PKG (2998)"

  • A simple SQL query question

    I have an interesting problem and wondering how I can get this result in a single SQL query:
    Here is table emp has data with a row for every year since the employee joined with the salary paid that particular year with following columns:
    emp (
    id varchar2(10),
    name varchar2(25),
    interested_year date,
    salarypaid number(10)
    I would like to print the results as follows:
    id name previousyear_salarypaid currentyear_salarypaid
    x xxxxx xxxxxx xxxxx
    Is this possible to do? I have tried to simplify my actual problem so I hope I have included all necessary details.

    Just to clarify, the columns mentioned in the results are
    previousyear_salarypaid is nothing but
    salarypaid where interested_year = '2007'
    currentyear_salarypaid is nothing but
    salarypaid where interested_year = '2006'

  • Simple SQL Query is not using Bitmap index

    Hello to All,
    We are having Oracle9i Database and using it for the datawarehouse purpose.
    I have created the bitmap index on calledinfo column and I am running the following simple query which takes serveral hours to complete:
    select * from ssp.ssp_2006_q4 where calledinfo='799992515f'
    OR
    select calledinfo from ssp.ssp_2006_q4 where calledinfo='799992515f'
    I don't know why it is not using the bitmap index: Can anybody help me here?
    Thanks in Advance
    Hashim

    I know why and everyone that has read Jonathan Lewis' book on the CBO knows why.
    Why? Because the CBO thinks the cost of using your index will be higher than the cost of ignoring it.
    To see what Oracle is thinking run an explain plan using DBMS_XPLAN for create the output and then rerun it with a hint forcing index usage.
    It is a mistake to believe that an index will always make things better. Issues of cardinality, clustering factor, etc. are very important.
    Post the explain plans if you have any questions about what they show:
    http://www.psoug.org/reference/explain_plan.html

  • Probably a simple SQL Query - Newbie

    I want to select entries from a table that has 2 columns where the first column value is contained within the 2 column....Does that make sense?
    The first is a varchar that contains a value for a customer. The second is a varchar that contains a a textual description of a problem the customer has. My problem is that I only want to select the entries in the table where the second column contains a description that includes the first column value.
    eg. I want to select rows that have the following condition:
    column1 has value of "customer1"
    column2 has a value of "an error was reported by customer1 on service blah"
    but not these
    column1 has value of "customer1"
    column2 has a value of "an error was reported by customer2 on service blah"
    This is probably a simple question but I've spent time looking at how to do it and can't seem to manage...any help would be appreciated....Thanks

    Hi Barbara,
    I've never used the CONTAINS operator before. I compared the use in this situation to the other methods and found the others to be FAR less resource intensive, despite working on unindexed columns, as I demonstrate below.
    It would seem that CONTAINS is unsuited to this type of simple query. Can you shed any light on this, from the perspective of somebody who has used it before? Is this type of performance penalty normal? If so, it could seem that CONTAINS is fairly useless next to LIKE.
    [email protected]> desc test;
    Name                                        Null?    Type
    COLUMN1                                              VARCHAR2(20)
    COLUMN2                                              VARCHAR2(100)
    [email protected]> select count(*) from test;
      COUNT(*)
         10000
    Elapsed: 00:00:00.00
    [email protected]> select * from test where instr(column2, column1) > 0;
    10000 rows selected.
    Elapsed: 00:00:00.18
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=23 Card=8328 Bytes=532992)
       1    0   TABLE ACCESS (FULL) OF 'TEST' (TABLE) (Cost=23 Card=8328 Bytes=532992)
    Statistics
              5  recursive calls
              0  db block gets
            821  consistent gets
              0  physical reads
              0  redo size
         702263  bytes sent via SQL*Net to client
           7838  bytes received via SQL*Net from client
            668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          10000  rows processed
    [email protected]> select * from test where column2 like '%'||column1||'%';
    10000 rows selected.
    Elapsed: 00:00:00.18
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=23 Card=8328 Bytes=532992)
       1    0   TABLE ACCESS (FULL) OF 'TEST' (TABLE) (Cost=23 Card=8328 Bytes=532992)
    Statistics
              5  recursive calls
              0  db block gets
            821  consistent gets
              0  physical reads
              0  redo size
         702263  bytes sent via SQL*Net to client
           7838  bytes received via SQL*Net from client
            668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          10000  rows processed
    [email protected]> create index testidx on test(column2) indextype is ctxsys.context;
    Index created.
    [email protected]> select * from test where contains(column2, column1) > 0;
    10000 rows selected.
    Elapsed: 00:00:56.80
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=25008 Card=4 Bytes=284)
       1    0   TABLE ACCESS (FULL) OF 'TEST' (TABLE) (Cost=25008 Card=4 Bytes=284)
    Statistics
          55201  recursive calls
              0  db block gets
          85857  consistent gets
              0  physical reads
              0  redo size
         702263  bytes sent via SQL*Net to client
           7838  bytes received via SQL*Net from client
            668  SQL*Net roundtrips to/from client
            204  sorts (memory)
              0  sorts (disk)
          10000  rows processedThanks in advance,
    Anthony

  • Simple SQL query problem

    Hi,
    I'm trying create a simple query which tells me the occurance of a particular football match on a particular date. The table is as follows...
    CREATE TABLE match
    (matchId NUMBER(5)
    CONSTRAINT match_matchId_nn NOT NULL,
    matchDate DATE
    CONSTRAINT match_date_nn NOT NULL,
    stadiumId          NUMBER(5)
    CONSTRAINT match_stadiumId_nn NOT NULL,
    CONSTRAINT matchId_pk PRIMARY KEY (matchId));
    Bascially, i'm trying to create a trigger which will implement the constraint that 'only one match can be at one stadium on a particular date'.
    Any ideas guys?
    Cheers...

    ALTER TABLE match ADD CONSTRAINT match_date_uk UNIQUE
    (stadiumId, matchDate)Bear in mind, though, that using dates in unique constraints can be problematic, because of the time element, which means there are 86400 unique values for each day. If your application enforces a rule that has only one match per stadium per day then all you need is a TRUNC() call in an insert/update trigger to make sure of that. If your application is going to allow more than one match per day the checking logic starts to get messy...
    Cheers, APC
    P.S. Oleg's solution is incorrect because it includes the primary key MatchId, which would thus permit duplicate combinations of stadium and date.

  • Execute simple SQL query on Java

    Hello,
    I am a newbie on ADF, I am a web developer used to work with EJBs, WebServices, Servlets and this stuff... But now I am on a project that uses ADF.
    My opinion, I don´t like this kind of development, drag and drop, I prefer to code on :) but, I need to work.
    I am developing a utility class that needs to run some SQL statements and send an email.
    I tried to work with the conventional @Resource (name...) Datasource ds; and did not worked, because it does not injected the object.
    I tried to create a java implementation of my application module, instanciate it and get a ViewObject that I created to do a select statement, and the ViewObject comes null...
    I just wanna do a simple query... just it, using simple java for web I would have already done it... How is the best way to do it?
    Thanks.

    ApplicationModuleImpl am = getApplicationModuleByName("AppModuleDataControl")
    DBTransaction dbt = am.getDBTransaction();
    CallableStatement cs = dbt.createCallableStatement(query, .......
    You can get ApplicationModule by this code. In this case there should be some binding related to this AM in pageDef. Input parameter "name" should be datacontrol name;
    public static ApplicationModuleImpl getApplicationModuleByName(String name) {
    try {
    BindingContext bc = (BindingContext)resolveExpression("#{data}");
    DCDataControl dc = bc.findDataControl(name);
    return (ApplicationModuleImpl)dc.getDataProvider();
    } catch (Exception e) {
    l.error(e);
    return null;
    public static Object resolveExpression(String expression) {
    l.debug("expression: " + expression);
    FacesContext fctx = FacesContext.getCurrentInstance();
    ELContext elctx = fctx.getELContext();
    ExpressionFactory exprFactory =
    fctx.getApplication().getExpressionFactory();
    ValueExpression ve =
    exprFactory.createValueExpression(elctx, expression, Object.class);
    Object value = ve.getValue(elctx);
    return value;
    }

  • Very Urgent: SQL Query Help

    Hi,
    I have a table which has location ID and text for these locations are stored in a seperate table.
    I am running query on table which has location ID but for every location I want it display its text which is stored in another table.
    How can this be done with SQL? This is a bit urgent, please help.
    Thank you,
    Raja

    might be a good idea to improve basic SQL knowledge by reading
          http://tahiti.oracle.com
          http://oreilly.com/catalog/9780596006327/index.html
          http://asktom.oracle.com
          ... whatever ...will give you some new insight about something very urgent

  • Very Complex SQL Query

    Hi,
    I have three tables
    master(m_id m_name)
    1 m1
    2 m2
    3 m3
    t1(m_id, int_type)
    1 INT(2)
    1 INT(3)
    t2(m_id, char_type)
    1 CHAR(3)
    1 CHAR(4)
    master table has m_id as a primary key, while this is foreign key in tables t1 and t2. Now i want to get the result like this.
    m1 INT(2) INT(3) CHAR(3) CHAR(4)
    [All these rows should be converted into columns]
    Thanx in Advance

    Hi,
    Here's a sample based on pivoting:TEST.SQL>CREATE TABLE MASTER
      2  (
      3       M_ID NUMBER PRIMARY KEY,
      4       M_NAME VARCHAR2(5)
      5  );
    Table created.
    TEST.SQL>INSERT INTO MASTER VALUES (1,'m1');
    1 row created.
    TEST.SQL>INSERT INTO MASTER VALUES (2,'m2');
    1 row created.
    TEST.SQL>INSERT INTO MASTER VALUES (3,'m3');
    1 row created.
    TEST.SQL>
    TEST.SQL>CREATE TABLE T1
      2  (
      3       M_ID NUMBER REFERENCES MASTER(M_ID),
      4       INT_TYPE VARCHAR2(10)
      5  );
    Table created.
    TEST.SQL>
    TEST.SQL>INSERT INTO T1 VALUES (1,'INT(2)');
    1 row created.
    TEST.SQL>INSERT INTO T1 VALUES (1,'INT(3)');
    1 row created.
    TEST.SQL>INSERT INTO T1 VALUES (2,'INT(1)');
    1 row created.
    TEST.SQL>INSERT INTO T1 VALUES (3,'INT(1)');
    1 row created.
    TEST.SQL>INSERT INTO T1 VALUES (3,'INT(2)');
    1 row created.
    TEST.SQL>INSERT INTO T1 VALUES (3,'INT(4)');
    1 row created.
    TEST.SQL>INSERT INTO T1 VALUES (3,'INT(8)');
    1 row created.
    TEST.SQL>
    TEST.SQL>CREATE TABLE T2
      2  (
      3       M_ID NUMBER REFERENCES MASTER(M_ID),
      4       CHAR_TYPE VARCHAR2(10)
      5  );
    Table created.
    TEST.SQL>
    TEST.SQL>INSERT INTO T2 VALUES (1,'CHAR(3)');
    1 row created.
    TEST.SQL>INSERT INTO T2 VALUES (1,'CHAR(4)');
    1 row created.
    TEST.SQL>INSERT INTO T2 VALUES (3,'CHAR(9)');
    1 row created.
    TEST.SQL>INSERT INTO T2 VALUES (3,'CHAR(10)');
    1 row created.
    TEST.SQL>
    TEST.SQL>
    TEST.SQL>COMMIT;
    Commit complete.
    TEST.SQL>
    TEST.SQL>SELECT M_NAME, MAX(V1), MAX(V2), MAX(V3), MAX(V4), MAX(V5), MAX(V6)
      2  FROM
      3       (
      4       SELECT
      5            M_NAME,RN,DECODE(RN,1,VAL) V1,DECODE(RN,2,VAL) V2,DECODE(RN,3,VAL) V3,DECODE(RN,4,VAL) V4,DECODE(RN,5,VAL) V5,DECODE(RN,6,VAL) V6
      6       FROM
      7                 (
      8                 SELECT M_NAME, VAL, ROW_NUMBER() OVER (PARTITION BY M_NAME ORDER BY VAL) RN
      9                 FROM
    10                           (
    11                           SELECT MASTER.M_NAME, T1.INT_TYPE VAL
    12                           FROM MASTER, T1
    13                           WHERE T1.M_ID=MASTER.M_ID
    14                           UNION ALL
    15                           SELECT MASTER.M_NAME, T2.CHAR_TYPE VAL
    16                           FROM MASTER, T2
    17                           WHERE T2.M_ID=MASTER.M_ID
    18                           ) SRC
    19                 )
    20       ) TS
    21  GROUP BY M_NAME
    22  ;
    M_NAM MAX(V1)    MAX(V2)    MAX(V3)    MAX(V4)    MAX(V5)    MAX(V6)
    m1    CHAR(3)    CHAR(4)    INT(2)     INT(3)
    m2    INT(1)
    m3    CHAR(10)   CHAR(9)    INT(1)     INT(2)     INT(4)     INT(8)Note that this will work only if the max number of columns is 6.
    It's possible (I already did it) to build a function that returns a dynamix result set from this query build dynamically. I'll let you do so!
    Regards,
    Yoann.

  • Simple SQL query

    Hi,
    I would like to know how this type of query is processed internally in Oracle
    SQL> select * from ( select 1 from dual, ( select 2 from dual ) g );
             1
             1
    SQL> select * from ( select 1 from dual, select 2 from dual );
    select * from ( select 1 from dual, select 2 from dual )
    ERROR at line 1:
    ORA-00903: invalid table nameWhy would 1 2 not be printed in result?
    Thanks

    user1980 wrote:
    Hi,
    I would like to know how this type of query is processed internally in Oracle
    SQL> select * from ( select 1 from dual, ( select 2 from dual ) g );
    1
    1
    SQL> select * from ( select 1 from dual, select 2 from dual );
    select * from ( select 1 from dual, select 2 from dual )
    ERROR at line 1:
    ORA-00903: invalid table nameWhy would 1 2 not be printed in result?
    ThanksJust look at what you are selecting from...
    SQL> select 1 from dual, select 2 from dual;
    select 1 from dual, select 2 from dual
    ERROR at line 1:
    ORA-00903: invalid table name
    SQL>it's not valid syntax for an SQL select statement so you can't use it as an inline view.
    If you are select from something, then that something has to be a valid view or table.

Maybe you are looking for