SQL Query doesn't work coccrectly

The table includes list of month and years.
When I write
SELECT MONTH,YEAR FROM MONTH_DETAILS ORDER BY YEAR DESC,MONTH DESC;
it works correcty and returns
MONTH YEAR
7 2009
6 2009
5 2009
4 2009
3 2009
2 2009
1 2009
12 2008
11 2008
But when I want to return only the first one(month=7 and year=2009) and change query like this
SELECT MONTH,YEAR FROM MONTH_DETAILS WHERE ROWNUM=1 ORDER BY YEAR DESC,MONTH DESC;
it returns
MONTH YEAR
2 2009
what is the problem?
Both month and year fields are defined as numbers.

Your query should be
SELECT MONTH
      ,YEAR
FROM (
      SELECT MONTH
            ,YEAR
            ,ROWNUM row_num
        FROM MONTH_DETAILS
       WHERE ORDER BY YEAR DESC,MONTH DESC
WHERE row_num  = 1; Regards
Arun

Similar Messages

  • SQL query doesn't work in VB program

    Hi:
    The following SQL query doesn't work into a VB program, I'm using Oracle OLEDB to established connection to the DB, ... the query returns 0 rows ...
    When I run this same query from any SQL Plus, works well (returning me something like 119 rows) ...
    Any clue or hint ??
    Thanks in advanced
    Angel Castro
    SELECT OPERADOR, ID_ALIMENTADOR, RB_FSC, NUM_CTROL, COND_OPERA, TRANSITORIO, PENDIENTES, ANORMAL, EDO_REAL, IDENTIFICADOR, CAUSA
    FROM HISTORICO_OPERACION
    WHERE (FECHA BETWEEN '20-AUG-2004' AND '5-NOV-2004')
    AND (HORA BETWEEN '10:00:00' AND '16:00:00')
    ORDER BY ID_ALIMENTADOR ASC;

    Is the column FECHA of datatype DATE?
    Are you running the query with the constant date looking like strings ('20-AUG-2004' in your post, for example) as-is from the VB program?
    If not, are you binding the parameters correctly?
    What is the setting of your NLS_DATE_FORMAT parameter?
    What happens if you do a
    ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY'from your VB program before running the query?

  • Form on a SQL Query - doesn't work with SELECT * - bug or feature ?

    When I do this,
    Create Page -> Page with Component -> Form -> Form on a SQL Query -> SELECT * FROM EMP
    I do not get any items displayed and it creates a simple HTML region / page. Do we have to necessarily specify the column names ?
    Iam looking at a way to see if any addition of columns in the table does not involve IT intervention in recreating the form.
    When we try to create with Form on a SQL Query, then shouldn't it be similar to the Report where the same thing works, if I give SELECT function_returning_columns() from DUAL even then the same thing happens where it creates an ITEM called functions_returning_columns() it creates HTML region
    I asked a related question with no answer :-( in
    Dynamic Creation of Items in Runtime through Application UI

    Hi Marc,
    Thanks. I just tried something like this. Taking the EMP table example, (it doesn't matter which table), I created a region based on a Pl/Sql function returning SQL query
    ( I selected the vertical report template including nulls to display it like a form ) :
    DECLARE
    v_sql VARCHAR2(3000) ;
    mn_idx NUMBER := 1 ;
    BEGIN
    v_sql := 'SELECT ' ;
    FOR recs IN (SELECT * FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = 'EMP' ORDER BY COLUMN_ID)
    LOOP
    v_sql := v_sql || 'HTMLDB_ITEM.TEXT(' || mn_idx || ',' ||
    recs.column_name || ') ' || recs.column_name || ', ' ;
    mn_idx := mn_idx + 1 ;
    END LOOP ;
    v_sql := SUBSTR(v_sql, 1, LENGTH(v_sql) -2) ;
    v_sql := v_sql || ' FROM EMP WHERE EMPNO = 7369 ORDER BY 1 ' ;
    RETURN v_sql ;
    END ;
    This allowed me to do my updates etc.., Then I created a button called 'Apply' and a process called 'update_changes' on button click and defined this:
    DECLARE
    v_sql varchar2(1000) ;
    mn_ctr NUMBER := 1 ;
    BEGIN
    v_sql := 'BEGIN UPDATE EMP SET ' ;
    FOR recs IN (select COLUMN_ID, COLUMN_NAME, DATA_TYPE
    from all_tab_columns where table_name = 'EMP'
    ORDER BY COLUMN_ID) loop
    -- Make changes here if required- this is assuming 9 columns --
    v_sql := v_sql || recs.column_name || ' = HTMLDB_APPLICATION.G_F0' || mn_ctr || '(1),' ;
    mn_ctr := mn_ctr + 1;
    end loop ;
    v_sql := substr(v_sql, 1, length(v_sql) - 1) ;
    v_sql := v_sql || ' WHERE EMPNO = 7369; END ;' ;
    execute immediate (v_sql) ;
    END ;
    Since this is for example, I didn't include code for Checksum and hardcoded empno = condition and have provision for 9 columns. I made some changes and tried saving it and I was able to do it.
    I altered the table to add a column / drop a column and when I relogin, Iam able to see the changes.
    Can you tell me if there could be any drawbacks in this approach ?.

  • SQL Query (PL/SQL Function Body returning SQL query) doesn't return any row

    I have a region with the following type:
    SQL Query (PL/SQL Function Body returning SQL query).
    In a search screen the users can enter different numbers, separated by an ENTER.
    I want to check these numbers by replacing the ENTER, which is CHR(13) || CHR(10) I believe, with commas. And then I can use it like this: POD IN (<<text>>).
    It's something like this:
    If (:P30_POD Is Not Null) Then
    v_where := v_where || v_condition || 'POD IN (''''''''||REPLACE(''' || :P30_POD || ''', CHR(13) || CHR(10), '','')||'''''''''')';
    v_condition := ' AND ';
    End If;
    But the query doesn't return any rows.
    I tried to reproduce it in Toad:
    select * from asx_worklistitem
    where
    POD IN (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
    ==> This is the query that does't return any rows
    select (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
    from dual;
    ==> This returns '541449200000171813','541449206006341366'
    select * from asx_worklistitem
    where pod in ('541449200000171813','541449206006341366');
    ==> and when I copy/paste this in the above query, it does return my rows.
    So why does my first query doesn't work?
    Doe anyone have any idea?
    Kind regards,
    Geert
    Message was edited by:
    Zorry

    Thanks for the help.
    I made it work, but via the following code:
    If (:P30_POD Is Not Null) Then
    v_pods := REPLACE(:P30_POD, CHR(13) || CHR(10));
    v_where := v_where || v_condition || 'POD IN (';
    v_counter := 1;
    WHILE (v_counter < LENGTH(v_pods)) LOOP
    v_pod := SUBSTR(v_pods, v_counter, 18);
    IF (v_counter <> 1) THEN
    v_where := v_where || ',';
    END IF;
    v_where := v_where || '''' || v_pod || '''';
    v_counter := v_counter + 18;
    END LOOP;
    v_where := v_where || ')';
    v_condition := ' AND ';
    End If;But now I want to make an update of all the records that correspond to this search criteria. I can give in a status via a dropdownlist and that I want to update all the records that correspond to one of these POD's with that status.
    For a region you can build an SQL query via PL/SQL, but for a process you only have a PL/SQL block. Is the only way to update all these records by making a loop and make an update for every POD that is specified.
    Because I think this will have a lot of overhead.
    I would like to make something like a multi row update in an updateable report, but I want to specify the status from somewhere else. Is this possible?

  • Buckup SQL Script doesn't work

    Hi  all,
    In ECC i want schedule ASE jobs to  dump transaction logs,i do it fellow the note 1588316 step by step .  In  schedule jobs my sql script doesn't work,but it works in sql command line.
    sql script :
    dump transaction DEV using config= 'DEVLOG'
    Anybody can give me some advise to face this issue?  Thanks in advance.
    David Lv

    Hi  all,
    My problem sloved, it's JSagent problem.
    sp_dumptrans not working at dbacockpit @Alcino Melo
    use sybmgmtdb
    go
    sp_js_wakeup "start_js",1
    go
    after start  JSagent  my sql script can run 
    Thanks  all
    David Lv

  • The query doesn't work

    Hi kind people!
    I have udf  TEST on the picture. The query on the picture I have connected to the field Test and conected to field description too. But with the field Description the query doesn't work. U_Producer is the name of another field. Why does not it work?

    Hi Gordon!
    From the right I have UDF for choosing the spare parts of auto.  I want to add a spare part, for example to item master data (OITM). I enter every field step by step 1 - 4 by choosing frome use tables linked in every field. I choose fielf 1 (Brand) for example TOYOTA and in the use table of 2(Model) field i see only values that belong to TOYOTA that to say corolla, carina, vista and so on.  But to find any component  exactly i put on the loupe in the field 5 and see a table where all types of auto parts in the world but they are filtered with parametrs in 1-4 fields. I chhose needed component and get in the 5 field any code of a choosed part. Then i d liked to link the table of filed 5 to field Description too and to filter component with code in field 5 in order to get item description from the use table. I used the one method of filtering in all fields Here i see that i can to filter values using use fields but I don't use it in standart field description, although the usual selection of elements of any use table works. As a result a see that the problem that doesn't work the selection and filtration in the field description but it works in in UDF.

  • An sql query is not working

    Hello everybody,
    I want to enter a word in a table if that word does not already exist in the table.
    I wrote a query like this.
    String word="Football";
    sql="INSERT INTO m_word_list (word_text , category_id , used_counter, date_of_addition, added_by, is_status ) VALUES ('"+word+"', 2, 0, '"+todaysDate+"', '1', '1')WHERE '"+word+"' NOT IN
    (SELECT * FROM `m_word_list` WHERE word_text = '"+word+"');
    Where am I wrong in the query?
    Please help.

    1.) Always post the exception, error message and whatever detail you've got when something "doesn't" work.
    2.) Always use PreparedStatements to execute parameterized queries/updates instead of dynamically building the String
    3.) INSERT INTO doesn't have a where clause.
    Why don't you simply make the wort_text column unique and simply try to insert. If there's already such a word then you'll get a message which tells you.

  • Where rownum=2 in my sql query is not working . Why ??

    Hello,
    i am using Oracle 11g .Referring scott schema's emp table.
    I just issued this sql query with the intention to get second highest salary of a employee. But i am unable to understand why my query fails ?
    select rownum,empno,ename,sal from (select empno,ename,sal from emp order by sal desc) where rownum=2;This query is returning no rows . Can you tell why this query is returning no rows ?

    888953 wrote:
    Because you can use ROWNUM only to limit the number of returned records, not to return a specific record.
    So only this has sense (n any number):
    ROWNUM <= n
    or
    ROWNUM = 1 (which is equal to ROWNUM <= 1)
    Anything else will not return a row.As i said ,
    select * from (select rownum rn,empno,ename,sal from (select empno,ename,sal from emp order by sal desc)) where rn=2;this query is working fine.So rownm can be used to return a specific record . Please rectify me if i am wrong .

  • SQL Query Report Not working

    Hi,
    I have a region as the type
    "SQL Query (PL/SQL function body returning SQL query)".
    The query works fine for reports if I query two columns. Select 1, 2 from table.
    For some reason if the returning query has more than three columns (select 1, 2, 3 from table), I get an error:
    "report error:
    ORA-01403: no data found"
    Any help would be great. Thanks.

    Hi,
    I've been trying all sorts of things on a test report and the only way that I get extra columns is by including derived columns in the report. Otherwise, even with custom headings, adding or removing columns in the report's PL/SQL adjusts the columns as I would expect.
    Are your extra columns derived or can your report return a varying number of columns?
    Andy

  • Multiple conditions in Query doesn't work

    Hi all,
    I've made a query pointing on a Multiprovider wich 's made of two main dimension ( multiple infoproviders ) :
    contract and pricing and on the other hand  Sales and Revenues.
    In my Query, one condition's concerned by a contract & pricing key figures ( Number of pricing condition > 0 ), and another one is about a Minimum Turnover Sales & Revenues key Figures restriction( by a prompt ).
    This doesn't match, Some rows are missing, and while a condition is active , the other one can't be..
    If any one meet this kind of problem before ?
    Thanks and sorry for my bad english..

    Hi,
    I already try to create another key figure wich made like this :
    Number of condition * Turnover
    and made a condition on this result.
    But the main problem is  if the contract doesn't have Turnover, it will not shown the rows with condition ..( the condition is on the single value 'number of document ) and if I put anotehr condition with number of condition > 0, it still doesn't work..
    thanks for help.

  • SQL / XML doesn't work here

    Hi,
    I'm working on Oracle9i Enterprise Edition Release 9.2.0.5.0.
    and with SQLPLUS i try this :
    SELECT XMLFOREST(1 "test", 2 "test2") from dual;
    But it seems taht it doesn't work I jsut have this result without error :
    XMLFOREST(1"TEST",2"TEST2")
    Has Someone an idea ?
    thanks.
    Romeo.

    SQL*Plus: Release 10.2.0.1.0 - Production on Wed Dec 7 07:25:53 2005
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> SELECT XMLFOREST(1 "test", 2 "test2") from dual;
    XMLFOREST(1"TEST",2"TEST2")
    <test>1</test><test2>2</test2>
    SQL>
    Um... which release of SQL*PLUS are you using to get your result...
    Can you try
    SELECT XMLFOREST(1 "test", 2 "test2").getClobVal() from dual;

  • SQL batch doesn't work; How to fetch related objects with fetch group?

    I have two questions:
    1. SQL Batch doesn't seem to work. I have tested some batch object creation
    with BatchLimit set to -1, 0, 1, 25, 100. They all have similar
    performance.
    kodo.jdbc.DBDictionary: BatchLimit=25
    2. How to use custom fetch group to fetch related objects? The example of
    custom fetch group only show how to fetch different attributes in different
    groups. I have a test cases where I would like to pre-fetch related objects
    to save round trip.
    Enviroments:
    * Kodo 3.1.0 RC1
    * Oracle 9i release 1
    Thanks for any help!
    Qingshan Luo
    Senior Software Engineer
    Open Harbor
    1123 Industrial Road
    San Carlos, CA 94070
    Phone: 650-413-4251
    Fax: 650-413-4298

    try poracle 10g driver. At least they fixed terrible CLOB bug may be batch
    to. BTW 9.2.x has problem with batching with deferred constraints so be
    careful
    "Greg Campbell" <[email protected]> wrote in message
    news:c3dmnu$rmj$[email protected]..
    >
    "Qingshan Luo" <[email protected]> wrote in message
    news:c3dg7q$mdl$[email protected]..
    Hi,
    I have two technical questions with Kodo.
    1. SQL Batch doesn't seem to work. I have tried batch size of -1, 0, 1,25.
    But the performance from batch creating objects is not affected by batch
    size.
    kodo.jdbc.DBDictionary: BatchLimit=25You may be running into a bug in the Oracle 9.2 driver. That driverdoesn't
    reliably give update counts when using batching and prepared statement
    caching. By default, Kodo will turn off batching. You can manuallyenable
    batching by setting the BatchLimit on your DBDictionary, as you've done.If
    you do this, though, you may want to turn off prepared statement cachingby
    setting MaxCachedStatements to 0 (see
    http://www.solarmetric.com/Software/Documentation/3.1.0RC1/docs/ref_guide_dbsetup.html#ref_guide_dbsetup_builtin).
    >
    2. How to use custom fetch groups to eagerly fetch related persistable
    objects? Example only showed attributes, not relationships.You can find information on setting up eager fetching of relations at
    http://www.solarmetric.com/Software/Documentation/3.0.3/docs/ref_guide_
    perfpack_eager.html
    Basically, you'll need to add the relations to your fetch group, and
    set the eager fetching mode.
    Enviroment:
    * Kodo 3.1.0 RC1
    * Oracle 9i release 1.
    Qingshan Luo
    Senior Software Engineer
    Open Harbor
    1123 Industrial Road
    San Carlos, CA 94070
    Phone: 650-413-4251
    Fax: 650-413-4298

  • SQL commands doesn't work

    I've instaled an oracle lite8i version 4.0.0.2.0 on Windows 98 operation system.
    When i try to change something in polite DB, the sql commands doesn't cause any effect on the polite.
    For example :
    when i type "alter user system identified by asd", even connected as system, i receive the message "Operation 0 succeeded", but the password doesn't change.
    This also happen with "create user ... " "create table ... "
    What should i do ????
    Thanks

    "/" does work . Please give a full working example that doesn't work.
    In Home>SQL>SQL Commands you usually execute a single command.
    But you can write multiple commands like:
    create table xx1(n number)
    drop table xx1
    /To execute one after the other, just highlight the first
    create table xx1(n number)
    /and press <ctrl>+<enter> .
    Then highlight the next command and press <ctrl>+<enter> again.
    --- OR ---
    create a sql script in Home>SQL>SQL Scripts . Then you can execute multiple commands at once.
    ~Dietmar.

  • WITH Clause query doesn't work in Oracle Reports.

    Hi Gurus,
    I'm using a WITH clause query and need to build a report using the same query.
    But when i'm trying to build a report, query is giving error as "WITH clause table or view doesn't exists".
    But the same query perfectly works in sql prompt.
    Oracle Reports doesn't supports WITH clause query?
    Please suggest.
    Thanks,
    Onkar

    I ran into a similar problem before and worked around it by moving the query to a pipelined function in the database as described at WITH clause unexpectedly causes ORA-00942 in Reports Builder
    Hope this helps.

  • Query doesn't work.

    I am declarin a cursor like this inside a pl\sql editor in Oracle Forms 6i:
    cursor customer_services is select * from Customers inner join Services on Customers.ServiceID=Services.ServiceID.
    And when i compile the followin error appears:
    Error 103:
    Encountered the symbol Join when expecting one of the following:
    If i remove the inner join the query works.I mean it doesn't accept joins.

    select * from Customers, Services where Customers.ServiceID(+)=Services.ServiceID That's an outer join.

Maybe you are looking for

  • How to perform auth check on Web Service calling BAPI in R/3 via XI?

    Hi all, We are running Net weaver PI 7.0 SPS11 and 4.6C R/3 and working on proof-of-concept project using BAPIs exposed on XI as Web Services and called from external SOAP client (MS SharePoint). We got it working fine with HTTPS and SOAP protocol as

  • CC 2014 benchmarks so far. Updating as their completed on different systems

    Before 6/18/2014 update 4790K @ 4.7GHz 32GB DDR3 1600 1TB Crucial M550 SSD 780Ti AVCHD 4 Layer 30 Minute test Adobe CC 3 Layer - 26:30 4 Layer – 29:40 Red 4K to DPX 4096 x 2048 24p Full Range (max bit depth) 3 Layer - 5:52 4 layer - 5:20 Red 6K to DP

  • Convert from 5.1.1 to 2009

    Hi, could you please convert from 5.1.1 to 2009 ? thank you YG Solved! Go to Solution. Attachments: Lost and Found.zip ‏34 KB

  • C.O.D option in eCommerce cart

    Hi all, I have a feeling this may have been asked here before. I have a C.O.D option on my shopping cart which works fine. But the invoice shows the "Total amount" as already paid. Does anyone know how to set this to amount outstanding = "Total amoun

  • CS4 soooooo slow!

    I have just upgraded to CS4 (from CS3) and also bought new workstations. The new computer is an HP Z800 dual quad core, with 6 GB RAM, Nvidia FX4800 graphics card running Vista Business 64 bit. I am currently trying to work on and render a 30" tvc cr