Update with Where clause

Hi,
I have aprogram like this...
declare
v_val varchar2(300) := '10,20';
begin
update emp set sal=888 where to_char(empno) in (v_val);
commit;
end;
When i run, it say success but the values are NOT updating...
Can any one tell me where i'm doing wrong ?
Thanks in advance

Assuming you will be doing this regularly, dynamic SQL is probably out, assuming that you don't want to trash your shared pool.
If you cannot change the procedure to accept an array of values, rather than a single comma separated string, you can use a pipelined table function to parse the string into an array. Tom Kyte has an example of this with his str2tbl function
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:2460648511591
and there are some examples of using a similar tokenizing function elsewhere
http://www.ddbcinc.com/askddbc/topic.asp?TOPIC_ID=758
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC

Similar Messages

  • Merge with where clause after matched and unmatched

    Hai,
    Can anybody give me one example of merge statement with
    where clause after matched condition and after the unmatched condition.
    MERGE INTO V1 VV1
    USING (SELECT     A.CNO XXCNO, A.SUNITS XXSU, A.DDATE XXDD, XX.SUM_UNITS SUMMED
    FROM V1 A,
    (SELECT                
    SUM(SUNITS) SUM_UNITS FROM V1 B                                   
    GROUP BY CNO) c
    WHERE
    A.DDATE=0 AND A.SUNITS <>0 AND
    A.ROWID=(SELECT MAX(ROWID) FROM V1 )) XX
    ON (1=1)
    WHEN MATCHED THEN UPDATE SET
    VV1.SUNITS=XX.SUMMED
    WHERE XX.XXDD=0
    WHEN NOT MATCHED THEN INSERT
    (VV1.CNO, VV1.SUNITS, VV1.SUNITS)
    VALUES (XX.XXCNO, XX.XXSU, XX.XXDD)
    WHERE XX.XXDD<>0
    i am getting the error
    WHERE XX.XXDD=0
    ERROR at line 13:
    ORA-00905: missing keyword
    Thanks,
    Pal

    One of the example is there:
    http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_9016.htm#sthref7014
    What Oracle version do you use ?
    Besides the condition (1=1) is non-deterministic,
    I would expect there an exception like "unable to get a stable set of rows".
    Rgds.

  • Apex 4.0 Image Buttons to update SQL Where clause of Report?

    I made a table called Letters with 1 column in it called Letter and the data in it is simply A,B,C, to H. I made an apex form around this table and then created two image buttons A and B that display above the reporting area b/c i want to be able to click on the A image button and have it update the Where clause for the Letters table to be "Where Letter = A" (so once you click the A button, only the A will appear), same for the B button. I have attached a link to an album of images to show what i'm trying to do to better explain it. I just can't figure out what or how to make it so that the image button can update the where clause. I should note that i am relatively new to Apex and i tried using a dynamic action to do it but can't get this to work.
    Link to images of what i have so far-> http://imgur.com/a/guxkd/oracle_apex_40_use_image_buttons
    Any suggestions?
    Edited by: Brobot on Feb 8, 2011 9:58 PM

    Since you are using some kind of button(with images or otherwise) , add some attributes to identify them together aswell as uniquely.
    For instance if you add a name and an a common classname to each button
    For example, in button attributes for A this could be
    name="A" class="where_clause_button"You can use these attributes to trigger a Dynamic action which can refresh the report.
    Since you want the report to be filtered based on the button(ie using the "name" attribute of the corresponding button) , you need to set that value in some hidden item, say P100_FILTER_LETTER. and add a where clase to your Report Region' SQL Query
    WHERE <column name> = :P100_FILTER_LETTERNow create a Dynamic Action as
    Event :Click
    Triggering Element : jQuery selector
    Selector : *.where_clause_button*
    <li>True action 1 : Execute Javascript code
    filter_item_name = 'P100_FILTER_LETTER'
    this_button_name = $(this.triggeringElement).attr('name');
    //Set session state of Hidden Item before refresh
    var ajaxRequest=new htmldb_Get(null,$v('pFlowId'),'null',$v('pFlowStepId'));
    ajaxRequest.add( filter_item_name ,this_button_name );
    var ajaxResult=ajaxRequest.get();<li> True Action 2: Refresh
    Affected Element: Region
    Name : Choose Report Region Name
    Hope it helps

  • Export (expdp) with where clause

    Hello Gurus,
    I am trying to export with where clause. I am getting below error.
    Here is my export command.
    expdp "'/ as sysdba'" tables = USER1.TABLE1 directory=DATA_PUMP dumpfile=TABLE1.dmp logfile=TABLE1.log query= “USER1.TABLE1:where auditdate>'01-JAN-10'” Here is error
    [keeth]DB1 /oracle/data_15/db1> DATA_PUMP dumpfile=TABLE1.dmp logfile=TABLE1.log query= USER1.TABLE1:where auditdate>'01-JAN-10'                    <
    Export: Release 11.2.0.3.0 - Production on Tue Mar 26 03:03:26 2013
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Starting "SYS"."SYS_EXPORT_TABLE_03":  "/******** AS SYSDBA" tables=USER1.TABLE1 directory=DATA_PUMP dumpfile=TABLE1.dmp logfile=TABLE1.log query= USER1.TABLE1:where auditdate
    Estimate in progress using BLOCKS method...
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    Total estimation using BLOCKS method: 386 MB
    Processing object type TABLE_EXPORT/TABLE/TABLE
    Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
    Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
    Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
    Processing object type TABLE_EXPORT/TABLE/TRIGGER
    Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
    ORA-31693: Table data object "USER1"."TABLE1" failed to load/unload and is being skipped due to error:
    ORA-00933: SQL command not properly ended
    Master table "SYS"."SYS_EXPORT_TABLE_03" successfully loaded/unloaded
    Dump file set for SYS.SYS_EXPORT_TABLE_03 is:
      /oracle/data_15/db1/TABLE1.dmp
    Job "SYS"."SYS_EXPORT_TABLE_03" completed with 1 error(s) at 03:03:58Version
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production

    Hello,
    You should use parameter file.Another question i can see you are using 11g.Why don't you use data pump?.
    Data Pump is faster and have more features and enhancement than regular imp and exp.
    You can do the following:
    sqlplus / as sysdba
    Create directory DPUMP_DIR3  for 'Type here your os path that you want to export to';then touch a file:
    touch par.txt
    In this file type the following the following :
    tables=schema.table_name
    dumpfile=yourdump.dmp
    DIRECTORY=DPUMP_DIR3
    logfile=Your_logfile.log
    QUERY =abs.texp:"where hiredate>'01-JAN-13' "then do the following
    expdp username/password parfile='par.txt'
    If you will import from Oracle 11g to version 10g then you have to addthe parameter "version=10" to the parameter file above
    BR
    Mohamed ELAzab
    http://mohamedelazab.blogspot.com/

  • Outer Join with Where Clause in LTS

    HI all,
    I have a requirement like this in ANSI SQL:
    select p1.product_id, p1.product_name, p2.product_group
    from product p1 left outer join product_group p2 on p1.product_id = p2.product_id
    and p2.product_group = 'NEW'
    In Regular SQL:
    select p1.product_id, p1.product_name, p2.product_group
    from product p1, product_group p2
    WHERE p1.product_id *= p2.product_id and p2.product_group = 'NEW'
    In OBIEE, I am using a left outer join between these two in Logical table Source, and also, Gave
    p2.product_group = 'NEW' in WHERE clause of LTS.
    This doesn't seem to solve purpose.
    Do you have any idea how to convert WHERE clause in physical query that OBIEE is generating to something like
    product p1 left outer join product_group p2 on p1.product_id = p2.product_id AND p2.product_group = 'NEW'
    I am using Version 10.1.3.4.1
    Creating an Opaque view would be my last option though.

    Hello
    I have read your post and the responses as well. and I understand that you have issues with the Outer Join with where Clause in LTS.
    Try this solution which worked for me (using your example ) -
    1. In the Physical Layer created a Complex join between PRODUCT and PRODUCT_GROUP tables and use this join relationship :
    PRODUCT.PROD_ID = PRODUCT_GROUP.PROD_ID  AND  PRODUCT_GROUP.GROUP_NAME = 'MECHANICAL' 
    2. In the General Tab of PRODUCT table LTS add PRODUCT_GROUP  table and select Join Type as Left Outer Join.
    3. Check Consistency and make sure there are no errors .
    when you run a request you should see the following query generated -
    select distinct T26908.PROD_ID as c1,
         T26908.PROD_NAME as c2,
         T26912.GROUP_NAME as c3
    from
         PRODUCT T26908 left outer join PRODUCT_GROUP T26912 On T26908.PROD_ID = T26912.PROD_ID and T26912.GROUP_NAME = 'MECHANICAL'
    order by c1, c2, c3
    Hope this works for you. If it does please mark this response as 'Correct' .
    Good Luck.

  • Insert with Where Clause

    Hi,
    Can we write Insert with 'Where' clause? I'm looking for something similar to the below one (which is giving me an error)
    insert into PS_AUDIT_OUT (AUDIT_ID, EMPLID, RECNAME, FIELDNAME, MATCHVAL, ERRORMSG)
    Values ('1','10000139','NAMES','FIRST_NAME',';','')
    Where AUDIT_ID IN
    (  select AUDIT_ID from PS_AUDIT_FLD where AUDIT_ID ='1' and RECNAME ='NAMES'
    AND FIELDNAME = 'FIRST_NAME' AND MATCHVAL = ';' );
    Thanks
    Durai

    It is not clear what are you trying to do, but it looks like:
    insert
      into PS_AUDIT_OUT(
                        AUDIT_ID,
                        EMPLID,
                        RECNAME,
                        FIELDNAME,
                        MATCHVAL,
                        ERRORMSG
    select  '1',
            '10000139',
            'NAMES',
            'FIRST_NAME',
      from  PS_AUDIT_FLD
      where AUDIT_ID = '1'
        and RECNAME ='NAMES'
        and FIELDNAME = 'FIRST_NAME'
        and MATCHVAL = ';'
    SY.

  • Hierarchical query with where clause

    Hi,
    How can I query hierarchically a query with WHERE clause? I have a table with three fields session_id,id and root_id.
    When I try with the following query,
    select id, level from relation
    where session_id = 79977
    connect by prior id = root_id start with id = 5042;
    It gets duplicate values.
    I want the query to show in the hierarchical manner with a filter condition using WHERE clause. Please help me how can I achieve this. If you know any link that describes more about this, please send it.
    Thanks in Advance.
    Regards,
    -Parmy

    Hi Sridhar Murthy an others,
    Thanks a lot for your/the answer. It's working for me. It saved a lot of other work around without the proper knowledge of hierarchical query. Please send me any link that describes these issues in detail and also I hope as I have mentioned in the other message, same cannot be achieved on views or ( on two different tables ???)
    Any way thanks for your reply,
    It's working for me.
    With happiness,
    -Parmy

  • Populate list by executing query with where clause

    Hi,
    I m populating my list from database table using following command.
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("learning", new HashMap());
    EntityManager em = emf.createEntityManager();
    String query = "select d from Dept d";
    List list = em.createQuery(query).getResultList();
    My list is getting populated with all of rows in my database table(dept). The problem is, I cant use where clause in my query string.
    String query = "select d from Dept d where d.dept_name='ANYNAME'";
    Moreover I cant select even indivisual columns by using following line
    String query = "select d.dept_code,d.dept_name from Dept d";
    It looks like that my query is getting all rows from table as Object.
    What to do to
    1. put some where clause
    2. get some particular colums instead of all columns
    3. apply some table joins in query
    plz help.

    Hi Alex,
    I misunderstood your question. You had mentioned "My list is getting populated with all of rows in my database table(dept). The problem is, I cant use where clause in my query string. "
    I thought you might not have permissions to modify the code in the class, and that's why I suggested that you could write new classes.
    1) write new classes,? means if I need just two columns from a table >(instead of all columns), do I need to write new class with just two >columns (getters and setters)?You can write a SQL statement anyway you want , there are no restrictions in JDBC , so if you need just 2 columns you can write a custom query for that.
    "select column1 as a, column2 as be from table_name where column3 = xyz" etc.
    2) Is not anyway to write SQL statement like
    select dept_code,dept_name from dept where dept_name='anything'The above SQL is correct, it should work.
    3) Stored procedures? can I get some example(code) to get an idea >how to implement complex queries with where clause and joinings >using stored procedures?Stored procedures are specific to the database you are using, Oracle has a particular syntax for store procdures.
    You can call stored procedures from JDBC also, search on Google for
    "Calling stored procedures from JDBC"
    4) I m using hibernate. can I get any example of using hibernate own >query?Tutorial on Hibernate Query Language:
    http://www.hibernate.org/hib_docs/v3/reference/en/html/queryhql.html

  • Urgent: Performance problem with where clause using IN and an OR condition

    Select statement is:
    select fl.feed_line_id
    from ap_expense_feed_lines_all fl
    where ((:1 is not null and
    fl.feed_line_id in (select distinct r2.object_id
    from xxdl_pcard_wf_routing_lists r2,
         per_people_f hr2
    where upper(hr2.full_name) like upper(:1||'%')
              and hr2.person_id = r2.person_id
    and r2.fyi_list is null
              and r2.sequence_number <> 0))
    or
    (:1 is null))
    If I modify the statement to remove the "or (:1 is null))" part at the bottom of the where clause, it returns in .16 seconds. If I modify the statement to only contain the "(:1 is null))" part of the where clause, it returns in .02 seconds. With the whole statement above, it returns in 477 seconds. Anyone have any suggestions?
    Explain plan for the whole statement is:
    (1) SELECT STATEMENT CHOOSE
    Est. Rows: 10,960 Cost: 212
    FILTER
    (2) TABLE ACCESS FULL AP.AP_EXPENSE_FEED_LINES_ALL [Analyzed]
    (2) Blocks: 8,610 Est. Rows: 10,960 of 209,260 Cost: 212
    Tablespace: APD
    (6) TABLE ACCESS BY INDEX ROWID HR.PER_ALL_PEOPLE_F [Analyzed]
    (6) Blocks: 4,580 Est. Rows: 1 of 85,500 Cost: 2
    Tablespace: HRD
    (5) NESTED LOOPS
    Est. Rows: 1 Cost: 4
    (3) TABLE ACCESS FULL XXDL.XXDL_PCARD_WF_ROUTING_LISTS [Analyzed]
    (3) Blocks: 19 Est. Rows: 1 of 1,303 Cost: 2
    Tablespace: XXDLD
    (4) UNIQUE INDEX RANGE SCAN HR.PER_PEOPLE_F_PK [Analyzed]
    Est. Rows: 1 Cost: 1
    Thanks in advance,
    Peter

    Thanks for the reply, but I have already checked what you are suggesting and I am pretty sure those are not causing the problem. The hr2.full_name column has an upper index and the (4) line of the explain plan shows that index being used. In addition, that part of the query executes on its own quickly.
    Because the sql is not displayed in an indented format on this page it is a little hard to understand the structure so I am going to restate what is happening.
    My sql is:
    select a_column
    from a_table
    where ((:1 is not null) and a_column in (sub-select statement)
    or
    (:1 is null))
    The :1 bind variable is set to a varchar2 entered on the screen of an application.
    If I execute either part of the sql without the OR condition, performance is good.
    If the :1 bind variable is null with the whole sql statement (so all rows or a_table are returned), performance is still good.
    If the :1 bind variable is a not-null value with the whole sql statement, performance stinks.
    As an example:
    where (('wa' is not null) and a_column in (sub-select statement)) -- fast
    where (('wa' is null)) -- fast
    where (('' is not null) and a_column in (sub-select statement) -- fast
    or
    ('' is null))
    where (('wa' is not null) and a_column in (sub-select statement) -- slow
    or
    ('wa' is null))

  • Issue in select query with where clause

    Hi guys,
    I'm facing an issue while using select query with the where clause. When I'm selecting all the data from the table it returns the correct result. But when I'm using the where clause to get the specific rows from the table it returns no rows. But the data I'm trying to fetch using the where condition exists in the table.
    Here is my query which causing the issue,
    select * from mytable where myfield = 'myvalue'
    But if I use the following query it returns the result correctly.
    select * from mytable
    Also the myfield value 'myvalue' exists in the table.
    I have tried by running this query in both SQL Developer and SQL Plus. I have tried this query in mssql as well. It works perfectly and returns correct result sets for both the queries I have mentioned above. I'm unable to predict the issue as I'm new to ORACLE. Please help.
    Thanks,
    Ram.

    Hi Ram,
    I experienced an issue similar to this with a varchar2 field. Some of our records had a hidden newline character at the end of them, which was making queries like the one below fail:
    select * from employees
    where email = '[email protected]'The best way I found to detect this was to use
    select 'XX'||email||'XX' from employeesTo make sure that there were no newlines. But that is just a guess. If you could provide some example table data and the outputs of your selects, it would be helpful.
    Jeff

  • Summary column with where clause

    Hi all,
    I'm using Oracle Report Builder 10GR2. I have the following issue: In one of the query i have the following result :
    Suppliers     0
    Suppliers     1408
    Total in  BGN     1408
    Customers      6024
    Customers      11779.32
    Customers      
    Total in  BGN     11779.32
    Taxes      0
    Taxes      0
    Total in  BGN     0
    Cash      1363.85
    Cash      691
    Cash      991.23
    Cash      688
    Total in  BGN     2355.08I want to make a sum for these columns where corresponds to description " Total in BGN" . Maybe it is a simple task... Do i have a chance to select from a query in a Report Builder?
    If yes, pls specify? Or maybe there is a chance to add a where clause for summary column. But keep in mind that this is one of the queries in the report builder and i have to add summary with this conditions. I cannot change the existing query but probably add a new one.
    Any ideas?
    DB Version: 11g
    Thanks in advance,
    Bahchevanov.
    Edited by: bahchevanov on Sep 29, 2012 2:21 AM

    Hello,
    You should use parameter file.Another question i can see you are using 11g.Why don't you use data pump?.
    Data Pump is faster and have more features and enhancement than regular imp and exp.
    You can do the following:
    sqlplus / as sysdba
    Create directory DPUMP_DIR3  for 'Type here your os path that you want to export to';then touch a file:
    touch par.txt
    In this file type the following the following :
    tables=schema.table_name
    dumpfile=yourdump.dmp
    DIRECTORY=DPUMP_DIR3
    logfile=Your_logfile.log
    QUERY =abs.texp:"where hiredate>'01-JAN-13' "then do the following
    expdp username/password parfile='par.txt'
    If you will import from Oracle 11g to version 10g then you have to addthe parameter "version=10" to the parameter file above
    BR
    Mohamed ELAzab
    http://mohamedelazab.blogspot.com/

  • Readonly table with where clause value from previous page

    Hi
    I am using jdeveloper 10.1.3.
    I have a globalhome page where the user enteres a reference number. i have a backing bean for the globalhome page that runs a method to run an sql that seraches for this reference number, if the reference number exsits the user is directed to a detail page.
    this detail page should display details of this reference number.
    i have set up a read only table to display this data based on a view object with a bind varaible in the where clause.
    however i am unsure how to set this bind varaible value to the reference entered in the first globalhome page.
    please can anyone advise how to do this.
    regards

    Hi,
    You can follow following steps to achieve this
    1) Write a custom method in your Application module like
    public void executeMyVO(String bindVarValue)
    MyVOImpl vo= getMyVo();
    vo.setNamedWhereClauseParam(<bind variable name decalred in VO>,bindVarValue);
    vo.execute();
    2) Expose the above method to client. (Right click AM-->Client-->Shift method from left to right)
    3) In the pagedef of globalhome page, create a method action for the aboce created custom method
    4) execute the method action from your backing bean after you run an sql that seraches for this reference number.
    Hope this help.
    Vikram

  • Outer join with where clause in the universe

    Hi,
    I have two tables such as:
    Patient Table (P)                          Territory Table (T)
    P. Alignment ID --------------------------   T.Alignment ID
    P. Patient ID                                    T. Region
    Two tables are joined on alignment ID, follow is how the data looks like
    When i run the query only on Patient Table  i get the following
    e.g.
    Select P.Patient ID, P.Alignment ID
    from Patient Table (P)
    Where P.Data_date=P.Latest data date
    ----Note that there is a Where clause here always & i get the following result
    P.Patient ID         P.Alignment ID      
        1                            1a
        2                             2a
        3                            3a
        4                            Null
        5                            Null
    Now when i join two tables on Alignment ID
    e.g.
    Select P.Patient ID, P.Alignment ID,T.Region
    from Patient Table (P)
    LEFT OUTER  JOIN Territory Table (T)
    ON P. Alignment ID =  T.Alignment ID
    Where P.Data_date=P.Latest data date
    AND T.Data_date=T.Latest data date
    Following is the result:
    P.Patient ID         P.Alignment ID      
        1                            1a
        2                            2a
        3                            3a
    Even with the left outer join it is not brining in the Null values , it seems that because of the WHERE clause the LEFT OUTER is working as a INNER join.
    How can i get the Null rows with my join to the territory table ?
    Please Advise,
    Thanks,
    Sheikh

    its not letting me atatched the excel extract but the data is simple as i shown above e.g.
    Patient Table (P)                          Territory Table (T)
    P. Alignment ID --------------------------   T.Alignment ID
    P. Patient ID                                    T. Region
    Two tables are joined on alignment ID, follow is how the data looks like
    When i run the query only on Patient Table  i get the following
    e.g.
    Select P.Patient ID, P.Alignment ID
    from Patient Table (P)
    Where P.Data_date='01-OCT-2014'
    ----Note that there is a Where clause here always & i get the following result
    P.Patient ID         P.Alignment ID      
        1                            1a
        2                             2a
        3                            3a
        4                            Null
        5                            Null
    Now when i join two tables on Alignment ID
    e.g.
    Select P.Patient ID, P.Alignment ID,T.Region
    from Patient Table (P)
    LEFT OUTER  JOIN Territory Table (T)
    ON P. Alignment ID =  T.Alignment ID
    Where P.Data_date='01-OCT-2014'
    AND T.Data_date='01-OCT-2014'
    Following is the result:
    P.Patient ID         P.Alignment ID      
        1                            1a
        2                            2a
        3                            3a
    Now the whole issue is that the condition in the WHERE clause is making it act like a inner join and iw ant the NULL rows to appear
    Sheikh

  • Case with where clause - ORA-00920: Invalid relational operator

    Hi All, when I try to run the query below, I get the following error...
    ORA-00920: invalid relational operator
    00920. 00000 -  "invalid relational operator"
    *Cause:   
    *Action:
    Error at Line: 16 Column: 5
    Does anyone know what's wrong with my query? thanks in advance.
    SELECT concat (year,period)
    FROM DD_ACTUALS_FACT
    WHERE CASE Period
    WHEN 'JAN' THEN '01'
    WHEN 'FEB' THEN '02'
    WHEN 'MAR' THEN '03'
    WHEN 'APR' THEN '04'
    WHEN 'MAY' THEN '05'
    WHEN 'JUN' THEN '06'
    WHEN 'JUL' THEN '07'
    WHEN 'AUG' THEN '08'
    WHEN 'SEP' THEN '09'
    WHEN 'OCT' THEN '10'
    WHEN 'NOV' THEN '11'
    WHEN 'DEC' THEN '12'
    END as "MonthNo"
    ORDER BY CONCAT (year,"MonthNo") DESC

    The problem is the as "MonthNo" - you can't give an "AS" alias to an expression in a where clause.
    You have not actually given any condition, just a set of translations from period into a number.
    You also haven't said what you're trying to do.
    Perhaps you want:
    SELECT concat (year,period)
    FROM DD_ACTUALS_FACT
    WHERE something
    ORDER BY CONCAT (year, CASE Period
    WHEN 'JAN' THEN '01'
    WHEN 'FEB' THEN '02'
    WHEN 'MAR' THEN '03'
    WHEN 'APR' THEN '04'
    WHEN 'MAY' THEN '05'
    WHEN 'JUN' THEN '06'
    WHEN 'JUL' THEN '07'
    WHEN 'AUG' THEN '08'
    WHEN 'SEP' THEN '09'
    WHEN 'OCT' THEN '10'
    WHEN 'NOV' THEN '11'
    WHEN 'DEC' THEN '12'
    END  ) DESC

  • Prob. with where clause with rownum

    hi
    i have a table with the following columns
    SQL> desc mark
    Name Null? Type
    STUDENTCODE NUMBER(3)
    MARK1 NUMBER(2)
    MARK2 NUMBER(3)
    and here are the rows in it
    SQL> select * from mark ;
    STUDENTCODE MARK1 MARK2
    1 20 40
    2 70 80
    3 80 90
    4 90 99
    12 13 35
    5 90 80
    6 78 87
    i wanna sum mark1 and mark2 and list down the rows with the top 2 rows
    i tried to first list down all the rows in the order of sum with the following stat.
    SQL> select studentcode,mark1+mark2 from mark order by mark1+mark2 desc
    STUDENTCODE MARK1+MARK2
    4 189
    3 170
    5 170
    6 165
    2 150
    1 60
    12 48
    it worked fine. but i used a where clause to get the first 2 rows and here is what i got.
    SQL> select studentcode,mark1+mark2 from mark where rownum < 3 order by (mark1+mark2) desc
    STUDENTCODE MARK1+MARK2
    3 170
    2 150
    1 60
    as You can see, i don't get the req. result.
    how do i get the prob. solved ?

    For Oracle versions prior to 8.1.5, you will have to create a view and then incorporate that view into your select statement.
    create or replace view my_view
    is
    select studentcode, mark1 + mark2
    from mark
    order by mark1 + mark2 desc;
    select *
    from my_view
    where rownum <= 2

Maybe you are looking for