views:

132

answers:

1

I'm fairly new to the language, and I was wondering if tail calls were optimized. In other language I could examinate the machine code or an intermediate representation and figure it for myself but I have no idea about how to do that in PL/SQL.

Thanks in advance.

+2  A: 

The online docs suggest not:

http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14261/subprograms.htm#i2884

Each recursive call creates a new instance of any items declared in the subprogram, including parameters, variables, cursors, and exceptions. Likewise, new instances of SQL statements are created at each level in the recursive descent.

And:

At least one path must lead to a terminating condition. Otherwise, the recursion would go on until PL/SQL runs out of memory and raises the predefined exception STORAGE_ERROR.

If tail call optimisation was available, it wouldn't run out of storage (though it might hit some timeout if you let it run for too long.)

You may be able to experimentally see what it does: write a recursive function that ends with a tail call to itself, and observe the memory usage of the Oracle process when you call it, or see what error message you get. See if you can get it to hang indefinitely without using increasing memory.

Daniel Earwicker
I have coded a simple factorial and executing it on a Oracle XE running on my workstation has exhausted its Virtual memory, so it seems you were right. Thanks a lot.BTW, is it possible to get any kind of assembler from Oracle?
Samuel
I'd assume that PL/SQL is largely interpreted.
Daniel Earwicker
PL/SQL can be interpreted or compiled in newer versions. If you really want to get low-level you can try programming in PRO*C.
Adam Hawkes