Run immediately exit DOF?
Hi all!If you run some ddl in SQL * Plus, Oracle offers a feedback, for example:
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
Connected as user
SQL> alter index table_ix01 rebuild;
Index altered
SQL>
Now run the same DOF as immediate execution:Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
Connected as user
SQL> begin
2 execute immediate ('alter index table_ix01 rebuild');
3 end;
4 /
PL/SQL procedure successfully completed
SQL>
Is there a way to get the same result in pl/sql, as in sql? I want to capture the "Index corrupted" message to write to a log file.I know I can use pl/sql to generate pure sql and feed of SQL * Plus, but that don't s not what I was looking for!
Thank you!
Rob
Well... you can try the DBMS_SQL. Function LAST_SQL_FUNCTION_CODE which seems to work with EXECUTE IMMEDIATE...
http://docs.Oracle.com/CD/E11882_01/AppDev.112/e25788/d_sql.htm#ARPLS68274
.. .but you must compare the result with this list...
http://DocStore.Mik.UA/orelly/Oracle/Bipack/ch02_03.htm#CH02-table-13
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> SET SERVEROUTPUT ON;
SQL> DECLARE
2 TYPE string_collection IS TABLE OF VARCHAR2 (30);
3
4 sql_function_codes CONSTANT string_collection
5 := string_collection (
6 'CREATE TABLE',
7 'SET ROLE',
8 'INSERT',
9 'SELECT',
10 'UPDATE',
11 'DROP ROLE',
12 'DROP VIEW',
13 'DROP TABLE',
14 'DELETE',
15 'CREATE VIEW',
16 'DROP USER',
17 'CREATE ROLE',
18 'CREATE SEQUENCE',
19 'ALTER SEQUENCE',
20 '(NOT USED)',
21 'DROP SEQUENCE',
22 'CREATE SCHEMA',
23 'CREATE CLUSTER',
24 'CREATE USER',
25 'CREATE INDEX',
26 'DROP INDEX',
27 'DROP CLUSTER',
28 'VALIDATE INDEX',
29 'CREATE PROCEDURE',
30 'ALTER PROCEDURE',
31 'ALTER TABLE',
32 'EXPLAIN',
33 'GRANT',
34 'REVOKE',
35 'CREATE SYNONYM',
36 'DROP SYNONYM',
37 'ALTER SYSTEM SWITCH LOG',
38 'SET TRANSACTION',
39 'PL/SQL EXECUTE',
40 'LOCK',
41 'NOOP',
42 'RENAME',
43 'COMMENT',
44 'AUDIT',
45 'NO AUDIT',
46 'ALTER INDEX',
47 'CREATE EXTERNAL DATABASE',
48 'DROP EXTERNAL DATABASE',
49 'CREATE DATABASE',
50 'ALTER DATABASE',
51 'CREATE ROLLBACK SEGMENT',
52 'ALTER ROLLBACK SEGMENT',
53 'DROP ROLLBACK SEGMENT',
54 'CREATE TABLESPACE',
55 'ALTER TABLESPACE',
56 'DROP TABLESPACE',
57 'ALTER SESSION',
58 'ALTER USER',
59 'COMMIT (WORK)',
60 'ROLLBACK',
61 'SAVEPOINT',
62 'CREATE CONTROL FILE',
63 'ALTER TRACING',
64 'CREATE TRIGGER',
65 'ALTER TRIGGER',
66 'DROP TRIGGER',
67 'ANALYZE TABLE',
68 'ANALYZE INDEX',
69 'ANALYZE CLUSTER',
70 'CREATE PROFILE',
71 'DROP PROFILE',
72 'ALTER PROFILE',
73 'DROP PROCEDURE',
74 '(NOT USED)',
75 'ALTER RESOURCE COST',
76 'CREATE SNAPSHOT LOG',
77 'ALTER SNAPSHOT LOG',
78 'DROP SNAPSHOT LOG',
79 'CREATE SNAPSHOT',
80 'ALTER SNAPSHOT',
81 'DROP SNAPSHOT',
82 'CREATE TYPE',
83 'DROP TYPE',
84 'ALTER ROLE',
85 'ALTER TYPE',
86 'CREATE TYPE BODY',
87 'ALTER TYPE BODY',
88 'DROP TYPE BODY',
89 'DROP LIBRARY',
90 'TRUNCATE TABLE',
91 'TRUNCATE CLUSTER',
92 'CREATE BITMAPFILE',
93 'ALTER VIEW',
94 'DROP BITMAPFILE',
95 'SET CONSTRAINTS',
96 'CREATE FUNCTION',
97 'ALTER FUNCTION',
98 'DROP FUNCTION',
99 'CREATE PACKAGE',
100 'ALTER PACKAGE',
101 'DROP PACKAGE',
102 'CREATE PACKAGE BODY',
103 'ALTER PACKAGE BODY',
104 'DROP PACKAGE BODY') ;
105 BEGIN
106 EXECUTE IMMEDIATE 'ALTER INDEX PK_EMP REBUILD';
107
108 dbms_output.put_line (
109 sql_function_codes (dbms_sql.last_sql_function_code) || ' succeeded.');
110 END;
111 /
ALTER INDEX succeeded.
PL/SQL procedure successfully completed.
SQL>
.. What at first glance seems a bit too much effort given that one.) everything you do is rebuild indexes and b.) I'm not sure that this list of codes is still updated to 100%.
And then as the DDL of this kind is generally quite short why not just attribute the statement to a string before you run it and just debug the statement?
Tags: Database
Similar Questions
-
How can I create VI with inputs that run immediately when the update?
I'm using LabView for controlling stepper motors. I would create a VI with a front panel that has 4 arrows, 2 per engine. My goal is to be able to run the VI and then press a button to move the engine.
I created separate VI for each funcition of engines - one vi to set current operations, to determine the current travel, another to move up by a certain amount and so on. Work of these vi and I can move and adjust engines, but only by running separate VI.
How can I combine them into a single VI and make them run to the pressure of a button or the change of a property? An example would be to establish a new current holding company and place the operation current vi run immediately and send the order to the engine. Then continue to press the arrow keys without having to hit 'run' on an another vi.
Thank you very much
-
What is the purpose of USE in "run immediately".
Hi all
I just want to understand what is the purpose of USING in "EXECUTE IMMEDIATE".
Say for example, the procedure below, what is the difference? Both will end up in the same result.
DECLARE
FIXED_STAT VARCHAR2 (4000);
VAL_STAT VARCHAR2 (4): = "ijkl";
BEGIN
EXECUTE IMMEDIATE ' INSERT INTO abcd (efgh) VALUES (: text_string)' USING "ijkl";
FIXED_STAT: = "INSERT INTO abcd (efgh) VALUES ('|)" VAL_STAT |') ' ;
IMMEDIATELY RUN FIXED_STAT;
END;
/
Two major assets to HELP to run immediately, i.e. using parameters
(1) SQL statement should not hard analysed by the database every time [performance gain].
(2) more important, to avoid the "SQL injection" and ensure that the variable data will be properly includes as part of the statement
-
run immediately fails with the error
The following code generates the error and I can not understand what the problem is:
SET SERVEROUTPUT ON;
declare
Val number (21);
s_sql varchar2 (2000);
Start
s_sql: = q '{select last_number in the Vale of all_sequences where sequence_owner = 'SST' and sequence_name = "ADDRESS_SEQ"}';
Dbms_output.put_line ('sql 1 ' | s_sql);
run immediately s_sql;
end;
Error report:
ORA-00905: lack of keyword
ORA-06512: at line 7
00905 00000 - 'lack the key word'
* Cause:
* Action:
select last_number SQL 1 in val all_sequences where sequence_owner = 'SST' and sequence_name = "ADDRESS_SEQ."
The error is strange since
Select last_number in the all_sequences where sequence_owner = 'SST' and sequence_name = "ADDRESS_SEQ."
is a valid instruction
Although I see no need for SQL dynamic in this case, in general, you must provide the vatiable to receive the value of the select statement outside the immediate execution. More like:
s_sql: = q '{select last_number in the all_sequences where sequence_owner = 'SST' and sequence_name = "ADDRESS_SEQ"}';
execute immediate s_sql in val
John
-
procedure call to run immediately
Hi Please help me call the procedure to run immediately.
I am trying to execute the procedure for several tables.
the same procedure on the SQL prompt works very well as shown below.
EXECUTE PROC1 ('BC_COALMINE');
Start
for rec in (select table_name
from all_tables
where table_name like '% BC_.
)
loop
run immediately 'execute proc1 (rec.table_name);
end loop;
end;
I get an error invalid SQL ORA-900.
concerning
EXECUTE is a SQL Plus command. In PL/SQL, you can simply call the procedure. And you need not EXECUTE IMMEDIATE. You can make a static call to the procedure. Like this.
Start
for rec in (select table_name
from all_tables
where table_name like '% BC_.
)
loop
PROC1 (Rec.table_name);
end loop;
end;
-
Run immediately in Oracle 10 g
Hi, I have a small doubt regarding run immediately.
According to my knowledge that we use run immediately to the writing of DDL(create,truncate,...) instructions to be executed in the procedure or function.
But I saw in my organization, some of the senior people (already left organization) used to write the inserts, updates, deletes in will also run immediate even there is not much involved dynamic logic.
But as per my knowledge run immediately can be misused by most pirates with SQL injection, I suppose!
Is there some reason they use run immediately instead of writing code directly? Or is there an advantage in writing like this. ???Delivery immediate to create tables and another using DDL is fundamentally undesirable and should be avoided at all costs.
Using run immediately you seem to exhibit, avoid too. Seniors were apparently not aware of the purpose of PL/SQL and the inconvenience of immediate execution.
If I could vote to remove execute immediate PL/SQL, I would immediately in favour, especially in the packages, procedures and functions, as they are saved, which means pre-built.-----------
Sybrand Bakker
Senior Oracle DBA -
ONE ERROR: run immediately (p_sql) return to p_id;
Has written a simple procedure:
procedure p_test)
P_ID number,
p_sql in varchar2
*)*
is
Start
run immediately (p_sql) return to p_id;
end;
Now, test it:
declare
P_ID number;
p_sql varchar2 (2000): = ' insert into test1 (pk, str) values (1, "aaa")';
Start
pkg_utility.sp_save_without_blob (p_id, p_sql);
dbms_output.put_line ('p_id' | p_id);
end;
The problem:
Without the 'back in p_id' statement, the sql code can be run successfully. But with the "p_id return', an error occurred:
ORA-20999: unexpected error when insert into test1 (pk, str) values (1, 'aaa')
ORA-01006: there is no bind variable
What I've done wrong? and how do I solve the problem?
Thank you for helping.You're not saying 'what' you try to return.
See the examples in the doc of PL/SQL
http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/Collections.htm#BABHDGIG
>
Example 5-52, using the RETURN IN the Clause with a RecordDECLARE
RECORD IS of TYPE EmpRec (last_name, employees.last_name%TYPE,
salary employees.salary%TYPE);
method EmpRec;
emp_id NUMBER: = 100;
BEGIN
UPDATE employees SET salary = salary * 1.1
WHERE employee_id = emp_id
RETURN last_name, salary INTO method;
DBMS_OUTPUT. PUT_LINE
("Just give a stimulus to ' | emp_info.last_name |)
', which now makes | emp_info.salary);
ROLLBACK;
END;
/ -
Oracle 11G copy a table to help to run immediately
I want to copy the contents of a table in another aid to run immediately.
It keeps fails with the following error
ORA-00903: invalid table name
ORA-06512: at "TABLE_COPY", line 6
ORA-06512: at line 8 level
create or replace
procedure TABLE_COPY)
Table1 varchar2,
Varchar2 TABLE2)
is
Start
run immediately 'insert'. TABLE2. "(select * from ' |) TABLE1 |') ' ;
end;
Published by: user9213000 on January 24, 2013 07:38user9213000 wrote:
I want to copy the contents of a table in another aid to run immediately.It keeps fails with the following error
ORA-00903: invalid table name
ORA-06512: at "TABLE_COPY", line 6
ORA-06512: at line 8 levelcreate or replace
procedure TABLE_COPY)
Table1 varchar2,
Varchar2 TABLE2)
is
Start
run immediately 'insert'. TABLE2. "(select * from ' |) TABLE1 |') ' ;
end;Published by: user9213000 on January 24, 2013 07:38
Standard when boards (ab) use of EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
Then print the variable before passing to EXECUTE IMMEDIATE.
COPY the statement & PASTE in sqlplus to validate its correctness. -
How to replace run immediately in 11g?
Hi, package and I need not not to use run immediately. There are a few plsql dynamic generation and sql stored in global lists. Any other possibility to execute without run immediately? TNX for help.
Edited by: 982676 2013-01-18 01:11Dynamic code is dynamic. It must be run dynamically. And THIS should be the concern and not what dynamic execution interface is used.
Regarding the interfaces to execute dynamic PL/SQL code:
-immediate execution
-ref Cursor
-DBMS_SQL -
How to pass a sequence of 'help' to run immediately
How can I place a sequence.nxlval as a parameter using, here is my code looks like
sql_string is-> insert into some_tab (col1, col2,...) (select col1: passed_seq,...) where the... (I want to insert values in sequence for col2)
and I call it like
passed_seq: = "seq_". some_dynamic_num |'. nextval' (in my PB will be sequences with the string formed as seq_10.nextval)
EXECUTE IMMEDIATE sql_string using passes_seq;
If I do like this I get
Error: - 1722:ORA - 01722: invalid number seq_10.nextval
Published by: DIVI on 8 January 2013 07:40>
So is there another way to solve my problem, where queries are already formed and stored in a table in the form of data in the column, and I need to run those from different sequences in different scenarios.
>
Yes - you change applications to use a placeholder for the sequence you need (e.g. [SEQ_GOES_HERE]) when you need to run it you create a PL/SQL block into a VARCHAR2 variable, then use run immediately on the variable.If your stored query would look like this
sql_string is -> insert into some_tab (col1,col2, ....) (select col1,[SEQ_GOES_HERE],......) where ....
Load the good seq.nextval in a variable, and then replace "[SEQ_GOES_HERE]" in the query with this value.
-
Scheduled task (dba_job) running immediately after starting
Hello
Clone of post a scheduled task (dba_job) runs immediately after startup. This task must be performed only in Production - not in the test environment.
I know that we can stop the task to run using exec dbms_job.broken (42, TRUE), but to do this, I have to start the database.
The job runs as soon as I start the database. This creates problems.
Could someone help to prevent the execution of this work.
Thank you
Prasad AravaJOB_QUEUE_PROCESSES = 0
-
using where clause with value to hardcode in run immediately
Dear Experts, I use below in the stored procedure make exception.
RUN IMMEDIATELY "REMOVE CC. TB WHERE COL ='HG ";
When the collar is varchar2 (30) DC. TB
Please guide how to use above the statement in the stored procedure
Thank youDBA wrote:
Dear Experts, I use below in the stored procedure make exception.RUN IMMEDIATELY "REMOVE CC. TB WHERE COL ='HG ";
When the collar is varchar2 (30) DC. TB
Please guide how to use above the statement in the stored procedure
Thank you
Why you use dynamic SQL? DELETE statement is a DML statement and its valid inside a PL/SQL block.
So, you can remove the immediate execution and write your DELETE statement directly.
begin delete from cc.tb where col = 'HG'; end;
-
Hello
I have a requirement where I have to choose the number of records in each table (which meets specific criteria) in a variable and print it.
I wrote the following piece of code which results in an error.
Code:
declare
row_cnt number;
v_query varchar2 (200);
Start
for x in (select table_name
from all_tables
where owner = ' EDI$ ".
table_name order)
loop
v_query: = ' select count (*) in: Y of ' | x.table_name;
dbms_output.put_line (x.table_name);
dbms_output.put_line (v_query);
execute immediate v_query using row_cnt;
end loop;
end;
/
Output:
EDI_UFE
Select count (*) in: Y de EDI_UFE
ERROR on line 13:
ORA-06550: line 13, column 14:
PLS-00103: encountered the symbol "SELECT" at the expected in the following way:
(- + new case mod not null < an ID >)
Let me know if the code has a any error.
Thanks in advance.declare
row_cnt number;
v_query varchar2 (200);
Start
for x in (select table_name
from all_tables
where owner = ' EDI$ ".
table_name order)
loop
v_query: = ' select count (*) from ' | x.table_name;
dbms_output.put_line (x.table_name);
dbms_output.put_line (v_query);
run immediately v_query in row_cnt;
end loop;
end;
/Edited by: lifexisxnotxsoxbeautiful Vithalani March 4, 2011 04:36
-
There is a problem with Adobe Acrobat/Reader. If it is running, please exit and try again. (0:521)
Although I found other discussions in this forum regarding this error - none of the fixes seem to work. I have not found exactly the same error number (0:521), I might need a different fix for this? Has anyone else had the same error?
Just to note, this seems to be a problem with Internet Explorer 8 on Windows 7 when displaying PDF files 'in the browser"which is using the plugin. Other versions of IE on other machines and FF on the same machine work very well on the same PDF files. It also works if you right-click on the pdf file, download and view it in Acrobat Reader 'locally '.
Any help greatly appreciated, I'm stumped.
'Open' Adobe Reader X
Go to "EDIT".
Open "Preferences" Ctrl + K
Open "General".
Select default PDF Manager
Select the product of the WAA
in this case WAA Reader X (10.1.1)
Apply
You want to enable blah blah blah YES
Restart your system blah blah blah YES
and he worked it at least he did
a 0:521 on IE9, Windows 7 error
-
Hello. I created a stored procedure that starts an immediate execution "create table..." Responses to Oracle with the message ' ORA-01031: insufficient privileges.
I solved the problem adding 'authid current_user is' in the procedure declaration.
Unfortunately, if I try to plan his by DBMS_JOB, responses to oracle with the same error again.
Why? And how can I avoid it?
Thank you very much in advance
Published by: user4501018 on 6-mag-2010 4.00user4501018 wrote:
Unfortunately, if I try to plan his by DBMS_JOB, responses to oracle with the same error again.
Add:
run immediately "role play all THE ';"
before immediate 'create table..."
SY.
Maybe you are looking for
-
Computer: Mac Mini (2016); 10.11.3 OS I have a problem, restart the computer after the update Olympus Viewer. After I clicked on Restart, the Mac went through the usual screens, and I was able to enter my password. After that, he on board to the nex
-
How can I calculate the amount of download and upload traffic within a single session?
Hi, I would like to calculate how much the traffic of data (in bytes) that I use a session (time).Mind you, I speak not of connection speed.I guess I have sum download traffic to forward traffic, but I don't know where I can find it in my Firefox or
-
Fault strike; should be "how to restore him organize bookmarks... selection." Also, this selection does not exist when I manually change Firefox to show the new tab menu orange "Firefox" in the upper left of the Firefox window.
-
Satellite C650 problem with USB ports
Hello I have a problem with my laptop, with my USB ports. A few days ago, I plugged my mp3 to charge its battery. I did when system Windows began and after a few ports seconds has stopped working. They work for one to five minutes after starting my c
-
Cannot retrieve the Satellite to factory settings after installing Win XP
I was running windows recovery then I chose 'delete all data... '. "something like that.Then in the Middle by mistake I turned off the system. After that, I tried to start windows so was in error "missing operating system". I managed to install WINDO