Executing ddl statment in pl/sql block
Hi all,
could anyone pls help in method for executing ddl statment in pl/sql block other than 'execute immediate' ?
could anyone pls help in method for executing ddl statment in pl/sql block other than 'execute immediate' ?On newer db versions you have more options:
SQL> desc t
Error: object t does not exist
SQL> exec sys.dbms_prvtaqim.execute_stmt('create table michael.t (a integer)')
PL/SQL procedure successfully completed.
SQL> desc t
TABLE t
Name Null? Type
A NUMBER
SQL> exec sys.dbms_utility.exec_ddl_statement('drop table michael.t')
PL/SQL procedure successfully completed.
SQL> desc t
Error: object t does not exist;)
Similar Messages
-
Execute DDL statements from pl / sql
Hi !!!!
I have to create every object (tables, sequences, etc) using a pl / sql block, so I need first looking for the object in the data dictionary and if it doesn't exist execute a ddl statement to create it.
I wanted to execute at the same "execute immediate " :
- create table.
- create synonym for the table created before.
- comments on table
- comments on table's columns
- grants on the table.
But I found some errors:
- I can`t have semicolon after every statement so I get an "ORA-00911: invalid character". I did'nt try to scape the semicolon so I need it.
- I split the execute immediate so now I have one execute immediate for every statement but I got an error in this statement:
EXECUTE IMMEDIATE 'COMMENT ON TABLE SYSADM.CVP_PAQ_SMS_REC_PRUEBA IS "COMMENT ON TABLE" '; The error I get is this:
ORA-01780: string literal required
Any suggestions about this ?
Thanks.The comment itself needs to be a SQL string so it needs to be delimited with single quotes not double quotes. You can either use two single quotes
EXECUTE IMMEDIATE 'COMMENT ON TABLE SYSADM.CVP_PAQ_SMS_REC_PRUEBA IS ''COMMENT ON TABLE'' ';or you can use the q quoting syntax
EXECUTE IMMEDIATE q'[COMMENT ON TABLE SYSADM.CVP_PAQ_SMS_REC_PRUEBA IS 'COMMENT ON TABLE' ]';You cannot combine multiple DDL statements into a single block (well, you could use dynamic PL/SQL, but then your string would have a bunch of embedded EXECUTE IMMEDIATE statements which would presumably not buy you much).
Justin -
Execute immediate will work in SQL Block in shell script?
Hi Friends,
i am wirting script to get the account id's corresponding to CIF from oracle table and need to pass to procedure.
Here first_org and last_org are shell variables.
When i execute the below program it is throwing execute not found.
Can you please correct me where i made a mistake? and also please let me know how to display some content in below sql block ?dbms_output.put_line or print which need to use and provide me the syntax for both.
`sqlplus -s crmuser/******@dotis11<<ENDOFSQL
whenever sqlerror exit 1
declare
qstr varchar2(200);
facid varchar2(20);
Lacid varchar2(20);
begin
qstr:='select ACCOUNTID from accounts where ORGKEY=:1';
execute immediate qstr into facid using $first_org;
dbms_output.put_line(facid);
qstr:='select ACCOUNTID from accounts where ORGKEY=:1';
execute immediate qstr into Lacid using $last_org;
dbms_output.put_line(Lacid);
exec Retail_Otu_Dedup_Account(facid,Lacid)
end;
exit;
ENDOFSQL`
Thanks,
Venkat Vadlamudi.Hi SY,
I Included set serveroutput on but i didn't include single quotes for shell variable in execute immediate.
Now iam able to execute and getting proper o/p.
Thanks SY for your help...
and how to print shell variable in above sql block..i tried like this. but throwing error.
dbms_output.put_line('$first_org');
dbms_output.put_line('VCIF1320');
ERROR at line 5:
ORA-06550: line 5, column 12:
PLS-00103: Encountered the symbol "." when expecting one of the following:
constant exception <an identifier>
*<a double-quoted delimited-identifier> table long double ref*
char time timestamp interval date binary national character
nchar
The symbol "<an identifier>" was substituted for "." to continue.
ORA-06550: line 6, column 5:
PLS-00103: Encountered the symbol "=" when expecting one of the following:
constant exception <an identifier>
*<a double-quoted delimited-identifier> table long double ref*
char time timestamp interval date binary national characte
Thanks,
Venkat Vadlamudi. -
Execute immediate of Anonymous pl/sql block stored in a VARCHAR2 DB Column
Hi Guys,
I really hope someone can help me with this.
I have the following pl/sql anonymous block stored in a varchar2 database column.
declare
l_my_val varchar2(32767);
cursor c_activity is
SELECT
l.DESCRIPTION || decode(l2.DESCRIPTION,null,'',l2.description, '-' || l2.description) || decode(a.DT,'Y',' - Distributed Training','N',null,null) as value1
FROM ACTIVITY a
,MOUNTAINEERING m
,LOV l
,LOV l2
WHERE a.JSATFA_ID = 82
AND a.SPECIFIC_ACTIVITY_LOV_ID = l.LOV_ID
AND m.ACTIVITY_ID(+) = a.ACTIVITY_ID
AND m.CLASSIFICATION_LOV_ID = l2.LOV_ID(+);
begin
for each_row in c_activity loop
l_my_val := l_my_val || ', ' || each_row.value1;
end loop;
:l_value := ltrim (l_my_val, ', ');
end; The code is select out of the database and assigned to a local variable within my pl/sql package. The following code should demonstrate what I'm trying to achieve:
declare
l_sql varchar2(32767);
l_value varchar2(32767);
begin
select query_sql into l_sql from lov where lov_id = 100;
execute immediate l_sql using out :l_value;
dbms_output.put_line(l_value);
end;However Oracle (10.2.0.2) seems to be doing something funny with the single quotes. and gives the following error:
ORA-06550: line 1, column 1:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare exit for function goto if loop mod null
package pragma procedure raise return select separate type
update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
form table call close current define delete fetch lock insert
open rollback savepoint set sql execute commit forall merge
library OPERATOR_ pipe
errorIf I embed the code I'm trying to execute within the package i.e
declare
l_sql varchar2(32767);
l_value varchar2(32767);
begin
l_sql := q'~declare
l_my_val varchar2(32767);
cursor c_activity is
SELECT
l.DESCRIPTION || decode(l2.DESCRIPTION,null,'',l2.description, '-' || l2.description) || decode(a.DT,'Y',' - Distributed Training','N',null,null) as value1
FROM ACTIVITY a
,MOUNTAINEERING m
,LOV l
,LOV l2
WHERE a.JSATFA_ID = 82
AND a.SPECIFIC_ACTIVITY_LOV_ID = l.LOV_ID
AND m.ACTIVITY_ID(+) = a.ACTIVITY_ID
AND m.CLASSIFICATION_LOV_ID = l2.LOV_ID(+);
begin
for each_row in c_activity loop
l_my_val := l_my_val || ', ' || each_row.value1;
end loop;
:l_value := ltrim (l_my_val, ', ');
end;
~';
execute immediate l_sql using out :l_value;
dbms_output.put_line(l_value);
end;It works perfectly. Notice I have used the q syntax when embedding the sql directly into the package.
I have tried
- appending the q syntax directly to query_sql stored in the database
- escaping the quotes i.e. ' become ''
Neither method seem to work. We are running 10.2.0.2 on Windows Server 2003. If anyone has any suggestions I would love to hear from you as this has me stumped.
Regards
Kris
- http://kristianjones.blogspot.comIf you do:
declare
l_sql varchar2(32767);
l_value varchar2(32767);
begin
select query_sql into l_sql from lov where lov_id = 100;
dbms_output.put_line(l_sql);
end;
You'll see something like that:
SELECT
l.DESCRIPTION || decode(l2.DESCRIPTION,null,'',l2.description, '-' || l2.description) || decode(a.DT,'Y',' - Distributed Training','N',null,null) as value1
FROM ACTIVITY a
,MOUNTAINEERING m
,LOV l
,LOV l2
WHERE a.JSATFA_ID = 82
AND a.SPECIFIC_ACTIVITY_LOV_ID = l.LOV_ID
AND m.ACTIVITY_ID(+) = a.ACTIVITY_ID
AND m.CLASSIFICATION_LOV_ID = l2.LOV_ID(+);
you need to duplicate the '
you can do many things like:
CTH@> select * from sqls;
C
select first_name || ' ' || last_name as value1 from employees where rownum=1
1 fila seleccionada.
CTH@>
CTH@> ;
1 declare
2 l_sql varchar2(32767);
3 l_value varchar2(32767);
4 type generic_cursor is ref cursor;
5
6 c generic_cursor;
7
8 begin
9 select replace(c, ''', ''''') into l_sql from sqls;
10
11 execute immediate l_sql into l_value;
12 dbms_output.put_line(l_value);
13* end;
CTH@> /
Ellen Abel
Procedimiento PL/SQL terminado correctamente.
CTH@> -
How to execute .bat file within pl/sql block
Hi,
I want to execute a batch file (.bat) file withing a pl/sql procedure. Please guide me for it.
RegardsThere are several possible ways to make a call-out from a PL/SQL program to the OS on the database server (but not to the client computer).
You could use java or an external procedure (you'll need to code it in C) for example.
You might be able to make use of UTL_HTTP to talk HTTP to another server or UTL_TCP to talk TCP to another server.
What is it you are trying to do? -
Obtaining a collection as a return from an execute immediate pl/sql block
version 10.2
I need to obtain the collection back from the execute immediate of a pl/sql block:
procedure block(owner varchar2) is
stmt long;
objecttab_coll dbms_stats.objecttab;
begin
stmt := '
begin
dbms_stats.gather_schema_stats(''' || owner || '''
,options => ''LIST AUTO''
,objlist => :objecttab_coll
end;';
execute immediate stmt returning into objecttab_coll;
-- do more stuff here
end block;I have tried this + a few variations but with no luck. In looking through the docs I do not see an example. can this be done?
Thanks
OxI dont find any need for an execute immediate here. This must be just enough.
procedure block(owner varchar2)
is
objecttab_coll dbms_stats.objecttab;
begin
dbms_stats.gather_schema_stats(ownname => owner, options => 'LIST AUTO', objlist => objecttab_coll);
-- do more stuff here
end block;Thanks,
Karthick. -
Executing a PL/SQL block (using Toplink)
I have a scenario where I need to execute some fairly complex PL/SQL blocks. As a tester, I am attempting to execute the following simple block:
declare val NUMBER := 1; begin val := 2; end;
Both wrapping this in an SQLCall, or a DataReadQuery give the following exception. What is the best way to execute a PL/SQL block using Toplink?
Local Exception Stack:
Exception [TOPLINK-4002] (Oracle TopLink - 10g Release 3 (10.1.3.0.0) (Build 060118)): oracle.toplink.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-00900: invalid SQL statement
Error Code: 900
Call: declare val NUMBER := 1; begin val := 2; end;
Query:DataReadQuery()
at oracle.toplink.exceptions.DatabaseException.sqlException(DatabaseException.java:290)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:570)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:442)
at oracle.toplink.threetier.ServerSession.executeCall(ServerSession.java:453)
at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:117)
at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:103)
at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:174)
at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeSelect(DatasourceCallQueryMechanism.java:156)
at oracle.toplink.queryframework.DataReadQuery.executeNonCursor(DataReadQuery.java:118)
at oracle.toplink.queryframework.DataReadQuery.executeDatabaseQuery(DataReadQuery.java:110)
at oracle.toplink.queryframework.DatabaseQuery.execute(DatabaseQuery.java:603)
at oracle.toplink.queryframework.DataReadQuery.execute(DataReadQuery.java:96)
at oracle.toplink.publicinterface.Session.internalExecuteQuery(Session.java:2062)
at oracle.toplink.publicinterface.Session.executeQuery(Session.java:981)
at oracle.toplink.publicinterface.Session.executeQuery(Session.java:938)Could you try the following:
Session s = ...
DataModifyQuery dmq = new DataModifyQuery();
SQLCall sqlCall = new SQLCall();
sqlCall.setQueryString(
"declare\n" +
" val NUMBER := 1;\n" +
"begin\n" +
" val := 2;\n" +
"end;");
sqlCall.setQuery(dmq);
dmq.setCall(sqlCall);
s.executeQuery(dmq); -
Alter database statement in anonymous pl/sql block
Is it possible to include an alter database statement in an anonymous pl/sql block?
When I execute this code to query user_tables for all table names, disable their constraints and drop the table, I got the following error:
***MY CODE
-- DECLARE VARIABLE(S)
DECLARE
v_TABLE_NAME TABLE_NAME.USER_TABLE%TYPE;
-- DECLARE AND DEFINE CURSOR
CURSOR c_GETTABLES is
SELECT TABLE_NAME from USER_TABLES;
BEGIN
OPEN c_GETTABLES;
LOOP
FETCH c_GETTABLES into v_TABLE_NAME;
EXIT when c_GETTABLES%notfound;
ALTER TABLE v_TABLE_NAME DISABLE PRIMARY KEY CASCADE;
DROP TABLE v_TABLE_NAME;
END LOOP;
CLOSE c_GETTABLES;
END;
***RESPONSE FROM SERVER
ALTER TABLE v_TABLE_NAME DISABLE PRIMARY KEY CASCADE;
ERROR at line 15:
ORA-06550: line 15, column 1:
PLS-00103: Encountered the symbol "ALTER" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge
<a single-quoted SQL string> pipe
ThanksWhen you want to perform ddl statements in a (anonymous) PL/SQL block, you have to use dynamic SQL because ddl is not possible in pl/sql.
Dynamic sql means that you sort of execute ddl statements in a sql manner. To use dynamic sql, two options exist:
- dbms_sql package : for oracle before 8i. To use this package is not always easy. Read about it carefully first before using.
- Native Dynamic SQL : implemented in 8i and very easy to use. An example would be :
declare
lv_statement varchar2(32676);
begin
lv_statement := 'ALTER TABLE MY_TABLE DISABLE CONSTRAINT MY_TABLE_CK1';
execute immediate lv_statement;
lv_statement := 'ALTER TABLE MY_TABLE ENABLE CONSTRAINT MY_TABLE_CK1';
execute immediate lv_statement;
end;
Good luck.
Edwin van Hattem -
Hi I am getting too many rows exception using execute immediate in this pl/sql block.
how can i handle this? i would like to process all records and insert to this temp table
declare
cursor c1 is select username from dba_users;
v_email varchar2(200);
begin
for rec in c1
loop
begin
execute immediate ('select email from '||rec.username||'.audit_tbl minus select email from secmaster.sec_user_tbl ' ) into v_email;
insert into secmaster.temp_tbl (email, val)
values (email, rec.username);
exception
when no_data_found then
null;
end;
end loop;
end;
/user520824 wrote:
Hi I am getting too many rows exception using execute immediate in this pl/sql block.
how can i handle this? i would like to process all records and insert to this temp table
declare
cursor c1 is select username from dba_users;
v_email varchar2(200);
begin
for rec in c1
loop
begin
execute immediate ('select email from '||rec.username||'.audit_tbl minus select email from secmaster.sec_user_tbl ' ) into v_email;
insert into secmaster.temp_tbl (email, val)
values (email, rec.username);
exception
when no_data_found then
null;
end;
end loop;
end;
Didn't test this but give a try:
DECLARE
TYPE recItem
IS
RECORD
v_email VARCHAR2);
TYPE setRec
IS
TABLE OF recItem;
some_rec setRec ;
CURSOR c1
IS
SELECT username FROM dba_users;
v_email VARCHAR2(200);
BEGIN
FOR rec IN c1
LOOP
BEGIN
EXECUTE immediate ('select email from '||rec.username||'.audit_tbl minus select email from secmaster.sec_user_tbl ' ) INTO v_email;
INSERT INTO secmaster.temp_tbl
(email, val
) VALUES
(email, rec.username
EXCEPTION
WHEN no_data_found THEN
NULL;
END;
WHEN too_many_rows
EXECUTE immediate 'select email from '||rec.username||'.audit_tbl minus select email from secmaster.sec_user_tbl ' BULK COLLECT into some_rec;
FOR i IN some_rec.FIRST..some_rec.LAST
LOOP
INSERT
INTO secmaster.temp_tbl
email,
val
VALUES
some_rec(i).email,
rec.username
END LOOP;
END;
END LOOP;
END;Did it work?
Edited by: Vitor Rodrigues on 17/Fev/2012 17:35 -
Error in insert statment in pl/sql
Hi all,
How i Execute Insert statment in Pl/Sql
SQL> DECLARE
2 tablename varchar2(30);
3 Begin
4 begin
5 select table_name into tablename from user_tables
6 where table_name=upper('t_calling');
7 EXCEPTION
8 WHEN no_data_found then
9 execute immediate 'create table t_calling(F_CODE number,
10 F_CALLING varchar2(50))';
11 INSERT INTO T_Calling VALUES (1, 'asd');
12 end;
13 -- --------------------------
14 Commit;
15 End;
16 /
INSERT INTO T_Calling VALUES (1, 'asd');
ORA-06550:
PLS-00201: identifier 'T_CALLING' must be declared
ORA-06550:
PL/SQL: SQL Statement ignored
Thanks
alaaYou are creating this table with an execute immediate statement. Which suggests that it doesn't exist yet. Therefore your insert statement is referencing a non-existent table so naturally it won't compile.
If you really want to do this you should put the insert into an execute immediate statement as well. However, I recommend that you don't do this - it is very bad practice to put this sort of processing in the exception handler. Why? Well, what happens if the table T_CALLING already exists? The exception's got no where to go, so your program fails with an Unhandled Exception error.
HTH, APC -
DDL in pl/sql block???
Hi,
begin
create table sample_test ( x number);
end;
gives an error, but
begin
execute immediate 'create table sample_test(x number)';
end
very much works, is there any specific reason to why the first way of doing a DDL statement is restricted or avoided???
cheereHi,
begin
create table sample_test ( x number);
end;
you can not issue DDL like above in a PL/SQL Block, hence error
gives an error, but
begin
execute immediate 'create table sample_test(x
(x number)';
end
You Issued DDL in PL/SQL Block using Native Dynamic SQL, hence worked !!
Message was edited by:
biswabijay -
Can't create a sequence within a pl/sql block with execute immediate.
Hi All. I created a user and granted it the 'create sequence' privilege though a role. In a pl/sql block I try to create a sequence using 'execute immediate' but get a 1031-insufficient privileges error. If I grant create sequence directly to the user, the pl/sql block completes successfully. Can anyone explain this behavior? We're running 11.2 Enterprise Editon.
Thanks,
MarkIn a definer's rights stored procedure (the default), you only have access to privileges that have been granted directly, not via a role.
There are two basic reasons for that. First, roles can be enabled or disabled, default and non-default, password-protected, etc. so the set of roles a particular user actually has is session-specific. Oracle needs to know at compile time what privileges the owner of the procedure has. The only way to do that (without deferring the privilege check) is to ignore privileges granted through roles.
Second, since 99% of privilege management DBAs do involves granting and revoking roles, it's helpful that changing role privileges will never cause objects to be marked invalid and recompiled which can have side-effects on applications. DBAs only need to worry about causing problems on those rare cases where they are granting or revoking direct privileges to users.
You can create an invoker's rights stored procedure by adding the clause (AUTHID CURRENT_USER). That defer's the security check to run-time but allows the procedure to see privileges granted through roles in the current session. But that means that the caller of the procedure would need to have the CREATE SEQUENCE privilege through the role, not the owner of the procedure.
And just to make the point, dynamic object creation in PL/SQL is almost always a red flag that there is something problematic in your design. If you are creating sequences dynamically, that means that you'd have to refer to them dynamically throughout your code which means that your inserts would need to use dynamic SQL. That's not a particularly easy or safe way to develop code.
Justin -
Hii All,
I'm facing the following error
ERROR at line 66:
ORA-06550: line 66, column 20:
PLS-00306: wrong number or types of arguments in call to '||'
ORA-06550: line 66, column 11:
PL/SQL: Statement ignoredVersion Details
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for Solaris: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - ProductionMy pl sql block
Declare
p_table_name clob := 'CP_CA_DTLS' ;
Type t_column_name_tab is table of varchar2(4000)
index by binary_integer;
l_table_tab t_column_name_tab;
l_file_name constant varchar2(5000) := 'column_counts';
l_count number;
l_tab_count number;
l_str varchar2(32000);
l_tbl_str varchar2(32000);
Cursor c_table_columns(c_table_name user_tables.table_name%type)
Is
Select column_name
from user_tab_cols
where table_name = upper(c_table_name);
Type t_table_columns is table of c_table_columns%rowtype;
l_column_name_tab t_table_columns;
Begin
--Splitting comma seperated data
Select regexp_substr(p_table_name,'[^,]+{1}',1,level)
bulk collect into l_table_tab
from dual
connect by level <= length(regexp_replace(p_table_name,'[^,]*'))+1;
for k in 1..l_table_tab.count
loop
-- dbg_print(l_file_name,'***'||l_table_tab(k)||'***');
Begin
l_tbl_str := 'Select count(*) from '||l_table_tab(k);
execute immediate l_tbl_str into l_tab_count;
-- dbg_print(l_file_name,'Overall Count of table '||l_table_tab(k)||' is '||l_tab_count);
End;
-- dbg_print(l_file_name,'Column Name '||','||'Count');
Open c_table_columns(l_table_tab(k));
loop
Fetch c_table_columns bulk collect into l_column_name_tab limit 50;
exit when l_column_name_tab.count = 0;
dbms_output.put_line('l_column_name_tab.count count is : '||l_column_name_tab.count);
for i in 1..l_column_name_tab.count
loop
Begin
l_str := 'Select count(*) ' ;
l_str := l_str||' from '||l_table_tab(k) ;
l_str := l_str||' where '||l_column_name_tab(i);
l_str := l_str||' is null' ;
Execute Immediate l_str into l_count;
End;
--dbg_print(l_file_name,l_column_name_tab(i)||','||l_count);
end loop;
end loop;
Close c_table_columns;
end loop;
dbms_output.put_line('l_column_name_tab.count count is : '||l_column_name_tab.count);
End;Even I'm not able to print l_column_name_tab(i) using dbms_output.
(Later I came to know that this information can be achieved using user_tab_col_statistics table)
But would like to know whats wrong with my code.???
Plz help me .
Edited by: 792353 on Dec 3, 2010 1:26 AMHii RDB,
when I comment this part of code
-- l_str := l_str||' where '||l_column_name_tab(i);
-- l_str := l_str||' is null' ;
SQL> Declare
2
3
4 p_table_name clob := 'CP_CA_DTLS' ;
5
6 Type t_column_name_tab is table of varchar2(4000)
7 index by binary_integer;
8
9 l_table_tab t_column_name_tab;
10
11
12
13
14 l_file_name constant varchar2(5000) := 'column_counts';
15 l_count number;
16 l_tab_count number;
17 l_str varchar2(32000);
18 l_tbl_str varchar2(32000);
19
20 Cursor c_table_columns(c_table_name user_tables.table_name%type)
21 Is
22 Select column_name
23 from user_tab_cols
24 where table_name = upper(c_table_name);
25
26
27 Type t_table_columns is table of c_table_columns%rowtype;
28
29
30 l_column_name_tab t_table_columns;
31
32 Begin
33 --Splitting comma seperated data
34
35 Select regexp_substr(p_table_name,'[^,]+{1}',1,level)
36 bulk collect into l_table_tab
37 from dual
38 connect by level <= length(regexp_replace(p_table_name,'[^,]*'))+1;
39
40 for k in 1..l_table_tab.count
41 loop
42 -- dbg_print(l_file_name,'***'||l_table_tab(k)||'***');
43
44 Begin
45 l_tbl_str := 'Select count(*) from '||l_table_tab(k);
46
47 execute immediate l_tbl_str into l_tab_count;
48
49 -- dbg_print(l_file_name,'Overall Count of table '||l_table_tab(k)||' is '||l_tab_coun
t);
50
51 End;
52
53 -- dbg_print(l_file_name,'Column Name '||','||'Count');
54
55 Open c_table_columns(l_table_tab(k));
56 loop
57 Fetch c_table_columns bulk collect into l_column_name_tab limit 50;
58 exit when l_column_name_tab.count = 0;
59 dbms_output.put_line('l_column_name_tab.count count is : '||l_column_name_tab.count);
60 for i in 1..l_column_name_tab.count
61 loop
62
63 Begin
64 l_str := 'Select count(*) ' ;
65 l_str := l_str||' from '||l_table_tab(k) ;
66 -- l_str := l_str||' where '||l_column_name_tab(i);
67 -- l_str := l_str||' is null' ;
68
69 Execute Immediate l_str into l_count;
70
71 End;
72
73 --dbg_print(l_file_name,l_column_name_tab(i)||','||l_count);
74
75 end loop;
76 end loop;
77 Close c_table_columns;
78 end loop;
79
80 dbms_output.put_line('l_column_name_tab.count count is : '||l_column_name_tab.count);
81 End;
82 /
PL/SQL procedure successfully completed.its running fine so the problem is l_column_name_tab(i) !!!!!!
and there is nothing wrong with l_table_tab(k) and its declaration.
Edited by: 792353 on Dec 3, 2010 2:17 AM -
Pass Pl/sql table into USING clause in EXECUTE IMMEDIATE statment
Getting error when I try to pass the PL/SQL table into USING clause in EXECUTE IMMEDIATE statment:
Declare
result NUMBER;
TYPE values_tab IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
lv_tab values_tab;
lv_exp varchar2(300);
lv_exec varchar2(300);
BEGIN
lv_tab(1) := 5;
lv_tab(2) := 48;
lv_tab(3) := 7;
lv_tab(4) := 6;
lv_exp := ':b1+:b2+(:b3*:b4)';
lv_exec := 'SELECT '||lv_exp ||' FROM DUAL';
EXECUTE IMMEDIATE
lv_exec
INTO
result
USING
lv_tab;
DBMS_OUTPUT.PUT_LINE(result);
END;
Error at line 1
ORA-06550: line 20, column 12:
PLS-00457: expressions have to be of SQL types
ORA-06550: line 15, column 8:
PL/SQL: Statement ignored
I am trying to evaluate the expression ":b1+:b2+(:b3*:b4)" which is stored in table. This table has different expressions (around 300 expressions). I want to use the bind variables in expression because each expression evaluated thousand of time may be more in some case. If I don't use bind variable then it fill shared pool.
Is there any way I can pass the USING (IN) parameters dynamically instead of writing "USING lv_tab(1), lv_tab(2), lv_tab(3), lv_tab(4)"? As number of input parameters change depend on the expression in the table.
If not possible please suggest any other ideas/approches
Please help..
Edited by: satnam on Jun 11, 2009 11:50 AMWell, you keep changing reqs faster I can keep up. Anyway, assuming N-th bind variable (left-to-right) corresponds to collection N-th element:
Declare
result NUMBER;
lv_tab values_tab := values_tab();
lv_exp varchar2(300);
lv_exec varchar2(300);
lv_i number := 0;
BEGIN
lv_tab.extend(4);
lv_tab(1) := 5;
lv_tab(2) := 48;
lv_tab(3) := 7;
lv_tab(4) := 6;
lv_exp := ':5000135+:5403456+(:5900111*:5200456)';
lv_exec := lv_exp;
While regexp_like(lv_exec,':\d+') loop
lv_i := lv_i + 1;
lv_exec := REGEXP_REPLACE(lv_exec,':\d+',':b(' || lv_i || ')',1,1);
end loop;
lv_exec := 'BEGIN :a := ' || lv_exec || '; END;';
DBMS_OUTPUT.PUT_LINE(lv_exec);
EXECUTE IMMEDIATE lv_exec USING OUT result,IN lv_tab;
DBMS_OUTPUT.PUT_LINE(result);
END;
BEGIN :a := :b(1)+:b(2)+(:b(3)*:b(4)); END;
95
PL/SQL procedure successfully completed.
SQL> SY. -
How to re-execute anonymous PL/SQL block in package definition ?
Hi all,
I implemented a package which contains procedures and an anonymous PL/SQL block.
This anonymous PL/SQL block is executed only once when the package is called.
and charge in-memory the content of table to avoid multiple SQL access each
time one procedure is called.
As my application open many sessions to the Oracle database, I would like to try
a solution to signal all sessions to reload the content of table when the content
of table is modified. The solution to stop and to restart the connection is not
acceptable.
Best regards
Sylvain> .. to avoid multiple SQL access each time one procedure is called.
As I understand your posting, this is the actual technical requirement. You want to force serialisation of PL/SQL code. Correct? (only one session at a time can run the procedure)
This feature typically used to accomplish this in o/s code is called a semaphore. PL/SQL does not specifically support semaphores. However, it supports a range of IPC (Inter Process Communication) methods - from message queues to pipes.
One of these IPC interfaces is DBMS_LOCK - which allows a unique lock to be defined and processes to manage their resource usage/execution/etc via this lock using the DBMS_LOCK API.
I've found this a pretty clean and manageable solution to enforce serialisation. Of course, it is even better not to enforce serialisation. Rather design the code to be thread safe and capable of multi-processing/parallel processing.
Personally, I would not use a table as an IPC mechanism as Oracle already provides better IPC mechanisms for PL/SQL code. As for "signalling sessions to re-load the table" - not possible as Oracle sessions cannot register callbacks to handle events. Oracle sessions are not event driven processes from a PL/SQL (application development) perspective.
Maybe you are looking for
-
My emails in mail have just disappeared leaving the headers of date etc
my emails in mail have just disappeared leaving the headers of date etc any one out there who has had this before smburc
-
Create material number in Idoc
Hi experts, I am new to create Idoc and ale.so please help me with basic steps. I have two servers ECC6.0 and 4.7. I want to send the details like (mbrsh,mtart.maktx,meins) from 4.7 then i want to create the material
-
How to get FF to remember bookmark folders
how do I make FF 'remember'the last used folder in bookmarks. Say I book mark a film into movies folder and then want to bookmark another film, how can i get the folder called movies to open again until changed
-
ABC Superbowl Ads are in HD - why not more HD ads?
There seems to be alot of HD editors in this forum, so what better than to discuss my impressions of the flagship HD broadcast of the year. I've been watching the Superbowl broadcast on ABC in HD via Comcast on a Plasma Display. The game footage look
-
OL-290 Quicken 2007 Lion Bill Pay
How do I disable Bill Pay in Quicken 2007 Lion and then reactivate? Every time I try to pay bills through bill pay on Quicken 2007 Lion, I get error message OL-290, which is an SSL server error. I've spoken to Quicken several times and they say they'