Home » SQL & PL/SQL » SQL & PL/SQL » Recursive Function -Oracle 11g (Oracle 11g)
Recursive Function -Oracle 11g [message #547403] Wed, 14 March 2012 03:25 Go to next message
gharsola
Messages: 3
Registered: March 2012
Location: Hyderabad
Junior Member
Can any body let me know if recursive functions are supported in ORacle 11g or not.

We are migrating from 8i to 11g.
Re: Recursive Function -Oracle 11g [message #547407 is a reply to message #547403] Wed, 14 March 2012 03:40 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
It is... since the very first version of PL/SQL.

Regards
Michel
Re: Recursive Function -Oracle 11g [message #547409 is a reply to message #547407] Wed, 14 March 2012 03:44 Go to previous messageGo to next message
John Watson
Messages: 9000
Registered: January 2010
Location: Global Village
Senior Member
I tried to create a recursive function, but it will not compile:
SQL*Plus: Release 11.2.0.3.0 Production on Wed Mar 14 08:38:56 2012

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


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


Session altered.

orcl> create or replace function recurf return number as begin
  2  recurf;
  3  end;
  4  /

Warning: Function created with compilation errors.

orcl> sho errors
Errors for FUNCTION RECURF:

LINE/COL ERROR
-------- --------------------------------------------------------------
2/1      PL/SQL: Statement ignored
2/1      PLS-00221: 'RECURF' is not a procedure or is undefined
orcl>

A procedure does compile and run:
orcl> create or replace procedure recurp as begin
  2  recurp;
  3  end;
  4  /

Procedure created.

orcl> exec recurp
but it crashes the database with this in the alert log:
c:\app\john\diag\rdbms\orcl\orcl\trace>type alert_orcl.log
Wed Mar 14 08:40:27 2012
Errors in file C:\APP\JOHN\diag\rdbms\orcl\orcl\trace\orcl_ora_5588.trc  (incident=54299):
ORA-04030: out of process memory when trying to allocate 8204 bytes (PLS PGA hp,PL/SQL STACK)
Incident details in: C:\APP\JOHN\diag\rdbms\orcl\orcl\incident\incdir_54299\orcl_ora_5588_i54299.trc
Use ADRCI or Support Workbench to package the incident.
See Note 411.1 at My Oracle Support for error and packaging details.
Wed Mar 14 08:41:06 2012
Errors in file C:\APP\JOHN\diag\rdbms\orcl\orcl\trace\orcl_j000_2420.trc  (incident=54179):
ORA-04030: out of process memory when trying to allocate 262668 bytes (kxs-heap-w,kllcqgf:kllsltba)
Incident details in: C:\APP\JOHN\diag\rdbms\orcl\orcl\incident\incdir_54179\orcl_j000_2420_i54179.trc
Use ADRCI or Support Workbench to package the incident.
See Note 411.1 at My Oracle Support for error and packaging details.
Wed Mar 14 08:41:06 2012
Exception [type: ACCESS_VIOLATION, UNABLE_TO_READ] [ADDR:0xC] [PC:0x90867B1, 090867B1]
Errors in file C:\APP\JOHN\diag\rdbms\orcl\orcl\trace\orcl_j001_4216.trc  (incident=55619):
ORA-07445: exception encountered: core dump [PC:0x90867B1] [ACCESS_VIOLATION] [ADDR:0xC] [PC:0x90867B1] [UNABLE_TO_READ] []
Incident details in: C:\APP\JOHN\diag\rdbms\orcl\orcl\incident\incdir_55619\orcl_j001_4216_i55619.trc
Use ADRCI or Support Workbench to package the incident.
See Note 411.1 at My Oracle Support for error and packaging details.
Wed Mar 14 08:41:07 2012
Errors in file C:\APP\JOHN\diag\rdbms\orcl\orcl\trace\orcl_ora_5588.trc  (incident=54300):
ORA-04030: out of process memory when trying to allocate 169004 bytes (pga heap,kgh stack)
ORA-04030: out of process memory when trying to allocate 8204 bytes (PLS PGA hp,PL/SQL STACK)
Incident details in: C:\APP\JOHN\diag\rdbms\orcl\orcl\incident\incdir_54300\orcl_ora_5588_i54300.trc
Use ADRCI or Support Workbench to package the incident.
See Note 411.1 at My Oracle Support for error and packaging details.
Wed Mar 14 08:41:08 2012
Process J001 died, see its trace file
kkjcre1p: unable to spawn jobq slave process
Errors in file C:\APP\JOHN\diag\rdbms\orcl\orcl\trace\orcl_cjq0_4212.trc:
Wed Mar 14 08:41:10 2012
Process startup failed, error stack:
Errors in file C:\APP\JOHN\diag\rdbms\orcl\orcl\trace\orcl_psp0_3708.trc:
ORA-27300: OS system dependent operation:CreateThread failed with status: 8
ORA-27301: OS failure message: Not enough storage is available to process this command.
ORA-27302: failure occurred at: ssthrddcr
Wed Mar 14 08:41:10 2012
Dumping diagnostic data in directory=[cdmp_20120314084110], requested by (instance=1, osid=2420 (J000)), summary=[incident=54179].
Wed Mar 14 08:41:11 2012
Process m000 died, see its trace file







Re: Recursive Function -Oracle 11g [message #547410 is a reply to message #547407] Wed, 14 March 2012 03:44 Go to previous messageGo to next message
gharsola
Messages: 3
Registered: March 2012
Location: Hyderabad
Junior Member
I am having one in oracle 8i which is not supporting in 11g..

Function def..

create or replace
function Item_Has_Mass_Needs
( psITEM_CODE varchar2
, psCheck_Locks varchar2 := 'Y'
)
return varchar2
is


REcursive call inside the function.

select 'Y'

from packaging.item_lnk a

where a.ITEM_ID = psITEM_CODE

and a.ITEM_LINK_TYPE_ID = 1 --Saleable Link;;

and fsg.Item_Has_Mass_Needs(a.ITEM_LINK_ID, 'N') = 'Y';



Re: Recursive Function -Oracle 11g [message #547411 is a reply to message #547410] Wed, 14 March 2012 03:47 Go to previous messageGo to next message
gharsola
Messages: 3
Registered: March 2012
Location: Hyderabad
Junior Member
I am getting below error while compiling..

Function FSG.ITEM_HAS_MASS_NEEDS@PDS 11g new
Error(1): PLS-00707: unsupported construct or internal error [2604]
Error(37,3): PL/SQL: SQL Statement ignored
Error(63,16): PL/SQL: ORA-06544: PL/SQL: internal error, arguments: [2604], [], [], [], [], [], [], []
Re: Recursive Function -Oracle 11g [message #547412 is a reply to message #547409] Wed, 14 March 2012 03:56 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
I tried to create a recursive function, but it will not compile


Of course as, in the function, you don't call the function but a procedure with the same name which is not defined.

Quote:
but it crashes the database with this in the alert log


You are in an infinite recursive loop of procedure calls so it will crash when the stack will exceed the available memory which is the error 4030 tells you: "PLS PGA hp,PL/SQL STACK".

Regards
Michel


Re: Recursive Function -Oracle 11g [message #547413 is a reply to message #547411] Wed, 14 March 2012 03:58 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
gharsola wrote on Wed, 14 March 2012 09:47
I am getting below error while compiling..

Function FSG.ITEM_HAS_MASS_NEEDS@PDS 11g new
Error(1): PLS-00707: unsupported construct or internal error [2604]
Error(37,3): PL/SQL: SQL Statement ignored
Error(63,16): PL/SQL: ORA-06544: PL/SQL: internal error, arguments: [2604], [], [], [], [], [], [], []


ORA-06544: PL/SQL: internal error, arguments: [%s], [%s], [%s], [%s], [%s], [%s], [%s], [%s]
 *Cause: A pl/sql internal error occurred.
 *Action:Report as a bug; the first argument is the internal error nuber.


Without the actual code and environment, we can't say more.

Regards
Michel
Re: Recursive Function -Oracle 11g [message #547569 is a reply to message #547413] Wed, 14 March 2012 15:14 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9106
Registered: November 2002
Location: California, USA
Senior Member
Valid recursive functions that don't loop endlessly are supported:

http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/subprograms.htm#i2884

[Updated on: Wed, 14 March 2012 15:16]

Report message to a moderator

Re: Recursive Function -Oracle 11g [message #547574 is a reply to message #547410] Wed, 14 March 2012 15:43 Go to previous message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
gharsola wrote on Wed, 14 March 2012 04:44
I am having one in oracle 8i which is not supporting in 11g..

Function def..

create or replace
function Item_Has_Mass_Needs
( psITEM_CODE varchar2
, psCheck_Locks varchar2 := 'Y'
)
return varchar2
is


REcursive call inside the function.

select 'Y'

from packaging.item_lnk a

where a.ITEM_ID = psITEM_CODE

and a.ITEM_LINK_TYPE_ID = 1 --Saleable Link;;

and fsg.Item_Has_Mass_Needs(a.ITEM_LINK_ID, 'N') = 'Y';







SQL> l
  1  create or replace
  2  function Item_Has_Mass_Needs
  3  ( psITEM_CODE      varchar2
  4  , psCheck_Locks    varchar2 := 'Y'
  5  )
  6  return varchar2
  7  is
  8
  9
 10  REcursive call inside the function.
 11
 12  select     'Y'
 13
 14  from       packaging.item_lnk a
 15
 16  where      a.ITEM_ID = psITEM_CODE
 17
 18  and         a.ITEM_LINK_TYPE_ID = 1         --Saleable Link;;
 19
 20  and         fsg.Item_Has_Mass_Needs(a.ITEM_LINK_ID, 'N') = 'Y';
 21
 22*
SQL> /

Warning: Function created with compilation errors.

SQL> show err
Errors for FUNCTION ITEM_HAS_MASS_NEEDS:

LINE/COL ERROR
-------- -----------------------------------------------------------------
9/16     PLS-00103: Encountered the symbol "INSIDE" when expecting one of
         the following:
         := . ( @ % ; not null range default character
Previous Topic: Customer search / user search (2 threads merged by bb)
Next Topic: HTML code in local variable? (2 Merged)
Goto Forum:
  


Current Time: Sun Apr 26 09:05:27 CDT 2026