Home » SQL & PL/SQL » SQL & PL/SQL » Dynamic Memory allocation
Dynamic Memory allocation [message #346386] Mon, 08 September 2008 07:05 Go to next message
panyam
Messages: 146
Registered: May 2008
Senior Member

Is it possible to Allocate Memory dynamically for Variables in procedures and functions depending upon the arguements passed ??
Re: Dynamic Memory allocation [message #346387 is a reply to message #346386] Mon, 08 September 2008 07:10 Go to previous messageGo to next message
Michel Cadot
Messages: 64098
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
They already are dynamically allocated.

Regards
Michel
Re: Dynamic Memory allocation [message #346389 is a reply to message #346386] Mon, 08 September 2008 07:15 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
Why do you think you have to allocate memory manually in the first place?
Re: Dynamic Memory allocation [message #346395 is a reply to message #346387] Mon, 08 September 2008 07:28 Go to previous messageGo to next message
panyam
Messages: 146
Registered: May 2008
Senior Member
Hi Michel ,

You assume a situation where in a pl/sql block i have to allocate memory for a variable based on the size of a variable passed at run time ;

some like this :

SQL> declare
  2  a varchar(20);
  3  begin
  4  a := '&b';
  5  dbms_output.put_line(a);
  6  end;
  7  /
Enter value for b: reserve for the
old   4: a := '&b';
new   4: a := 'reserve for the';

PL/SQL procedure successfully completed.

SQL> /
Enter value for b: Rama is the greatest boy of the School
old   4: a := '&b';
new   4: a := 'Rama is the greatest boy of the School';
declare
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 4

[Updated on: Mon, 08 September 2008 07:57] by Moderator

Report message to a moderator

Re: Dynamic Memory allocation [message #346398 is a reply to message #346395] Mon, 08 September 2008 07:50 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
That's not memory allocation - that's ust defining the maximum size of a string.

You cannot dynamicaly assign the size of Varchar2 variables.
Re: Dynamic Memory allocation [message #346405 is a reply to message #346395] Mon, 08 September 2008 07:58 Go to previous message
Michel Cadot
Messages: 64098
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Use the correct size for the variable.
When you declare a VARCHAR2 variable nothing is allocated, space is allocated when you assign it.

Regards
Michel
Previous Topic: index
Next Topic: Merge with extra condition
Goto Forum:
  


Current Time: Fri Dec 02 12:05:46 CST 2016

Total time taken to generate the page: 0.08913 seconds