Home » SQL & PL/SQL » SQL & PL/SQL » ORA-00907: missing right parenthesis
ORA-00907: missing right parenthesis [message #604899] Sun, 05 January 2014 23:46 Go to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi all,

I got ORA-00907: missing right parenthesis error in LEAD Function can you please suggest me?

select empno,comm,
lead(comm ignore nulls) over(order by empno)next_comm
from emp
order by empno


Thank you
Re: ORA-00907: missing right parenthesis [message #604900 is a reply to message #604899] Sun, 05 January 2014 23:54 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
it works for me.
[oracle@localhost ~]$ sqlplus scott/tiger

SQL*Plus: Release 11.2.0.2.0 Production on Sun Jan 5 21:52:51 2014

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select empno,comm,
lead(comm ignore nulls) over(order by empno)next_comm
from emp
order by empno  2    3    4  
  5  /

     EMPNO       COMM  NEXT_COMM
---------- ---------- ----------
      7369                   300
      7499        300        500
      7521        500       1400
      7566                  1400
      7654       1400          0
      7698                     0
      7782                     0
      7788                     0
      7839                     0
      7844          0
      7876

     EMPNO       COMM  NEXT_COMM
---------- ---------- ----------
      7900
      7902
      7934

14 rows selected.

SQL> 


Re: ORA-00907: missing right parenthesis [message #604901 is a reply to message #604900] Sun, 05 January 2014 23:59 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi Blackswan,

please find the below..
       
SQL*Plus: Release 10.1.0.4.2 - Production on Mon Jan 6 11:27:18 2014

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select empno,comm,
  2  lead(comm ignore nulls) over(order by empno)next_comm
  3  from emp
  4  order by empno  2    3    4  
  5  /
lead(comm ignore nulls) over(order by empno)next_comm
          *
ERROR at line 2:
ORA-00907: missing right parenthesis



Thank You
Re: ORA-00907: missing right parenthesis [message #604902 is a reply to message #604901] Mon, 06 January 2014 00:03 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>SQL*Plus: Release 10.1.0.4.2 - Production on Mon Jan 6 11:27:18 2014
>Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production

Oracle version mis-match?
Re: ORA-00907: missing right parenthesis [message #604903 is a reply to message #604902] Mon, 06 January 2014 00:06 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi BlackSwan,

Can you please suggest how can i overcome this problem?

Thank You
Re: ORA-00907: missing right parenthesis [message #604904 is a reply to message #604903] Mon, 06 January 2014 00:07 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Can you please suggest how can i overcome this problem?
only use MSACCESS
Re: ORA-00907: missing right parenthesis [message #604905 is a reply to message #604899] Mon, 06 January 2014 00:20 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

"ignore nulls" was introduced in 11.2.

Re: ORA-00907: missing right parenthesis [message #604906 is a reply to message #604905] Mon, 06 January 2014 00:25 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi,

Blackswan suggested me only use MSACCESS, how can i use this?

Thank You
Re: ORA-00907: missing right parenthesis [message #604911 is a reply to message #604903] Mon, 06 January 2014 01:54 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
mist598 wrote on Mon, 06 January 2014 11:36
Can you please suggest how can i overcome this problem?


Since you are not in Oracle DB version 11gR2, you cannot use IGNORE NULLS option with LEAD. The workaround for this is to use a CASE construct.

Something like :

SELECT id,
  2      sal     ,
  3      deptno  ,
  4      comm    ,
  5      CASE
  6        WHEN comm IS NULL
  7        THEN lead(comm) over(partition BY deptno order by id)
  8        ELSE comm
  9      END AS lead_comm
 10       FROM t
 11  /

Re: ORA-00907: missing right parenthesis [message #604912 is a reply to message #604911] Mon, 06 January 2014 02:02 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Thank You very much Lalit Kumar..-)
Re: ORA-00907: missing right parenthesis [message #604946 is a reply to message #604911] Mon, 06 January 2014 06:58 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Lalit Kumar B wrote on Mon, 06 January 2014 02:54
Something like :


??? It is not even close. Compare:

SQL> select  empno,
  2          comm,
  3          lead(comm ignore nulls) over(order by empno) next_comm
  4    from  emp
  5    order by empno
  6  /

     EMPNO       COMM  NEXT_COMM
---------- ---------- ----------
      7369                   300
      7499        300        500
      7521        500       1400
      7566                  1400
      7654       1400          0
      7698                     0
      7782                     0
      7788                     0
      7839                     0
      7844          0
      7876

     EMPNO       COMM  NEXT_COMM
---------- ---------- ----------
      7900
      7902
      7934

14 rows selected.

SQL> select  empno,
  2          comm,
  3          case
  4            when comm is null
  5              then lead(comm) over(order by empno)
  6            else comm
  7          end next_comm
  8    from  emp
  9    order by empno
 10  /

     EMPNO       COMM  NEXT_COMM
---------- ---------- ----------
      7369                   300
      7499        300        300
      7521        500        500
      7566                  1400
      7654       1400       1400
      7698
      7782
      7788
      7839                     0
      7844          0          0
      7876

     EMPNO       COMM  NEXT_COMM
---------- ---------- ----------
      7900
      7902
      7934

14 rows selected.


Workaround is to use first_value:

SQL> select  empno,
  2          comm,
  3          first_value(comm ignore nulls) over(order by empno rows between 1 following and unbounded following) next_comm
  4    from  emp
  5    order by empno
  6  /

     EMPNO       COMM  NEXT_COMM
---------- ---------- ----------
      7369                   300
      7499        300        500
      7521        500       1400
      7566                  1400
      7654       1400          0
      7698                     0
      7782                     0
      7788                     0
      7839                     0
      7844          0
      7876

     EMPNO       COMM  NEXT_COMM
---------- ---------- ----------
      7900
      7902
      7934

14 rows selected.

SQL>


SY.
Re: ORA-00907: missing right parenthesis [message #604950 is a reply to message #604946] Mon, 06 January 2014 07:57 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
In fact, I suggest not to use LEAD/LAG with IGNORE NULLS unless you are on 12C:

SQL> select  banner
  2    from  v$version
  3  /

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE    11.2.0.2.0      Production
TNS for HPUX: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production

Elapsed: 00:00:00.01
SQL> drop table tbl purge
  2  /

Table dropped.

Elapsed: 00:00:00.10
SQL> create table tbl
  2    as
  3      select  level id,
  4              case mod(level,10)
  5                when 0 then 'NAME' || level
  6              end name
  7        from  dual
  8        connect by level < 10001
  9  /

Table created.

Elapsed: 00:00:00.11
SQL> drop table tbl1 purge
  2  /

Table dropped.

Elapsed: 00:00:00.07
SQL> create table tbl1
  2    as
  3      select  id,
  4              name,
  5              first_value(name ignore nulls) over(order by id rows between 1 following and unbounded following) next_name
  6        from  tbl
  7  /

Table created.

Elapsed: 00:00:01.45
SQL> drop table tbl1 purge
  2  /

Table dropped.

Elapsed: 00:00:00.07
SQL> create table tbl1
  2    as
  3      select  id,
  4              name,
  5              lead(name ignore nulls) over(order by id) next_name
  6        from  tbl
  7  /

Table created.

Elapsed: 00:00:14.83 <-- Huge performance hit
SQL>


12C:

SQL> select  banner
  2    from  v$version
  3  /

BANNER
--------------------------------------------------------------------------------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
PL/SQL Release 12.1.0.1.0 - Production
CORE    12.1.0.1.0      Production
TNS for 64-bit Windows: Version 12.1.0.1.0 - Production
NLSRTL Version 12.1.0.1.0 - Production

Elapsed: 00:00:00.13
SQL> drop table tbl purge
  2  /

Table dropped.

Elapsed: 00:00:00.06
SQL> create table tbl
  2    as
  3      select  level id,
  4              case mod(level,10)
  5                when 0 then 'NAME' || level
  6              end name
  7        from  dual
  8        connect by level < 10001
  9  /

Table created.

Elapsed: 00:00:00.17
SQL> drop table tbl1 purge
  2  /

Table dropped.

Elapsed: 00:00:00.03
SQL> create table tbl1
  2    as
  3      select  id,
  4              name,
  5              first_value(name ignore nulls) over(order by id rows between 1 following and unbounded following) next_name
  6        from  tbl
  7  /

Table created.

Elapsed: 00:00:00.16
SQL> drop table tbl1 purge
  2  /

Table dropped.

Elapsed: 00:00:00.07
SQL> create table tbl1
  2    as
  3      select  id,
  4              name,
  5              lead(name ignore nulls) over(order by id) next_name
  6        from  tbl
  7  /

Table created.

Elapsed: 00:00:00.05
SQL>


SY.
Re: ORA-00907: missing right parenthesis [message #605017 is a reply to message #604950] Mon, 06 January 2014 23:01 Go to previous message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Thanks to Solomon Yakobson we are given to explanation to me.. Smile

[Updated on: Sun, 09 March 2014 03:04] by Moderator

Report message to a moderator

Previous Topic: join two virtual tables with if-else condition join
Next Topic: Decode explanation
Goto Forum:
  


Current Time: Fri Apr 26 13:25:41 CDT 2024