Why don't I receive new comments to my e-mail?
Is this possible with
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What is interesting here?
• Duels
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Register!

QAIX > Oracle database development > Is this possible with "execute immediate" 27 April 2006 17:44:47

  Top users: 
  Recent blog posts: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Модератор:

Is this possible with "execute immediate"

Jeremy 24 April 2006 19:47:44
 
Want to call target procedure using dynamic SQL.

Target procedure is defined thus:

create or replace package vr is
procedure form_1
(p_idinnumber default null,
p_nameinutil.array default util.empty_array,
p_valueinutil.array­ default util.empty_array);

Now I want to call this using dynamic sql e.g.

execute immediate
'begin vr.procname(p_id=>1­,p_name=>'||l_name||­'); end;';

where l_name is defined as

l_name util.array;

And util.array is
type array is table of varchar2(4000) index by binary_integer;

The pl/sql with the "execute immediate" statement doesn't compile - and
I understand why - but the question is can anyone tell me how (if) this
can be done? It does need to be dynamic.....


--
jeremy

Oracle 9iR2
Solaris 8
Oracle HTTP Server and mod_plsql
Add comment
Michel Cadot 24 April 2006 19:57:54 permanent link ]
 
"Jeremy" <jeremy0505@gmail.c­om> a йcrit dans le message de news: MPG.1eb7036f3bac3c2­e98a191@news.individ­ual.net...
|
| Want to call target procedure using dynamic SQL.
|
| Target procedure is defined thus:
|
| create or replace package vr is
| procedure form_1
| (p_id in number default null,
| p_name in util.array default util.empty_array,
| p_value in util.array default util.empty_array);
|
| Now I want to call this using dynamic sql e.g.
|
| execute immediate
| 'begin vr.procname(p_id=>1­,p_name=>'||l_name||­'); end;';
|
| where l_name is defined as
|
| l_name util.array;
|
| And util.array is
| type array is table of varchar2(4000) index by binary_integer;
|
| The pl/sql with the "execute immediate" statement doesn't compile - and
| I understand why - but the question is can anyone tell me how (if) this
| can be done? It does need to be dynamic.....
|
|
| --
| jeremy
|
| Oracle 9iR2
| Solaris 8
| Oracle HTTP Server and mod_plsql

Why not just:

vr.procname(p_id=>1­,p_name=>l_name);

Regards
Michel Cadot


Add comment
Jeremy 24 April 2006 20:05:01 permanent link ]
 In article <444cf591$0$27282$6­26a54ce@news.free.fr­>, says...>
"Jeremy" <jeremy0505@gmail.c­om> a Г©crit dans le message de news: MPG.1eb7036f3bac3c2­e98a191@news.individ­ual.net...> |
|> | The pl/sql with the "execute immediate" statement doesn't compile - and> | I understand why - but the question is can anyone tell me how (if) this> | can be done? It does need to be dynamic.....> |>
Why not just:>
vr.procname(p_id=>1­,p_name=>l_name);


Becase we don't know the name of "vr.procname" - as I said, it needs to
be a dynamic SQL call (or another method where the actual proc name
isn't known until runtime - but that *is* dynamic SQL)
--

jeremy
Add comment
Michel Cadot 24 April 2006 20:14:40 permanent link ]
 
"Jeremy" <jeremy0505@gmail.c­om> a йcrit dans le message de news: MPG.1eb7078838ec738­498a192@news.individ­ual.net...
In article <444cf591$0$27282$6­26a54ce@news.free.fr­>, says...>
"Jeremy" <jeremy0505@gmail.c­om> a йcrit dans le message de news: MPG.1eb7036f3bac3c2­e98a191@news.individ­ual.net...> |
|> | The pl/sql with the "execute immediate" statement doesn't compile - and> | I understand why - but the question is can anyone tell me how (if) this> | can be done? It does need to be dynamic.....> |>
Why not just:>
vr.procname(p_id=>1­,p_name=>l_name);


Becase we don't know the name of "vr.procname" - as I said, it needs to
be a dynamic SQL call (or another method where the actual proc name
isn't known until runtime - but that *is* dynamic SQL)
--

jeremy


So now we know you really need dynamic SQL, what does mean
"The pl/sql with the "execute immediate" statement doesn't compile"?
I never saw Oracle displaying such an error message.

Regards
Michel Cadot


Add comment
Jeremy 24 April 2006 20:31:03 permanent link ]
 In article <444cf970$0$27281$6­26a54ce@news.free.fr­>, says...
So now we know you really need dynamic SQL, what does mean> "The pl/sql with the "execute immediate" statement doesn't compile"?> I never saw Oracle displaying such an error message.

OK you caught me - I didn't expect the pl/sql to compile as the execute
immediate statement requires a strcing defining the SQL statement to be
run and I was trying to effectively concatenate an array with a string
which was never going to work.

833/2
PL/SQL: Statement ignored

834/4
PLS-00306: wrong number or types of arguments in call to '||'


--

jeremy

Add comment
Steph 24 April 2006 20:41:19 permanent link ]
 l_name should be defined as a string, shouldn't it? your l_name is a
collection, right? so you try to concatenate a string with a collection
... seems strange!

stephan

Add comment
Jeremy 24 April 2006 21:55:10 permanent link ]
 In article <1145896879.150069.­234400@e56g2000cwe.g­ooglegroups.com>,
steph says...> l_name should be defined as a string, shouldn't it? your l_name is a> collection, right? so you try to concatenate a string with a collection> ... seems strange!>

Which was exactly my point. I want to pass the collection as a parameter
to a procedure whose name we do not know until run-time - and I want to
know if this is possible.

cheers,

--

jeremy
Add comment
Frank van Bortel 24 April 2006 22:08:30 permanent link ]
 Jeremy wrote:> Want to call target procedure using dynamic SQL.>
Target procedure is defined thus:>
create or replace package vr is> procedure form_1> (p_idinnumber default null,> p_nameinutil.array default util.empty_array,> p_valueinutil.array­ default util.empty_array);>­
Now I want to call this using dynamic sql e.g.>
execute immediate> 'begin vr.procname(p_id=>1­,p_name=>'||l_name||­'); end;';>
where l_name is defined as>
l_name util.array;>
And util.array is > type array is table of varchar2(4000) index by binary_integer;>
The pl/sql with the "execute immediate" statement doesn't compile - and > I understand why - but the question is can anyone tell me how (if) this > can be done? It does need to be dynamic.....>
Something along the line of:
declare
g_proc varchar2(40) := 'vr.procname';
g_name varchar2(40) := 'l_name';
begin
execute immediate (
':l_procname(p_id=>­1,p_name=>:l_name'
)
using g_proc, g_name;
end;

?
--
Regards,
Frank van Bortel

Top-posting is one way to shut me up...
Add comment
Steph 25 April 2006 11:20:35 permanent link ]
 as far as i know you can't pass collections as parameter of execute
immediate. maybe you can change your procedure(s) in a way that it
don't needs the parameter - with a package that handles these
collections and your procedure(s) accessing this package (or being part
of this package).

stephan

Add comment
Jeremy 26 April 2006 17:37:41 permanent link ]
 In article <e2j44j$u4h$1@news5­.zwoll1.ov.home.nl>,­ Frank van Bortel
says...
Something along the line of:> declare> g_proc varchar2(40) := 'vr.procname';> g_name varchar2(40) := 'l_name';> begin> execute immediate (> ':l_procname(p_id=>­1,p_name=>:l_name'> )> using g_proc, g_name;> end;>
?>


Not sure exactly waht you're getting at here Frank - doesn't that just
literally pass the string value 'l_name' into the p_name param of
vr.procname?

I need to find a way to pass an array param to a stored procedure using
some form of dynamic SQL. Perhaps it is not possible with "execute
immediate" - perhaps only with DBMS_SQL?

--

jeremy
Add comment
Connor McDonald 26 April 2006 17:38:19 permanent link ]
 Jeremy wrote:>
Want to call target procedure using dynamic SQL.>
Target procedure is defined thus:>
create or replace package vr is> procedure form_1> (p_id in number default null,> p_name in util.array default util.empty_array,> p_value in util.array default util.empty_array);>­
Now I want to call this using dynamic sql e.g.>
execute immediate> 'begin vr.procname(p_id=>1­,p_name=>'||l_name||­'); end;';>
where l_name is defined as>
l_name util.array;>
And util.array is> type array is table of varchar2(4000) index by binary_integer;>
The pl/sql with the "execute immediate" statement doesn't compile - and> I understand why - but the question is can anyone tell me how (if) this> can be done? It does need to be dynamic.....>
--> jeremy>
Oracle 9iR2> Solaris 8> Oracle HTTP Server and mod_plsql

execute immediate
'begin vr.procname(p_id=>1­,p_name=>:b1); end;'
using l_name;

hth
Connor
--
Connor McDonald
Co-author: "Mastering Oracle PL/SQL - Practical Solutions"
Co-author: "Oracle Insight - Tales of the OakTable"

web: http://www.oracledb­a.co.uk
web: http://www.oaktable­.net
email: connor_mcdonald@yah­oo.com


"Semper in excremento, sole profundum qui variat."

-------------------­--------------------­--------------------­-
Add comment
Jeremy 26 April 2006 17:40:52 permanent link ]
 In article <1145949635.345961.­308770@u72g2000cwu.g­ooglegroups.com>,
steph says...> as far as i know you can't pass collections as parameter of execute> immediate. maybe you can change your procedure(s) in a way that it> don't needs the parameter - with a package that handles these> collections and your procedure(s) accessing this package (or being part> of this package).>
stephan>

I don't see how it can be done - trying to compile proc where it refers
to an array variable in the using clause results in an oracle error ora-
00457 - expressions have to be of SQL types.

I am a bit stuck at the moment....


cheers


--

jeremy
Add comment
Steph 26 April 2006 17:57:54 permanent link ]
 What i meant was something like:

create pacakge AAA is
l_name util.array;
procedure set_collection(p_na­me in util.array default
util.empty_array);
procedure form_1(); -- this is using l_name
procedure form_2(); -- this is also using l_name
end AAA;
/

then you can call your procedures dynamically - you only need to set
l_name beforehand. but of course i don't now if this is applicable in
your situation ...

regs,
stephan

Add comment
Mark C. Stock 26 April 2006 18:24:43 permanent link ]
 
"Jeremy" <jeremy0505@gmail.c­om> wrote in message
news:MPG.1eb988b5dc­6e5f9898a196@news.in­dividual.net...
: In article <1145949635.345961.­308770@u72g2000cwu.g­ooglegroups.com>,
: steph says...
: > as far as i know you can't pass collections as parameter of execute
: > immediate. maybe you can change your procedure(s) in a way that it
: > don't needs the parameter - with a package that handles these
: > collections and your procedure(s) accessing this package (or being part
: > of this package).
: >
: > stephan
: >
: >
:
: I don't see how it can be done - trying to compile proc where it refers
: to an array variable in the using clause results in an oracle error ora-
: 00457 - expressions have to be of SQL types.
:
: I am a bit stuck at the moment....
:
:
: cheers
:
:
: --
:
: jeremy

a varray or nested table would qualify as a SQL type -- have you tried that?

++mcs


Add comment
Jeremy 26 April 2006 18:52:34 permanent link ]
 In article <444F77CB.5F13@yaho­o.com>, Connor McDonald says...> Jeremy wrote:> >
Want to call target procedure using dynamic SQL.> >
Target procedure is defined thus:> >
create or replace package vr is> > procedure form_1> > (p_id in number default null,> > p_name in util.array default util.empty_array,> > p_value in util.array default util.empty_array);>­ >
Now I want to call this using dynamic sql e.g.> >
execute immediate> > 'begin vr.procname(p_id=>1­,p_name=>'||l_name||­'); end;';> >
where l_name is defined as> >
l_name util.array;> >
And util.array is> > type array is table of varchar2(4000) index by binary_integer;> >
The pl/sql with the "execute immediate" statement doesn't compile - and> > I understand why - but the question is can anyone tell me how (if) this> > can be done? It does need to be dynamic.....>
execute immediate> 'begin vr.procname(p_id=>1­,p_name=>:b1); end;'> using l_name;>

This is my example:

create or replace procedure p
is
l_namewd_util.array­;
begin
begin
execute immediate
'begin myproc(p_web_site_i­d=>3,p_name=>:b1); end;'
using in l_name;
exception
when others then
dbms_output.put_lin­e(sqlerrm(sqlcode));­
end;
end p;
/


Fails to compile with a
PLS-00457: expressions have to be of SQL types

If I change the data type of l_name to say varchar2 then it compiles
fine.

Is there a method ny which I might pass an array like this into a
procedure executed via dynamic SQL?



--

jeremy
Add comment
Jeremy 26 April 2006 18:55:35 permanent link ]
 In article <1146059874.455302.­171200@v46g2000cwv.g­ooglegroups.com>,
steph says...> What i meant was something like:>
create pacakge AAA is> l_name util.array;> procedure set_collection(p_na­me in util.array default> util.empty_array);>­ procedure form_1(); -- this is using l_name> procedure form_2(); -- this is also using l_name> end AAA;> />
then you can call your procedures dynamically - you only need to set> l_name beforehand. but of course i don't now if this is applicable in> your situation ...>

This is probably me needing to do some more research here Steph because
I don't undersatnd how we get from that to what I want... thanks for the
pointers, appreciate the assistance.
--

jeremy
Add comment
Jeremy 26 April 2006 18:57:25 permanent link ]
 In article <itGdnQyI2so2H9LZnZ­2dnUVZ_tmdnZ2d@comca­st.com>, Mark C. Stock
says...>
"Jeremy" <jeremy0505@gmail.c­om> wrote in message > news:MPG.1eb988b5dc­6e5f9898a196@news.in­dividual.net...> : In article <1145949635.345961.­308770@u72g2000cwu.g­ooglegroups.com>,> : steph says...> : > as far as i know you can't pass collections as parameter of execute> : > immediate. maybe you can change your procedure(s) in a way that it> : > don't needs the parameter - with a package that handles these> : > collections and your procedure(s) accessing this package (or being part> : > of this package).
:> : I don't see how it can be done - trying to compile proc where it refers> : to an array variable in the using clause results in an oracle error ora-> : 00457 - expressions have to be of SQL types.> :> : I am a bit stuck at the moment....> :> :> : cheers> :> :> : -- > :> : jeremy>
a varray or nested table would qualify as a SQL type -- have you tried that?>

Hi Mark,

I haven't tried that - that is creating a type in the database first,
yes?

I wanted to explore all avenues which didn't require me to define a type
in the database (as to be honest it is because I haven't been down that
path before).

cheers
--

jeremy
Add comment
Mark C. Stock 26 April 2006 19:00:48 permanent link ]
 
"Jeremy" <jeremy0505@gmail.c­om> wrote in message
news:MPG.1eb99ab4ef­05cb798a199@news.ind­ividual.net...
: In article <itGdnQyI2so2H9LZnZ­2dnUVZ_tmdnZ2d@comca­st.com>, Mark C. Stock
: says...
...
: >
: > a varray or nested table would qualify as a SQL type -- have you tried
that?
: >
:
: Hi Mark,
:
: I haven't tried that - that is creating a type in the database first,
: yes?
:
: I wanted to explore all avenues which didn't require me to define a type
: in the database (as to be honest it is because I haven't been down that
: path before).
:

it may be doable just in the package without creating a persistent type in
the database ... worth a try

++ mcs


Add comment
Jeremy 26 April 2006 19:21:18 permanent link ]
 In article <H4-dnUcTFd29FtLZRV­n-sg@comcast.com>, Mark C. Stock says...>
"Jeremy" <jeremy0505@gmail.c­om> wrote in message > news:MPG.1eb99ab4ef­05cb798a199@news.ind­ividual.net...> : In article <itGdnQyI2so2H9LZnZ­2dnUVZ_tmdnZ2d@comca­st.com>, Mark C. Stock> : says...> ...> : >> : > a varray or nested table would qualify as a SQL type -- have you tried > that?> : >> :> : Hi Mark,> :> : I haven't tried that - that is creating a type in the database first,> : yes?> :> : I wanted to explore all avenues which didn't require me to define a type> : in the database (as to be honest it is because I haven't been down that> : path before).> :>
it may be doable just in the package without creating a persistent type in > the database ... worth a try>

Any examples of this (new area for me) - or keywords to search oracle
doc on?

--

jeremy
Add comment
Jeremy 26 April 2006 19:38:20 permanent link ]
 In article <MPG.1eb9a045dc7647­c498a19a@news.indivi­dual.net>, Jeremy
says...> In article <H4-dnUcTFd29FtLZRV­n-sg@comcast.com>, Mark C. Stock says...> >
it may be doable just in the package without creating a persistent type in > > the database ... worth a try> >
Any examples of this (new area for me) - or keywords to search oracle > doc on?>
Follow-up on own post time:

This compiled OK:

create type mytype as table of varchar2(2000)
/

create or replace procedure p
is
l_namemytype;
begin
begin
execute immediate
'begin myproc(p_web_site_i­d=>3,p_name=>:b1); end;'
using in l_name;
exception
when others then
dbms_output.put_lin­e(sqlerrm(sqlcode));­
end;
end p;
/
sho err


So changing the definition of l_name to be of type "mytype" instead of
wd_util.array

Now to see if the rest of it behaves as hoped ;)

thanks


--

jeremy
Add comment
Frank van Bortel 26 April 2006 21:45:32 permanent link ]
 Jeremy wrote:> In article <e2j44j$u4h$1@news5­.zwoll1.ov.home.nl>,­ Frank van Bortel > says...>
Something along the line of:>> declare>> g_proc varchar2(40) := 'vr.procname';>> g_name varchar2(40) := 'l_name';>> begin>> execute immediate (>> ':l_procname(p_id=>­1,p_name=>:l_name'>>­ )>> using g_proc, g_name;>> end;>>
?>>
Not sure exactly waht you're getting at here Frank - doesn't that just > literally pass the string value 'l_name' into the p_name param of > vr.procname?>
I need to find a way to pass an array param to a stored procedure using > some form of dynamic SQL. Perhaps it is not possible with "execute > immediate" - perhaps only with DBMS_SQL?>

1) It uses bind variables.
2) it passes the value (contents) of g_name (in this example
that would be "l_name" indeed).
3) Haven't tested with arrays, but here's your framework; pass the
array.
--
Regards,
Frank van Bortel

Top-posting is one way to shut me up...
Add comment


Jeremy 26 April 2006 22:08:52 permanent link ]
 In article <e2obhd$uqk$1@news4­.zwoll1.ov.home.nl>,­ Frank van Bortel
says...> Jeremy wrote:> > In article <e2j44j$u4h$1@news5­.zwoll1.ov.home.nl>,­ Frank van Bortel > > says...> >
Something along the line of:> >> declare> >> g_proc varchar2(40) := 'vr.procname';> >> g_name varchar2(40) := 'l_name';> >> begin> >> execute immediate (> >> ':l_procname(p_id=>­1,p_name=>:l_name'> >> )> >> using g_proc, g_name;> >> end;> >>
?> >>
Not sure exactly waht you're getting at here Frank - doesn't that just > > literally pass the string value 'l_name' into the p_name param of > > vr.procname?> >
I need to find a way to pass an array param to a stored procedure using > > some form of dynamic SQL. Perhaps it is not possible with "execute > > immediate" - perhaps only with DBMS_SQL?> >
1) It uses bind variables.> 2) it passes the value (contents) of g_name (in this example> that would be "l_name" indeed).> 3) Haven't tested with arrays, but here's your framework; pass the> array.>

Don't know if you've seen my other posts following up on this but it
seems you cannot do it unless the type of the variable (l_name in this
case) is a SQL type. So I created a type vc2000_array and used that
definition for l_name - and got successful compile. Then I discovered my
next set of issues under the thread "Passing array values into pl/sql
procedure via a URL" :(­

cheers!

--

jeremy
Add comment
Connor McDonald 27 April 2006 17:44:47 permanent link ]
 Jeremy wrote:>
In article <444F77CB.5F13@yaho­o.com>, Connor McDonald says...> > Jeremy wrote:> > >
Want to call target procedure using dynamic SQL.> > >
Target procedure is defined thus:> > >
create or replace package vr is> > > procedure form_1> > > (p_id in number default null,> > > p_name in util.array default util.empty_array,> > > p_value in util.array default util.empty_array);>­ > >
Now I want to call this using dynamic sql e.g.> > >
execute immediate> > > 'begin vr.procname(p_id=>1­,p_name=>'||l_name||­'); end;';> > >
where l_name is defined as> > >
l_name util.array;> > >
And util.array is> > > type array is table of varchar2(4000) index by binary_integer;> > >
The pl/sql with the "execute immediate" statement doesn't compile - and> > > I understand why - but the question is can anyone tell me how (if) this> > > can be done? It does need to be dynamic.....> >
execute immediate> > 'begin vr.procname(p_id=>1­,p_name=>:b1); end;'> > using l_name;> >
This is my example:>
create or replace procedure p> is> l_name wd_util.array;> begin> begin> execute immediate> 'begin myproc(p_web_site_i­d=>3,p_name=>:b1); end;'> using in l_name;> exception> when others then> dbms_output.put_lin­e(sqlerrm(sqlcode));­> end;> end p;> />
Fails to compile with a> PLS-00457: expressions have to be of SQL types>
If I change the data type of l_name to say varchar2 then it compiles> fine.>
Is there a method ny which I might pass an array like this into a> procedure executed via dynamic SQL?>
-->
jeremy

Can you recast wd_util.array as a nested table type (I assume its a
plsql table currently).

Cheers
Connor


--
Connor McDonald
Co-author: "Mastering Oracle PL/SQL - Practical Solutions"
Co-author: "Oracle Insight - Tales of the OakTable"

web: http://www.oracledb­a.co.uk
web: http://www.oaktable­.net
email: connor_mcdonald@yah­oo.com


"Semper in excremento, sole profundum qui variat."

-------------------­--------------------­--------------------­-
Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или законы РФ. Ваш ip-адрес записывается.


QAIX > Oracle database development > Is this possible with "execute immediate" 27 April 2006 17:44:47

see also:
Server Relocation
SOLVED: Re: Any reason client.LastVisit…
pass tests:
see also:
A powerful online MPG Encoder 3.1.06…
How to convert and edit videos for…
How to Converter Any Video to 3GP

  Copyright © 2001—2010 QAIX
Идея: Монашёв Михаил.
Авторами текстов, изображений и видео, размещённых на этой странице, являются пользователи сайта.
See Help and FAQ in the community support.qaix.com.
Write in the community about the bugs you have noticedbugs.qaix.com.
Write your offers and comments in the communities suggest.qaix.com.
Information for parents.
Пишите нам на .
If you would like to report an abuse of our service, such as a spam message, please .
Если Вы хотите пожаловаться на содержимое этой страницы, пожалуйста .