Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. ORA-00936 missing expression

ORA-00936 missing expression

Scheduled Pinned Locked Moved Database
helptools
9 Posts 3 Posters 19 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    StrayGrey
    wrote on last edited by
    #1

    When run the following script returns an ORA-00936 missing expression error. [Code] select MemNumber, Turnover from ( select mem_number MemNumber, sum(trans_turnover) Turnover from members join transact on mem_number = trans_code where Trans_date between '&Start' and '&End' and mem_barred = 0 group by mem_number order by turnover desc ) where rownum <=200 / [/code] Please tell me how I should fix it.

    Regards, Alf Stockton

    A W 2 Replies Last reply
    0
    • S StrayGrey

      When run the following script returns an ORA-00936 missing expression error. [Code] select MemNumber, Turnover from ( select mem_number MemNumber, sum(trans_turnover) Turnover from members join transact on mem_number = trans_code where Trans_date between '&Start' and '&End' and mem_barred = 0 group by mem_number order by turnover desc ) where rownum <=200 / [/code] Please tell me how I should fix it.

      Regards, Alf Stockton

      A Offline
      A Offline
      Al Ortega
      wrote on last edited by
      #2

      [Code] where rownum <=200 [/code] Your where clause references a "rownum" column... Your select statement does not produce a column named "rownum"...

      hth Al

      S W 2 Replies Last reply
      0
      • A Al Ortega

        [Code] where rownum <=200 [/code] Your where clause references a "rownum" column... Your select statement does not produce a column named "rownum"...

        hth Al

        S Offline
        S Offline
        StrayGrey
        wrote on last edited by
        #3

        Thank you. I will try your suggestion.

        Regards, Alf Stockton

        1 Reply Last reply
        0
        • S StrayGrey

          When run the following script returns an ORA-00936 missing expression error. [Code] select MemNumber, Turnover from ( select mem_number MemNumber, sum(trans_turnover) Turnover from members join transact on mem_number = trans_code where Trans_date between '&Start' and '&End' and mem_barred = 0 group by mem_number order by turnover desc ) where rownum <=200 / [/code] Please tell me how I should fix it.

          Regards, Alf Stockton

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          If you're running this in SQL*Plus or a program based on that, I would guess that the problem is in & character. This is normally reserved for prompting values so your statement may evaluate to

          where Trans_date between '' and ''

          Also you 'should' provide an alias for sub select in FROM. If you're using tools mentioned above, they should show you the line where the problem is.

          The need to optimize rises from a bad design

          1 Reply Last reply
          0
          • A Al Ortega

            [Code] where rownum <=200 [/code] Your where clause references a "rownum" column... Your select statement does not produce a column named "rownum"...

            hth Al

            W Offline
            W Offline
            Wendelius
            wrote on last edited by
            #5

            rownum is a pseudocolumn so it's created automatically and defining it in the inner select would change the logic of the statement.

            The need to optimize rises from a bad design

            A 1 Reply Last reply
            0
            • W Wendelius

              rownum is a pseudocolumn so it's created automatically and defining it in the inner select would change the logic of the statement.

              The need to optimize rises from a bad design

              A Offline
              A Offline
              Al Ortega
              wrote on last edited by
              #6

              Good catch, try asking tom.... http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html[^]

              hth Al

              W 1 Reply Last reply
              0
              • A Al Ortega

                Good catch, try asking tom.... http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html[^]

                hth Al

                W Offline
                W Offline
                Wendelius
                wrote on last edited by
                #7

                Didn't quite understand your point? There's a good example in the article:

                select *
                from
                (select *
                from t
                order by id)
                where rownum <= 10

                which returns top 10 rows. Rownum is placed on the outer query and the inner query selects only columns from the table t. Rownum is used on the ordered result set to ensure that really top 10 rows based on id column are returned. I understood that the original query in this question was doing top N fetch.

                The need to optimize rises from a bad design

                A 1 Reply Last reply
                0
                • W Wendelius

                  Didn't quite understand your point? There's a good example in the article:

                  select *
                  from
                  (select *
                  from t
                  order by id)
                  where rownum <= 10

                  which returns top 10 rows. Rownum is placed on the outer query and the inner query selects only columns from the table t. Rownum is used on the ordered result set to ensure that really top 10 rows based on id column are returned. I understood that the original query in this question was doing top N fetch.

                  The need to optimize rises from a bad design

                  A Offline
                  A Offline
                  Al Ortega
                  wrote on last edited by
                  #8

                  I know that's why I said good catch... when I saw the rownum I was thinking of it as ( SELECT col1, col2,ROW_NUMBER() OVER (PARTITION BY col1_id ORDER BY col1) AS rownum FROM employee ) where rownum < 200 My bad..

                  hth Al

                  W 1 Reply Last reply
                  0
                  • A Al Ortega

                    I know that's why I said good catch... when I saw the rownum I was thinking of it as ( SELECT col1, col2,ROW_NUMBER() OVER (PARTITION BY col1_id ORDER BY col1) AS rownum FROM employee ) where rownum < 200 My bad..

                    hth Al

                    W Offline
                    W Offline
                    Wendelius
                    wrote on last edited by
                    #9

                    Oh, I see. I clearly misunderstood your reply to my post. Sorry for that.

                    The need to optimize rises from a bad design

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups