Home » SQL & PL/SQL » SQL & PL/SQL » execute immediate with select
execute immediate with select [message #364750] Tue, 09 December 2008 23:09 Go to next message
shaksing
Messages: 115
Registered: November 2008
Senior Member
Is it possible to use select count(*) statement with INTO (a varaiable) using execute immediate (dynamic query).
Re: execute immediate with select [message #364751 is a reply to message #364750] Tue, 09 December 2008 23:20 Go to previous messageGo to next message
spmano1983
Messages: 269
Registered: September 2007
Senior Member
You can use like this..
DECLARE
   n          NUMBER;
   sql_stmt   VARCHAR2 (100);
BEGIN
   sql_stmt := 'select count(*) from scott.emp';

   EXECUTE IMMEDIATE sql_stmt
                INTO n;

   DBMS_OUTPUT.put_line (n);
END;
Re: execute immediate with select [message #364753 is a reply to message #364750] Tue, 09 December 2008 23:21 Go to previous messageGo to next message
shaksing
Messages: 115
Registered: November 2008
Senior Member
Thanks spmano i will try this out.
Re: execute immediate with select [message #364754 is a reply to message #364750] Tue, 09 December 2008 23:22 Go to previous messageGo to next message
manns
Messages: 59
Registered: March 2006
Location: Bangalore
Member

yes you can use.. see the below ex.

create or replace function fn_sequence(p_tblname in varchar2)
return number is
l_cnt number;
begin
execute immediate 'select count(*) from '|| p_tblname into l_cnt;
return l_cnt;
end;

regards,
Manju
Re: execute immediate with select [message #364764 is a reply to message #364750] Wed, 10 December 2008 00:16 Go to previous messageGo to next message
shaksing
Messages: 115
Registered: November 2008
Senior Member
Problem solved.
Re: execute immediate with select [message #364778 is a reply to message #364754] Wed, 10 December 2008 00:39 Go to previous messageGo to next message
Michel Cadot
Messages: 64098
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
manns wrote on Wed, 10 December 2008 06:22
yes you can use.. see the below ex.

create or replace function fn_sequence(p_tblname in varchar2)
return number is
l_cnt number;
begin
execute immediate 'select count(*) from '|| p_tblname into l_cnt;
return l_cnt;
end;

regards,
Manju

Google for SQL INJECTION.

Regards
Michel

Re: execute immediate with select [message #364780 is a reply to message #364750] Wed, 10 December 2008 00:41 Go to previous message
shaksing
Messages: 115
Registered: November 2008
Senior Member
Thanks Michel.
Previous Topic: Has anyone gotten dbms_ldap.open_ssl to work?
Next Topic: Query to copy columns from one table to another table
Goto Forum:
  


Current Time: Fri Dec 02 12:23:52 CST 2016

Total time taken to generate the page: 0.19724 seconds