Using run immediately in Oracle PLSQL
HelloPlease tell me what's the use of using the EXECUTE IMMEDIATE statement?
According to the docs, it is said that:
The EXECUTE IMMEDIATE statement prepares (analysis) and immediately executes a dynamic SQL statement.
The EXECUTE IMMEDIATE statement analyzes the SQL string command and executes the statement.
An example of EXECUTE IMMEDIATE in a block:
DECLARE
sql_stmt VARCHAR2 (200);
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE (NUMBER, amt id NUMBER) Bonus';
sql_stmt: = "INSERT INTO dept VALUES (: 1,: 2: 3)"; "
Here, I have a question, what is the purpose to use EXECUTE IMMEDIATE, I mean if I do not use EXECUTE IMMEDIATE will that my statement will not be created?
For example: him below will also work where I use not any what EXECUTE IMMEDIATE to process a statement,
DECLARE
sql_stmt VARCHAR2 (200);
BEGIN
' *' Bonus (id NUMBER, amt NUMBER) CREATE TABLE '; *
sql_stmt: = "INSERT INTO dept VALUES (: 1,: 2: 3)"; "
explain please, thank you.
user10503747 wrote:
I don't know for what reason the bonus of the table is not being created
Of course not. You have coded the exception handler for delete all exceptions... and pretend that there is no error.
Then... According to the logic of this code, there is no error and the table has been created very well.
Tags: Database
Similar Questions
-
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 -
Can I use run immediately "to process_point on submit '.
Hello friends,
In oracle apex 3.2.1 Oracle 11g.
can I use the following instructions as given below
immediately execute stmt in var_datatype;
to process_point 'submit immediately after calculations and validations'.
I get the following error:
ORA-00936: lack of expression
Thanks for giving me another approach if this is not possible. I got to run the select statement!
Thank you/kumar
Published by: kumar73 on April 26, 2010 10:35Hello
This isn't a problem of EXECUTE IMMEDIATE
CHAI table in your application is the analysis of schema?You can try the query from all_tab_columns where you can select also from an owner as
SELECT DATA_TYPE FROM ALL_TAB_COLUMNS WHERE COLUMN_NAME = 'EVNDRIVE' and TABLE_NAME = 'CHAI' and OWNER = 'MY_SCHEMA'
BR, Jari
-
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.
-
run immediately and the set of query results
Hi gurus,
I want to create a series of paintings on the fly using run immediately.
the table_names are stored in another table work_table.
run immediately (select 'create table' | table_name |) '(id int)' of
* (select table_name in work_tables)); *
This will raise error.
ORA-06550: line 1, column 18:
PLS-00103: encountered the symbol "SELECT" at the expected in the following way:
(en) - + new case mod not null < an ID >
< between double quote delimited identifiers of > < a variable binding >
instead of using a cursor to run one by one is the lines an alternative solution?
Thank you very much
CharlesMay not know why you want to do it in a single statement, anyway:
SQL> select * from work_tables; TABLE_NAME ------------------------------ x1 x2 SQL> declare 2 str varchar2(32000); 3 begin 4 for r in (select table_name from work_tables) loop 5 str := str || 'execute immediate ''create table ' || r.table_name || '( id int )''; ' ; 6 end loop; 7 8 execute immediate 'begin '||str||' end;'; 9 10 end; 11 / PL/SQL procedure successfully completed. SQL> desc x1 Name Null? Type ----------------------------------------------------------- -------- ------------------------------ ID NUMBER(38) SQL> desc x2 Name Null? Type ----------------------------------------------------------- -------- ------------------------------ ID NUMBER(38)
Max
http://oracleitalia.WordPress.comPublished by: Massimo Ruocchio, February 18, 2010 15:03
-
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
-
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. -
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;
-
run a string using to run immediately
Hi experts,
How can I run a string using to run immediately
f.g. I want to execute the statement given below, but it gives "ORA-00900: invalid SQL statement" error:
run immediately "select id from enterpriseuser";
Thank you very muchYou must run as below:
SQL> declare 2 v_test pls_integer; 3 begin 4 execute immediate 'select 2 from dual' into v_test; 5 dbms_output.put_line('v_test ' || v_test); 6 end; 7 / v_test 2
-
Features of BigDecimal.ROUND_HALF_UP using ORACLE PLSQL
Hello
is there a way I can reproduce the functionality of BigDecimal.ROUND_HALF_UP using PL SQL to oracle.
I'm looking for the following rounded result.
Value-> expected result
165.725-> 165.72
165.726-> 165,73
165.724-> 165.72
ROUND (165.725,2) current is not giving me the results for 165.725 expected... I expect 165.72 rather 165.73.
Ravi
Hello
Solomon Yakobson says:
... And apparently you were flanking class Math...
I like the picture to go on the sides of the class math, rather than face him (perhaps for fear of flunking).
In any case, I don't think that we can simply add (or subtract) a constant and then round. No mater what ever we choose, which will cause numbers which are very close to the Middle - order to round up the bad sense. If we add-. 001, for example, this means a number such as 70.0059 will get rounded down to 70, not 70,01.
If we cannot assume that the numbers are already rounded, we should do something like this:
SELECT column_value AS n
CASE
WHEN ABS (MOD (column_value,.01)) =.005
THEN TRUNC (column_value, 2)
ANOTHER round (column_value, 2)
END AS round_half_down
TABLE (sys.odcinumberlist (65.72,65.7212,65.722,65.725,65.726,65.729, 65,73, 65.726,-65.72,-65.7212,-65.722,-65.725,-65.726,-65.729,-65.73,-65.726,-70.0059, 70.0059))
)
ORDER BY column_value
;
Output:
ROUND_HALF_DOWN N
---------- ---------------
-70.0059 - 70.01
-65.73 - 65,73
-65.729 - 65,73
-65.726 - 65,73
-65.726 - 65,73
-65.725 - 65,72
-65.722 - 65,72
-65.7212 - 65,72
-65.72 - 65,72
65,72 65,72
65.7212 65,72
65.722 65,72
65.725 65,72
65.726 65,73
65.726 65,73
65.729 65,73
65,73 65,73
70.0059 70.01
-
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;
/ -
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
-
How to create the xml file in oracle plsql
Hello
I need the under xml (abc.xml) in unix Server out_directory file (the out_directory path: / u01/apps/xml /)
Select sivauser, sivapwd from sivainformations;-it will be multiple records
Select sivatelepone phone; - it will be multiple records
Select xyzverion versionid; - it will be multiple records
based on the above information, I need the sub file xml using oracle plsql procedure or a block
example: suppose we record
<? XML version = "1.0" encoding = "UTF-8"? >
"< sivaService version ="2.0"xmlns ="http://www.siva.ab/siva/4.0/test">."
< data language 'DEU' = >
< sivauser action = "siva3" sivapwd = "siva123" > --i need to sivainformations table(sivauser,sivapwd) timeline
phone < sivatelepone > < / sivatelepone >--i need to chronogram sivatelepone table (phone) based on the sivauser column
< abcversion version = "1.0" >
< Productinfo >
versionID < xyzverion > < / xyzverion >--i need to xyzverion (versionid) based on the sivauser column table records
< / Productinfo >
< / abcversion >
< / action >
< / data >
< / sivaService >
example: assume that multiple records<? XML version = "1.0" encoding = "UTF-8"? >
"< sivaService version ="2.0"xmlns ="http://www.siva.ab/siva/4.0/test>
< data language 'DEU' = >
< sivauser action = "siva3" sivapwd = "siva123" > --i need to sivainformations table(sivauser,sivapwd) timeline
< sivatelepone > '345678' < / sivatelepone >--i need to chronogram sivatelepone table (phone) based on the sivauser column
< abcversion version = "1.0" >
< Productinfo >
'1.1' < xyzverion > < / xyzverion >--i need to xyzverion (versionid) based on the sivauser column table records
< / Productinfo >
< / abcversion >
< / action >< sivauser action = "siva4" sivapwd = "siva123" > --i need to sivainformations table(sivauser,sivapwd) timeline
< sivatelepone > '123456' < / sivatelepone >--i need to chronogram sivatelepone table (phone) based on the sivauser column
< abcversion version = "1.0" >
< Productinfo >
"1.2" < xyzverion > < / xyzverion >--i need to xyzverion (versionid) based on the sivauser column table records
< / Productinfo >
< / abcversion >
< / action >
< / data >
< / sivaService >Please help me
Thank you
SivaI added a column ID to match the lines between the three tables.
SQL> with sivainformations 2 as 3 ( 4 select 1 id, 'karthick' sivauser, 'karthick' sivapwd from dual union all 5 select 2 id, 'ram', 'ram' from dual 6 ) 7 , sivatelepone 8 as 9 ( 10 select 1 id, 1234567890 telepone from dual union all 11 select 2 id, 1234512345 from dual 12 ) 13 , versionid 14 as 15 ( 16 select 1 id, 1.1 versionid from dual union all 17 select 2, 1.2 from dual 18 ) 19 select xmlelement 20 ( 21 "shivaService" 22 , xmlattributes('2.0' as "version", 'http://www.siva.ab/siva/4.0/test' as "xmlns") 23 , xmlelement 24 ( 25 "Data" 26 , xmlattributes('DEU' as "language") 27 , xmlagg 28 ( 29 xmlelement 30 ( 31 "Action" 32 , xmlattributes(s.sivauser as "sivauser", s.sivapwd as "sivapwd") 33 , xmlelement("shivatelepone", t.telepone) 34 , xmlelement 35 ( 36 "abcversion" 37 , xmlattributes('1.0' as "version") 38 , xmlelement 39 ( 40 "ProductInfo" 41 , xmlelement("xyzversion", v.versionid) 42 ) 43 ) 44 ) 45 ) 46 ) 47 ).EXTRACT('*') xml_output 48 from sivainformations s 49 join sivatelepone t 50 on s.id = t.id 51 join versionid v 52 on s.id = v.id; XML_OUTPUT -------------------------------------------------------------------------------------------------------------------
1234567890 1.1 1234512345 1.2 -
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
Maybe you are looking for
-
Given that I downloaded a new version of mozilla, everytime I open firefox opens a tab mozilla.org next to a label with my home page. How can I stop firefox opening the tab with the mozilla.org page?
-
I'm looking for a time sound real when system starts in a PDA?
Hi all! I want to create a program that can be useful as a meter away. I have the PDA with microphone and speaker, so I can use it as sonar in the audible range. The problem is when I try to find the point in time when my acoustic impulse starts ring
-
Can't get my printer to work error message says: communication problem
printer error message want to work: communication problem
-
Send program if command is unable to receive the signal
I'm relatively new to LabVIEW and tries to do an IF statement to get a response from the hardware store. If it receives a response, a response, do nothing. If it does not receive a response order (for, say, 1 second) hardware. With the LabVIEW data,
-
I can't send Emails of Outlook Express recently. I deleted norton antivirus which has accelerated, but no shipping. Even disable the firewall is not good. POP3 is set up correctly in Outlook Express and I can receive Emails. A message of support