Home » SQL & PL/SQL » SQL & PL/SQL » using nested table in a package ...
using nested table in a package ... [message #186411] Mon, 07 August 2006 19:51 Go to next message
m_arafa
Messages: 36
Registered: June 2006
Member
hi,

when i create this package ...

################################

create or replace package num_pack
as
type num_table is table of number;
function ss1 return num_table;
function ss2 return num_table;
end num_pack;

create or replace package body num_pack
as
v_max pls_integer := 0;

function ss1 return num_table
is
v_num num_table := num_table();
i pls_integer;
begin
for i in 1..20 loop
v_num.extend;
v_num(i) := i * 2;
end loop;
v_max := i;
return v_num;
end ss1;

function ss2 return num_table
is
v_num num_table := num_table();
begin
for i in 1..v_max loop
v_num.extend;
v_num(i) := ss1(i); -- an error in this line
end loop;
return v_num;
end ss2;

end num_pack;

################################

it cause this error :

pls-00306 : wrong number or types of arguments in call to 'ss1'

Re: using nested table in a package ... [message #186419 is a reply to message #186411] Mon, 07 August 2006 21:49 Go to previous messageGo to next message
BlackSwan
Messages: 25037
Registered: January 2009
Location: SoCal
Senior Member
> wrong number or types of arguments in call to 'ss1'
What part of the above do you not understand?
SS1 is NOT defined to accept any argument.
Why are you passing SS1 the argument (1)?
Re: using nested table in a package ... [message #186499 is a reply to message #186419] Tue, 08 August 2006 04:45 Go to previous messageGo to next message
amit_kiran
Messages: 50
Registered: July 2006
Location: UK
Member

Hi,

You have declared function ss1 which does not accept arguments. Then what makes you pass a parameter value to the function ??

v_num(i) := ss1(i);

Razz
Re: using nested table in a package ... [message #186645 is a reply to message #186499] Tue, 08 August 2006 17:38 Go to previous messageGo to next message
m_arafa
Messages: 36
Registered: June 2006
Member
ok
i try to modify this code ,will be...

function ss1 (x number) return num_table
...
i := x;
...
end ss1;


and still wrong ...

please give me alternate solution ....
Re: using nested table in a package ... [message #186792 is a reply to message #186645] Wed, 09 August 2006 10:25 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
The usual question I'm afraid.

When you say 'and still wrong', could you actually let us know what the error message is?

I think a better solution would have been to modify function SS2 so that it called SS1 correctly, rather than changing SS1.
Re: using nested table in a package ... [message #186793 is a reply to message #186792] Wed, 09 August 2006 10:25 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
You did change the definition of SS1 in the package header as well, didn't you?
Re: using nested table in a package ... [message #186842 is a reply to message #186793] Wed, 09 August 2006 16:01 Go to previous messageGo to next message
m_arafa
Messages: 36
Registered: June 2006
Member
i try to be .....and it fail......


create or replace package num_pack
as
type num_table is table of number;
function ss1 (x number) return num_table;
function ss2 return num_table;
end num_pack;

create or replace package body num_pack
as
v_max pls_integer := 0;

function ss1 (x number ) return num_table
is
v_num num_table := num_table();
i pls_integer;
begin
for i in 1..20 loop
v_num.extend;
v_num(i) := i * 2;
x := i;
end loop;
v_max := i;
return v_num;
end ss1;

function ss2 return num_table
is
v_num num_table := num_table();
begin
for i in 1..v_max loop
v_num.extend;
v_num(i) := ss1(i);
end loop;
return v_num;
end ss2;

end num_pack;

##################################


and i try again .. and also wrong ..


create or replace package num_pack
as
type num_table is table of number;
function ss1 return num_table;
function ss2 return num_table;
end num_pack;

create or replace package body num_pack
as
v_max pls_integer := 0;

function ss1 return num_table
is
v_num num_table := num_table();
i pls_integer;
begin
for i in 1..20 loop
v_num.extend;
v_num(i) := i * 2;
end loop;
v_max := i;
return v_num;
end ss1;

function ss2 return num_table
is
v_num num_table := num_table();
begin
for i in 1..v_max loop
v_num.extend;
v_num(i) := ss1;
end loop;
return v_num;
end ss2;

end num_pack;

####################

I don't understand ,why?

Re: using nested table in a package ... [message #186852 is a reply to message #186842] Wed, 09 August 2006 19:55 Go to previous messageGo to next message
Barbara Boehmer
Messages: 8631
Registered: November 2002
Location: California, USA
Senior Member
The first error that I noticed is that you have a line that says:

x := i;

but you have not declared x anywhere. There may be other errors. I didn't test it. When posting, you should post a copy and paste of an attempted compilation, complete with line numbers and corresponding error message. When you get an error message, use what it says and the line number to help you figure out what the problem is.
Re: using nested table in a package ... [message #186904 is a reply to message #186842] Thu, 10 August 2006 02:09 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Obviously I'm not being direct enough.

WHAT ERROR ARE YOU GETTING?

What is the actual problem that you are encountering?
All you are doing is posting code and saying "It fails"

We'd like to help. We want to help - otherwise we wouldn't be here, but PLEASE give us the bare minimum information we ask for.

Is that too much to ask?
Re: using nested table in a package ... [message #186909 is a reply to message #186842] Thu, 10 August 2006 02:16 Go to previous message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Tracing through your code, apart from the error Barbara Boehmer spotted, the real problem with your code is this line:
v_num(i) := ss1(i); 

The variable v_num is of type NUM_TABLE, and the function SS1 returns a variable of type NUM_TABLE.

So here you are attempting to populate element (i) of v_num with a NUM_TABLE, rather than a number.
Previous Topic: How to manipulate and insert records from flat fil???
Next Topic: Query to find total number of working day, elimnating saturday(s) and sunday(s)
Goto Forum:
  


Current Time: Mon Dec 05 07:01:35 CST 2016

Total time taken to generate the page: 0.13236 seconds