Using orderby clause when defining a view

Hi,
In oracle documentation they specified the query that defines a view cannot contain the ORDER BY or FOR UPDATE clauses.
But according to the book oracle DBA certification exam (by JASON S.COUCHMAN) the query that defines a view can contain the ORDER BY clause.
Can anyone help me clarify, whether we can use order by clause in defining a view

Hi,
THere are two classifications for views:simple and complex.A complex view can contains functions or groups of data.Use syntax:
Create view dept_sum_vu
(name,minsal,maxsal,avgsal)
as select d.name,MIN(e.sal),MAX(e.sal),AVG(e.sal)
from emp e,dept d
where e.deptno=d.deptno
group by d.dname
Hope it will work.
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by moturideepa([email protected]):
Hi,
In oracle documentation they specified the query that defines a view cannot contain the ORDER BY or FOR UPDATE clauses.
But according to the book oracle DBA certification exam (by JASON S.COUCHMAN) the query that defines a view can contain the ORDER BY clause.
Can anyone help me clarify, whether we can use order by clause in defining a view<HR></BLOCKQUOTE>
null

Similar Messages

  • I use floating time zone with all of my iCal entries.  But then the times of the entries do not print when printing month view.  Is there a fix for this?

    I use floating time zone with all of my iCal entries.  But then the times of the entries do not print when printing month view.  Is there a fix for this?

    Sorry to have repeated this question as if I were answering it.  Just a mistake.  I'm just now learning how to use this site.

  • When I click on a link in an RSS feed it used to indicate that I'd viewed that particular link by changing the icon to the left of the link. It doesn't do that anymore. [SOLVED]

    When I click on a link in an RSS feed it used to indicate that I'd viewed that particular link by changing the icon to the left of the link. It doesn't do that anymore. This started happening right around the time I updated to Firefox 4, but may have been a little before that too. For some things, like news and web comics it's just a little annoying. For important things like looking for new journal articles for my job, it literally makes my job more difficult. So fixing this would make my day.

    I seem to have solved my own problem. When I disabled the add-on "Tab Renamizer" everything started working fine.

  • Difference between View Creiterias and Where Condition when defining a VO

    Hi Friends,
    I am trying to understand the difference between specifying Where clause conditions in the View Criteria or directly in the VO Query.
    both meet the same requirement in executing the Query with the Where Conditions. Is there ay specific diff.?
    Thanks,
    User

    Hi Rade
    There are many ways to optimize the performance of your querys or VO, the most importantly is thing is not to make full scans of your table, always use the explain plain testing the query execution, filter using the indexs atributes, VO editor have a tuning SQL execution in the query optimizer hint you can use FIRST_ROWS for example.
    More information to tuning your query check this link [http://download.oracle.com/docs/cd/B28359_01/text.111/b28303/aoptim.htm#i1006353]
    Good Luck

  • When to use Tables, which are defined as u0093No Objectu0094?

    Generally, in which situations should we use a “<b>no object type</b> ” table ? There’s not much explanation about that type in help files.

    Hello,
    the possibility to define a type for table is new with version 2004. Before, all the table where defined as "no Object type"
    "No Object Type" tables are tables not used in UDO (User Defined Object). They are the "defaut type" table in Business one, You can access to them using the UserTables object, select/insert/remove/update record using this object
    If you choose ono of the available object type (master data, master data line....) theses table are created as UDO tables.
    Sebastien

  • Having a problem with creating/using a primary key on a view

    I have a problem with a primary key on a view
    I created the view and primary key as follows:
    CREATE OR REPLACE FORCE VIEW "MDD"."ROCK_LU" ("DESCRIPTION",
         UNIQUE ("DESCRIPTION") RELY DISABLE,
         CONSTRAINT "ROCK_LU_PK" PRIMARY KEY ("DESCRIPTION") RELY DISABLE) AS
    SELECT DESCRIPTION
    FROM MRMC_LU
    WHERE ROCK = 'T';
    The view with the primary key appears to have been created as there were no error messages. (The above was from the sql tab in sql developer.)
    When I try to create the foreign key on my mdd_hr table - I get an error
    /* hr_name - foreign key */
    ALTER TABLE mdd_hr add CONSTRAINT hr_name_fk FOREIGN KEY (hr_name) REFERENCES rock_lu(description);
    Error report:
    SQL Error: ORA-02270: no matching unique or primary key for this column-list.
    When I lookup the index in sql developer, rock_lu_pk is not there.
    All my other foreign keys work - but I don't understand what I am doing wrong with this one. Please help.
    glenn
    Background - as to why I want to use a view as a lookup table.
    The MRMC_LU table that the view is created from is structured like:
    DESCRIPTION - MINERAL - ROCK - MODIFIER - COMMODITY
    ANHYDRITE - T - T - T
    APLITE - T - - T
    GRAPHITE - T - - - T
    GREYWACKE - - T
    DESCRIPTION is a list of all names of minerals, rocks, modifiers and commodities. T is entered in each valid field. Often a description name is used for both a mineral and a rock or a mineral and a commodity or any other combination. Because this database is just starting up, it was more efficient to create one table that could be updated (and thereby automatically update the MINERAL_LU, ROCK_LU, MODIFIER_LY, COMMODITY_LU views) rather than create and maintain four separate but similar tables. A primary key cannot be generated for the MRMC_LU table as there are nulls in each column
    except DESCRIPTION.
    Perhaps there is a smarter way to do this?

    http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_85a.htm#2065512
    You can specify constraints on views and object views. You define the constraint at the view level using the out_of_line_constraint clause. You define the constraint as part of column or attribute specification using the inline_constraint clause after the appropriate alias.
    Oracle does not enforce view constraints. However, operations on views are subject to the integrity constraints defined on the underlying base tables. This means that you can enforce constraints on views through constraints on base tables.
    Restrictions on View Constraints
    View constraints are a subset of table constraints and are subject to the following restrictions:
    You can specify only unique, primary key, and foreign key constraints on views. However, you can define the view using the WITH CHECK OPTION clause, which is equivalent to specifying a check constraint for the view.
    Because view constraints are not enforced directly, you cannot specify INITIALLY DEFERRED or DEFERRABLE.
    View constraints are supported only in DISABLE NOVALIDATE mode. You must specify the keywords DISABLE NOVALIDATE when you declare the view constraint, and you cannot specify any other mode.
    You cannot specify the using_index_clause, the exceptions_clause clause, or the ON DELETE clause of the references_clause.
    You cannot define view constraints on attributes of an object column.
    Rgds.

  • How to define the Index on the column which is define in view (9i)

    hi all,
    I have one view which is based on to tables say 'customers' and 'vendors'
    view definition is like:
    create or replace view customer_vendor as
    select customer_name, 'Customer' type from customers
    union all
    select vendor_name, 'Vendor' type form vendors;
    my problem is that how i can define index on 'type' column if i used in where clause when i query the view.
    Regards
    s

    An index is a pointer. A pointer to a data place.
    Data result of a view aren't stored.
    So, how an index may work against a view ?
    SQL> create index idx1 on v1(type);
    create index idx1 on v1(type)
    ERROR at line 1:
    ORA-01702: a view is not appropriate hereThink about mview instead of view, maybe that can help. Data result of mview are stored somewhere in database, so you are allowed to create an index against mview, like for table.
    Anyway, if you want 'Customer', why not request onto customers table ?
    Nicolas.

  • 'lag' works in normal SQL statement, but not when in a view (resolved)

    hi,
    got a problem when using 'lag' in a view.
    if i set up a select statement using 'lag' and execute it, all the results are correct.
    when i stick the exact same select into a view, then the results for the 'lag' entries are not correct any more.
    has anyone experienced this ?
    any hints would be good.
    thanks
    Martin
    using Oracle 10g Express
    version 10.2.0.1.0
    can not download the patch because i can not log into metalink - no CSI
    setting to resolved.
    Message was edited by:
    user614086

    Hi again,
    I think the problem is more with your expectation of what LAG should be doing than with LAG itself.
    LAG must calculate based on the result set, in your stand alone query that means what's left after the WHERE clause is applied.
    In the view that means across all rows the view produces. THEN you apply the where clause to the calculated values. You can see this in the example below.
    So what you'd need to do is define this view in a manner in which the WHERE clause won't make a difference to the logical window produced.
    That would mean using some columns in the partition by clause and order by clause, or leaving the lag function outside the view.
    create table test_lag (column1 number, column2 varchar2(10), column3 date);
    insert into test_lag values (1, 'ONE', trunc(sysdate,'DD') - 1);
    insert into test_lag values (2, 'TWO' trunc(sysdate,'DD') );
    insert into test_lag values (3, 'THREE', trunc(sysdate,'DD') + 1);
    insert into test_lag values (4, 'FOUR', trunc(sysdate,'DD') + 2);
    commit;
    create or replace view test_lag_v
    as
    select column1, column2, lag(column2, 1) over (order by column1 asc) AS laggery, lag(column1) over (order by column3 desc) as laggery_2
    from test_lag;
    ME_XE?select *
      2  from test_lag_v
      3  where column1 <> 3;
               COLUMN1 COLUMN2                        LAGGERY                                 LAGGERY_2
                     4 FOUR                           THREE
                     1 ONE                                                                            3
    2 rows selected.
    Elapsed: 00:00:00.50
    ME_XE?
    ME_XE?select *
      2  from test_lag_v;
               COLUMN1 COLUMN2                        LAGGERY                                 LAGGERY_2
                     4 FOUR                           THREE
                     3 THREE                          ONE                                             4
                     1 ONE                                                                            3
    3 rows selected.
    Elapsed: 00:00:00.68

  • ADF VO bind variable does not work in 'OrderBy' clause

    Hello, All
    When trying to define a VO with a SQL query, we use VO bind variables on the 'OrderBy' clause and set Groovy expression to populate values at runtime. Based on simple experiments, ADF throws out an exception saying that "Attempt to set a parameter name that does not occur in the SQL'. I am wondering if it is allowed to use bind variables in a 'OrderBy' clause? I know it does in 'Where' clause.
    Thanks a lot for your answers.
    Regards,
    David

    So is there any change of the BC framework being corrected to allow this, since it is legal syntax, as in the following sql*plus example?
    select last_name, decode(&&1, 'SA_REP', nvl(commission_pct,0), 'SA_MAN', nvl(commission_pct,0), nvl(salary,0))
    from hr.employees
    where job_id = &&1
    order by decode (&&1, 'SA_REP', nvl(commission_pct,0), 'SA_MAN', nvl(commission_pct,0), nvl(salary,0))
    /

  • Using WITH clause in Pro*Cobol

    Hi!
    I am trying to improve the performance of a query by introducing WITH clause.
    The query is in Pro*Cobol Release 9.2.0.6.0 - Production.
    I got compilation error
    WITH DPTCOST AS (
    ...............1
    PCB-S-00400, Encountered the symbol "DPTCOST" when expecting one of the following:
    END-EXEC
    ....continued
    So I wonder if we could use that clause at all with Pro*Cobol
    Here is the excerp of the code
    EXEC SQL
    DECLARE INPUT_ACTUAL CURSOR FOR
    WITH DPTCOST AS (
    SELECT /*+ rule */
    A.CODE_COMBINATION_ID,
    A.SEGMENT1, A.SEGMENT2, A.SEGMENT3,
    A.SEGMENT6,
    D.COSTING, D.PROCESS,
    D.MTL_CODE, D.FACTOR
    FROM
    GL_CODE_COMBINATION A,
    ALCGL_DEPARTMENT_COSTINGS D
    WHERE
    A.TEMPLATE_ID IS NULL
    AND A.SUMMARY_FLAG <> 'Y'
    AND A.SEGMENT1 = D.PLANT_NUMBER
    AND A.SEGMENT3 <> '6999001'
    AND A.SEGMENT3 <> '6999002'
    AND SUBSTR(A.SEGMENT2,4,3) = D.DEPARTMENT
    AND D.ACTUAL_FLAG = 'A'
    ) ... continued

    Materialized views are basically stored query results. They offer advanced functionality like query rewrite, refresh on commit, and more;
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_6002.htm
    Unlike a view, they actually store the results of the query - not just the query;
    SQL> create table t (cid number primary key)
    Table created.
    SQL> insert into t select object_id from dba_objects where object_id is not null
    12791 rows created.
    SQL> create materialized view mv
       as select * from t
    Snapshot created.
    SQL> select object_name, object_type from user_objects where object_name ='MV'
    OBJECT_NAME                    OBJECT_TYPE       
    MV                             TABLE             
    MV                             MATERIALIZED VIEW 
    2 rows selected.
    SQL> select segment_name, bytes from user_segments where segment_name in ('T', 'MV')
    SEGMENT_NAME                        BYTES
    T                                  196608
    MV                                 196608
    2 rows selected.Temporary tables are simply tables that are created then dropped. GLOBAL TEMPORARY TABLES have the advantage (or disadvantage) of only existing until commit or the end of the session. They results are visible to the user that inserted the data - but only temporarily;
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7002.htm#sthref7483

  • Error : The ORDER BY clause is invalid in views, inline functions, derived

    Hi All,
    I am on 11g 6.2, Windows Server 2008, my db SQL server 2008, I am facing the error for the reports in which I am trying to edit one the column formula and do something like 'abc/sum(abc)*100'.
    10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 43119] Query Failed: [nQSError: 16001] ODBC error state: 37000 code: 8180 message: [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.. [nQSError: 16001] ODBC error state: 37000 code: 1033 message: [Microsoft][ODBC SQL Server Driver][SQL Server]The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.. [nQSError: 16002] Cannot obtain number of columns for the query result. (HY000)
    One of the solutions to this which I have found is to edit the EXPRESSION_IN_ORDERBY_SUPPORTED feature in the db properties.
    I want to know what does EXPRESSION_IN_ORDERBY_SUPPORTED means?
    When I create a calculations in 11g like abc/sum(abc) in the column formula for a column then i get this error.
    What does this error mean? Does OBIEE 11g doesn't support using these expressions in the report and the fact that it applies the order by clause to the reports, the report fail?
    Could anybody please explain the issue. There is very limited information on this over the web.
    Thanks in advance.
    Ronny

    Thanks svee for the quick response, actually i had resolved the issue by unchecking the EXPRESSION_IN_ORDERBY_SUPPORTED option in the database. I want to understand how does that makes the difference?
    What does EXPRESSION_IN_ORDERBY_SUPPORTED mean? Does it mean that if I give any expression in my answers report and since obiee uses a order by for all the queries, the expression won't be supported?
    Please explain.

  • Can we define a view that refers to 50 tables?

    Hi,
    I've a problem at hand and I'm not sure what the right solution I can adopt.
    There is an application which hits the DB (v11.2) for accessing a single view 'XVIEW'. This view has a simple sql & join which is based on two tables XTABLE1 and XTABLE2.
    Now, the new version of the schema that has got released has split XTABLE2 into 50 different tables each having a same structure. To the fix the issue, there are two solutions I could think of:
    1. Create 50 views on top of 50 tables, and fix the Application to refer to these 50 new views; note: the application has hundreds of references and this has a significant work involved.
    2. Rewrite XVIEW to refer to 50 tables. This will avoid changing the application, however I'm not sure if this is feasible and will have a decent performance.
    I would like to go for solution 2 as it involves significantly less effort, but not sure how best i should define the view, single the 50 table structure is the same can I just union all of them?
    Thanks for the help.

    Hi,
    Hozy wrote:
    Frank, thanks for helping me out.
    What you are suggesting is that I should recreate the view XVIEW which does union all (as the rows will be unique) of the 50 tables, however performance will be an issue unless I can create a materialized views.
    What I know of materialized views is that it's used for static, pre-computed type of data. A materialized view is pre-computed; that's what makes it faster. The time and effort spent in doing the UNION is shifted from the time when you do the queries to the time when you refresh the materialized view. Whether that is more or less total time depends on how often you query the view, and how often you refresh it. At any rate, the performance when you do the queries will be as good as possible.
    Materialized views ar often used in data wharehouses, where then data may only change once a month, but they are also often used in situations like yours, where the data changes every day, or even more frequently.
    In my case, the data in few of the 50 tables might change once every 24hrs and it all comes at one time. The queries that hit XVIEW should get the latest data. Is there a way I can define a materialized view which will pick up the new data in the base 50 tables?I see; you have some job that runs at, say, 2:00 am every morning, and changes some, or maybe all, of the 50 tables. You might refresh the materialized view at, say, 4:00 am every day, or at some time when you're sure that the changes to the base tables are complete. Any query that uses the materialized view between 2:00 and 4:00 am will get stale data.
    You could, alternatively, make the materilaized view refresh whenever any of the base tables change, but this uses more resources, including your time and effort setting it up.

  • Define multiple views

    I'm trying to build a simple app which has multiple views. When the user clicks on the worksetItem I want to change the view, and display an other table in the shell. But I dont know how can I define another view, and add it to the shell.

    Hy Venkatesh
    I've found the link too that you've posted.
    I've used the following tutorial to buld the base of my app:
    Developing a simple List based SAPUI5 Application
    And now I want to spereate the BP data, and create a subview for it, and do the same for Sales, than load it to the main view, when the user clicks on the menu. But I dont really know how to write my own view. (what to write to the "createContent()").

  • Using RETURNING clause with Execute Immediate

    I wrote a query to update a table and return the column in to a nested table type variable using returning clause but its not working I am getting error like
    ORA-06550: line 66, column 22:
    PLS-00306: wrong number or types of arguments in call to '||'
    ORA-06550: line 66, column 4:
    PL/SQL: Statement ignored
    I am getting error in following part of my query
    || 'RETURNING if_row_status bulk collect INTO '
    || v_if_row_status;
    v_if_row_status is defined as -
    TYPE v_count IS TABLE OF varchar2(50) INDEX BY BINARY_INTEGER;
    v_if_row_status v_count;

    I am trying to update a table for diffrent column if they are null and want no of column updated for each column.
    I wrote following query but I am not getting the correct output.
    UPDATE
    Temp_Bulk_Col_POC
    SET if_row_status = 'VALIDATED',
    if_row_processed_date = sysdate,
    if_row_error_msg =
    CASE
    WHEN record_type IS NULL
    THEN 'RECORD_TYPE is a required column and cannot be NULL'
    WHEN source_system IS NULL
    THEN 'SOURCE_SYSTEM is a required column and cannot be NULL'
    WHEN record_company IS NULL
    THEN 'RECORD_COMPANY is a required column and cannot be NULL'
    WHEN record_system IS NULL
    THEN 'RECORD_SYSTEM is a required column and cannot be NULL'
    WHEN txn_flag IS NULL
    THEN 'TXN_FLAG is a required column and cannot be NULL'
    WHEN create_date IS NULL
    THEN 'CREATE_DATE is a required column and cannot be NULL'
    WHEN UPDATE_date IS NULL
    THEN 'UPDATE_DATE is a required column and cannot be NULL'
    WHEN source_customer_id IS NULL
    THEN 'SOURCE_CUSTOMER_ID is a required column and cannot be NULL'
    WHEN source_product_id IS NULL
    THEN 'SOURCE_PRODUCT_ID is a required column and cannot be NULL'
    WHEN az_product_id IS NULL
    THEN 'AZ_PRODUCT_ID is a required column and cannot be NULL'
    WHEN decile IS NULL
    THEN 'DECILE is a required column and cannot be NULL'
    END
    WHERE if_row_status IS NULL
    AND (record_type IS NULL
    OR source_system IS NULL
    OR record_company IS NULL
    OR record_system IS NULL
    OR txn_flag IS NULL
    OR create_date IS NULL
    OR UPDATE_date IS NULL
    OR source_customer_id IS NULL
    OR source_product_id IS NULL
    OR az_product_id IS NULL
    OR decile IS NULL)
    RETURNING if_row_status,record_type,source_system,record_company,record_system,
    txn_flag,create_date,UPDATE_date,source_customer_id,source_product_id,az_product_id,
    decile
    BULK COLLECT INTO
    v_if_row_status,v_record_type,v_source_system,
    v_record_company,v_record_system,v_txn_flag,v_create_date,v_UPDATE_date,
    v_source_customer_id,v_source_product_id,v_az_product_id,v_decile;
    its showing same number for all the column.
    how I can collect based on the coulmn updated

  • I want to use variation funtion without define the characteristic...

    Dear.
    I want to use variation funtion without define the characteristic into general data selection in making report painter.
    Finally hopeful thing is, The extract data which contain that characteristic group should be used in the whole sub-hierarchy
    automatically such as I did that in general data selection.
    For example, supposing the profit center group A is composed like below,
       A
      └─ B
    └─ C
    .....└─ D
    When I make report painter, if the profit center positioned in lead column not general data,
    I can't use variation funtion in profit center. So, I must save extract data each profit center group manually. (A,B,C,D..)
    It is so uncomfortalble.(Guess the profit center group composed over hundreds.)
    You know, the profit center located in general data, I just need to extract data only once in A. Then B,C,D also saved automatically.
    Why can't do this in former case ? If possible, please let me know.

    Replace af with h.
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <%@ page contentType="text/html;charset=UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <f:view>
    <h:messages id="m1"/>
    <h:form id="f1">
    <h:outputText value="#{inputValue}" id="ot1"/>
    </h:form>
    </f:view>

Maybe you are looking for