Execute immediate in pl/sql block not functioning
Hello,
I've made a short plsql block which create's a bind variable on an dynamic select. when i try this in sqplus with a dbms_output.put_line(v_temp) the correct value is displayed but within the execute immediate commando the bind variable is not filled. Here's the code:
DECLARE
v_count number(5) := 1;
v_text varchar2(200);
v_temp varchar2(200);
BEGIN
select count(*) into v_count from v_survey_questions where page_id=2;
for c1 in 1..v_count
loop
v_temp:='select text into :P2_Q'||c1||' from v_survey_questions where page_id=2 and ord='||c1||'';
execute immediate v_temp;
end loop;
END;
Any help would be appreciated.
Thanks Leo.
Hi Vikas,
Thanks but i've tried that. The thing is that the bind variable :P2_Q1 is dynamic generated like this:
DECLARE
v_count number(5) := 1;
v_temp varchar2(2000);
v_temp2 varchar2(200);
BEGIN
select count(*) into v_count from v_survey_questions where page_id=2;
for c1 in 1..v_count
loop
v_temp:='select text from v_survey_questions where page_id=2 and ord=1';
v_temp2:=':P2_Q'||c1;
execute immediate v_temp into v_temp2;
end loop;
END;
Hope you can help me out.
Greetings,
Leo.
Similar Messages
-
While executing the following pl/sql block Iam getting following error
While executing the following pl/sql block
Iam getting following error
ORA-06550: line 5, column 11:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 5, column 11:
PL/SQL: Item ignored
declare
TYPE t_customer_details IS REF CURSOR;
o_customer_details t_customer_details;
v_rec o_customer_details%ROWTYPE;
begin
o_customer_details:=pkg_search.fngetcustdetails( 2727,1000841, NULL,NULL,119105329);
LOOP
FETCH o_customer_details INTO rec ;
EXIT WHEN o_customer_details%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(' print' );
END LOOP;
CLOSE o_customer_details;
end;sorry
declare
TYPE t_customer_details IS REF CURSOR;
o_customer_details t_customer_details;
begin
o_customer_details:= pkg_search.fngetcustdetails( 2727,1000841, NULL,NULL,119105329);
FOR v_rec IN o_customer_details
LOOP
DBMS_OUTPUT.PUT_LINE(' print' );
END LOOP;
END;I changed code,
Can you say , o_customer_details:= pkg_search.fngetcustdetails( 2727,1000841, NULL,NULL,119105329); is it right?
pkg_search.fngetcustdetails return ref cursor?? -
Calling 'start' from a pl/sql block or function
hi all,
i want to start a script from a Procedure, but using start is invalid, so i think the command 'start' is SQL*PLUS-Command. When i run the following code:
declare
stmt varchar2(200);
begin
stmt := 'start C:\null.sql';
execute immediate stmt;
end;
i get this Error:
ERROR at line 1:
ORA-00900: invalid SQL statement
ORA-06512: at line 5
how can i run a script from a Procdure???
thankshi,
i know that man can use java to run external commads, but this is not a system command. its sql*plus command!??
my solution befor having the idea tu use "start sql_script" is to read the commands from the script file ( either using utl_file or java) and then executing it.
is there an other way to run sql*plus commands (like start) from a PL/SQL block? -
Execute immediate and dynamic sql
Dear all;
Just curious....Why do developers still use dynamic sql..and execute immediate, because I always thought dynamic sql were bads and the use of execute immediate as well...
or am I missing something...There are no 'bad' things and 'good' things.
There are 'correctly used' and 'incorrectly used' features.
It depends what you want to do.
One simple example: Oracle 11.2 - you write a package that fetches data from range interval partitioned table (a new partition is created automatically every day when new key values are inserted). If you use static SQL then whenever Oracle creates a new partition then your package gets invalidated and has to be compiled. If your package is heavily used (by many sessions running in parallel) then you may get this:
ORA-04068: existing state of packages has been discarded
ORA-04061: existing state of package body "PACKAGE.XXXXX" has been invalidated
ORA-06508: PL/SQL: could not find program unit being called: "PACKAGE.XXXXX" Nice, isn't it?
You can avoid this kind of problems by simply using dynamic SQL. You break dependency with the table and your package is not invalidated when new partition is created. -
My First while loop inside PL/SQL block not working , please help
Hi ,
I am new to PL/sql and struck at PL SQL blocks , please help to solve this .
declare
v_A number constant :=10 ;
j number constant := 3 ;
BEGIN
WHILE j < v_A
LOOP
DBMS_OUTPUT.PUT_LINE('Hai');
END LOOP;
END;
please help as how to resolve this .
Thanks in advance .btw it's a useful habit to use indentation to highlight the block structure. Also it's worth deciding what your convention will be for keywords (I use uppercase, lowercase is also fine as far as I'm concerned but I've set up my editor to uppercase them) and variables, database object names etc (I use lowercase), e.g:
DECLARE
v_a CONSTANT PLS_INTEGER := 10;
j CONSTANT PLS_INTEGER := 3;
i PLS_INTEGER := j;
BEGIN
WHILE i <= v_a LOOP
DBMS_OUTPUT.PUT_LINE(i);
i := i +1;
END LOOP;
END;or perhapsdeclare
v_a constant pls_integer := 10;
j constant pls_integer := 3;
i pls_integer := j;
begin
while i <= v_a loop
dbms_output.put_line(i);
i := i +1;
end loop;
end;When I see "declare" and "BEGIN" in the same block of code I worry about the standard of code I'm going to see... -
My first PL/SQL block not working with using Select query within begin
I am new to PL/SQL , just started with basics of BLOCKS .
I am having a query here in executing a block .
When i am doing a insert oprtation in Blocks Begin method everything is working fine , but when ever i tried to do select operation , some error is being thrown .
First of all This is my Table :
select from try :*
KEY VALUE
Key Value
Key1 Value1
Key2 Value2
Key3 Value3
======================
This is the code which is not working : Please see the code and tell me what is the problem .
DECLARE
v_KEY VARCHAR2(20);
v_VALUE VARCHAR2(20);
BEGIN
select key into v_KEY FROM try where v_value='Value' ;
dbms_output.put_line(v_KEY);
END;
When i run this code , it is saying Data Not Found on this line " select key into v_KEY FROM try where v_value='Value' ;"
wheer when i run tis individually it worked fine :
select KEY FROM try where VALUE='Value' ;"
please share your ideas .as why it isn't running ??
Edited by: user10503747 on Sep 20, 2010 3:16 AMHi,
user10503747 wrote:
I am new to PL/SQL , just started with basics of BLOCKS .
I am having a query here in executing a block .
When i am doing a insert oprtation in Blocks Begin method everything is working fine , but when ever i tried to do select operation , some error is being thrown .
First of all This is my Table :
select from try :*
KEY VALUE
Key Value
Key1 Value1
Key2 Value2
Key3 Value3
======================
This is the code which is not working : Please see the code and tell me what is the problem .
DECLARE
v_KEY VARCHAR2(20);
v_VALUE VARCHAR2(20);
BEGIN
select key into v_KEY FROM try where v_value='Value' ;
dbms_output.put_line(v_KEY);
END;
When i run this code , it is saying Data Not Found on this line " select key into v_KEY FROM try where v_value='Value' ;"
wheer when i run tis individually it worked fine :
select KEY FROM try where VALUE='Value' ;"
please share your ideas .as why it isn't running ??
Edited by: user10503747 on Sep 20, 2010 3:16 AMInstead of:
{code}
select key into v_KEY FROM try where v_value='Value' ;
{code}
perhaps you meant something like:
{code}
v_value := 'Value1';
select key into v_KEY FROM try where v_value=Value ; -- No quotes
{code}
Until you assign a vlue to a variable, like v_value, it is NULL, so your original statement was equivalent to
{code}
select KEY FROM try where NULL='Value' ;
{code}
In PL/SQL, a SELECT ... INTO statement must return exactly one row, or else you will get an error (either NO_DATA_FOUND or TOO_MANY_ROWS). This is different from SQL, where a query cn return any number of rows, including 0, without raising an error. -
PL/SQL block not understood
Hi experts,
I'm looking at a PL/SQL like..
1> CREATE OR REPLACE TRIGGER trg_tbl_cat_biu
BEFORE INSERT OR UPDATE OF cat_id, parent_cat_id, display_order_no
ON tbl_cat
BEGIN
pkg_tbl_cat.newcat_ids := pkg_tbl_cat.empty;
pkg_tbl_cat.newparent_cat_ids := pkg_tbl_cat.empty;
END;
2> CREATE OR REPLACE PACKAGE pkg_tbl_cat
AS
TYPE numarray IS TABLE OF NUMBER
INDEX BY BINARY_INTEGER;
newcat_ids numarray;
newparent_cat_ids numarray;
empty numarray;
END;
can any one give a brief wht these section is doing?
Regards,
SKPafter inserting the other trigger which i've
mentioned previousely is used for this loop:
FOR i IN 1 .. pkg_tbl_cat.newparent_cat_ids.COUNT
Not clear. I guess - whenever u perform any DML statement on that perticular table, based on the condition triggers perform some operation to store some value inside the package variable - which in some cases cannot be obtain through :New.Value . So, using this package variable u can access the data inside the trigger. Moreover, the variable which is declared inside the package are treated as global variable. U can access these value in any procedure/function in that session. Your, for loop exectly does what i've told. With the help of the trigger u store some values into the package variable named pkg_tbl_cat.newparent_cat_ids. And, it is populated with data. Now using COUNT function u can iterate that perticular function - which is completely dependant on the number of data that have stored into that package variable.
Regards.
Satyaki De. -
SQL Server not functional after Windows Sysprep
Hello!
I sysprep generalized a full configured Windows Server 2012 Standard copy with SQL Server 2012 configured on it but not set up using the sysprep prepare method. I only want to generalize the windows copy but have the SQL install work as previously configured.
After i boot back into the server after the generalize finishes i am unable to access the SQL server using windows authentication even after i changed the computer name and use the same user accounts as before. I have seen the sysprep prepare for imaging
documentation for syspreping an SQL instance however i already have SQL installed and i just want to migrate this install to newer hardware. Does anyone have any advice for this? Thank you.Hello Kabitokaii,
It seems that sql server is not recognizing your new computer name. Since your new name is different from the name when SQL Server has been installed, you have to change the also in sys.servers....
you can query the name by submitting the following statement: (once you´re told you can´t connect only with windows autentication, i`m assumin that you can connect with SQL Server autentication.)
SELECT * FROM SYS.SERVERS.
If the names are different (from SYS.SERVERS to current machine name), you have to change is, following the bellow steps:
http://www.mssqltips.com/sqlservertip/2525/steps-to-change-the-server-name-for-a-sql-server-machine/
Steps to rename SQL Server
Execute the below commands for each instance on the machine.
-- for a Default Instance
sp_dropserver <old_physical_server_name>
GO
sp_addserver <new_name>, local
GO
--for a Named Instance
sp_dropserver <'old_physical_server_name\instancename'>
GO
sp_addserver <'new_name\instancename'>, local
GO
</new_name></old_physical_server_name>
Restart the SQL Server services.
Execute the below query in each instance to verify the updated system metadata.
SELECT @@SERVERNAME
Edvaldo Castro http://edvaldocastro.com MCITP Database Administrator on SQL Server® 2008 MCITP Database Administrator on SQL Server® 2005 MCTS: SQL Server® 2008 MCTS: SQL Server® 2005 MCT: Microsoft Certified Trainer MTA: Microsoft Technology Associate
MTAC – Microsoft Technical Audience Contributor CCSQLA – Cambridge Certified SQL Associate TOEIC – Test of English for International Communication -
EXECUTE IMMEDIATE ERROR ..
Kidnly somebody suggest me how to wirte below query in execute immediate in pl/sql block as it throwing below error
CREATE OR REPLACE PROCEDURE LBA_NORTH
AS
BEGIN
execute immediate ( 'CREATE TABLE LBA_ALERT(DATE_CRT,DIST_MSISDN,FOS_MSISDN,RT_COUNT,RT_SERIES)TABLESPACE PRTP_INDX1 AS
SELECT TO_CHAR(LMA.DATE_CRT,'DD-MON-YY'), LMP.DIST_MSISDN,LMA.FOS_MSISDN,COUNT(LMA.RT_MSISDN)RT_COUNT,
RTRIM (xmlagg (xmlelement (e, LMA.RT_MSISDN || ',')).extract ('//text()'), ',')AS RT_SERIES
FROM LBA_Mapping LMP,LBA_Master LMA
WHERE LMP.DIST_MSISDN=LMA.DIST_MSISDN
GROUP BY LMP.DIST_MSISDN,LMA.FOS_MSISDN,TO_CHAR(LMA.DATE_CRT,'DD-MON-YY')');
END;
LINE/COL ERROR
5/30 PLS-00103: Encountered the symbol "DD" when expecting one of the
following:
) , * & | = - + < / > at in is mod remainder not rem => ..
<an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_
LIKE4_ LIKEC_ between || multiset member SUBMULTISET_
The symbol "," was substituted for "DD" to continue.
5/39 PLS-00103: Encountered the symbol "),
LMP.DIST_MSISDN,LMA.FOS_MSISDN,COUNT(LMA.RT_MSISDN)RT_COUNT,
" when expecting one of the following:
. ( ) , * @ % & | = - + < / > at in is mod remainder not rem
LINE/COL ERROR
=> .. <an exponent (**)> <> or != or ~= >= <= <> and or like
LIKE2_ LIKE4_ LIKEC_ between || member SUBMULTISET_
The symbol "(" was substituted for "),
LMP.DIST_MSISDN,LMA.FOS_MSISDN,COUNT(LMA.RT_MSISDN)RT_COUNT,
" to continue.
6/65 PLS-00103: Encountered the symbol "/" when expecting one of the
following:
( - + case mod new null <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current max min prior sql stddev sum variance execute
LINE/COL ERROR
forall merge time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set
specification>
<an alternatively-quoted SQL string>
6/72 PLS-00103: Encountered the symbol "), " when expecting one of the
following:
. ( ) , * % & | = - + < / > at in is mod remainder not rem =>
.. <an exponent (**)> <> or != or ~= >= <= <> and or like
LINE/COL ERROR
LIKE2_ LIKE4_ LIKEC_ between || member SUBMULTISET_
Edited by: user3558544 on Mar 28, 2013 4:52 AMAnd by the way...
user3558544 wrote:
Kidnly suggest immediately
This is a forum of volunteers who have their own jobs to do. Suggesting they respond immediately or ugently is considered downright rude, not just to those volunteers but also to all the other people who would like a quick answer to their questions (but who haven't been rude).
Read: {message:id=9360002} -
Using Execute Immediate in PLSQL block Vs Stand alone procedure
I am facing very unusual ( atleast unusual to me ) with usage of "Execute Immediate" statement.
I have a table dynamic_sql with one column plsql_block as VARCHAR2(4000);
I have stored some PLSQL blocks ('DECLARE ..... BEGIN.... END.... ) in this column .
Now I want to execute these PLSQL blocks one after other depending on certain conditions .
In order to archive this I wrote a PLSQL block as below
DECLARE
Cursor c1 is
select plsql_block from dynamic_sql
begin
for irec in c1
loop
<<< Condition >>>
begin
execute_immediate(irec.plsql_block);
exception
when others then
raise_application_error(-20001,'error ' ||irec.plsql_block||' '||sqlerrm);
end loop ;
end ;
With above PLSQL block , "execute immediate" is executing PLSQL block successfully without any error
But When I converted above PLSQL block into standalone procedure as shown below , I am getting error .
CREATE OR REPLACE procedure test AS
Cursor c1 is
select plsql_block from dynamic_sql
begin
for irec in c1
loop
<<< Condition >>>
begin
execute_immediate(irec.plsql_block);
exception
when others then
raise_application_error(-20001,'error ' ||irec.plsql_block||' '||sqlerrm);
end loop ;
end ;
BEGIN
test;
end ;
It is showing the value of irec.plsql_block but not showing sqlerrm...
I found this is very unusual as I am able to execute "execute immediate" statement with PLSQL block but not with similar procedure .
can anybody explain me why this is happening?
Thanks in Advance
AmitHello,
It doesn't make any sense to add SQLERRM for user defined exception, unless you want to raise application error for already defined error (e.g NOT_DATA_FOUND, ..)
Check following piece of code and its output,
CREATE OR REPLACE PROCEDURE myinsert1
AS
v_count NUMBER;
v_sql VARCHAR2 (300);
BEGIN
v_sql :=
'INSERT INTO ENTITY_EMPLOYEE VALUES(0,''TIM'',''LASTNAME'',10000)';
BEGIN
EXECUTE IMMEDIATE v_sql;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE (SUBSTR (SQLERRM, 1, 300));
RAISE_APPLICATION_ERROR (-20002, 'My Error ' || SQLERRM, TRUE);
RAISE;
END;
END;
Output._
ORA-20002: My Error ORA-00001: unique constraint (ENTITY_EMPLOYEE_PK) violated
ORA-06512: at "MYINSERT1", line 21
ORA-00001: unique constraint (ENTITY_EMPLOYEE_PK) violated
ORA-06512: at line 2
Regrds -
Unable to INSERT PL/SQL record with EXECUTE IMMEDIATE
Hi All,
I am selecting data from a source table and after some modification inserting into a target table. Source and target table name are available at run time. You can say only source table structure is fixed.
I have crated a pl/sql table of type source record and inserting record by record in target table using execute immediate. But I am not able to write
EXECUTE IMMEDIATE string USING pl_sql_table(index); and getting error as
PLS-00457: expressions have to be of SQL types
Please see the part of code below. Is it possible to use FORALL with dynamic sql like
FORALL pl_sql_table.FIRST .. pl_sql_table.COUNT
EXECUTE IMMEDIATE .... pl_sql_table(j); -- Like this.
Please suggest why I am not able to write record here. I also want to replace 'INSERT in a loop' with a single INSERT statement out of the loop, to upload whole pl_sql table into target table in one go.
Thanks,
Ravi
DECLARE
TYPE rec_tab_CMP IS RECORD
model_id NUMBER(38),
absolute_rank NUMBER(5)
v_rec_tab_CMP rec_tab_CMP;
TYPE t_rec_tab_CMP IS TABLE OF v_rec_tab_CMP%TYPE INDEX BY BINARY_INTEGER;
v_records_CMP t_rec_tab_CMP;
rc SYS_REFCURSOR;
v_old_table_name VARCHAR2(30); -- passed from parameter
v_new_table_name VARCHAR2(30); -- passed from parameter
dyn_str VARCHAR2(500);
v_columns_str VARCHAR2(200) := ' model_id, absolute_rank ';
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE '|| v_new_table_name || ' AS SELECT * FROM ' || v_old_table_name ||' WHERE 1 = 2 ' ;
OPEN rc FOR 'SELECT '|| v_columns_str ||' FROM '|| v_old_table_name;
FETCH rc BULK COLLECT INTO v_records_CMP;
FOR j IN 1..v_records_CMP.COUNT
LOOP
v_records_CMP(j).model_id := 1; -- Do someting here, This thing can be performed in SQL stmt directly.
dyn_str := 'INSERT INTO '|| v_new_table_name ||' ( '|| v_columns_str || ' ) VALUES (:1, :2) ';
EXECUTE IMMEDIATE dyn_str USING v_records_CMP(j).model_id ,
v_records_CMP(j).absolute_rank ;
-- Here in place of two columns I want to use one record like
-- EXECUTE IMMEDIATE dyn_str USING v_records_CMP(j);
-- But it is giving me error like
-- EXECUTE IMMEDIATE dyn_str USING v_records_st(j);
-- PLS-00457: expressions have to be of SQL types
END LOOP;
CLOSE rc;
END;
/You cannot bind PL/SQL record types to dynamic SQL.
Possibly you could work around this by declaring the INDEX-BY table of records at package specification level, e.g.
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> CREATE PACKAGE package_name
2 AS
3 TYPE tt_emp IS TABLE OF emp%ROWTYPE;
4 t_emp tt_emp;
5 END package_name;
6 /
Package created.
SQL> CREATE TABLE new_emp
2 AS
3 SELECT *
4 FROM emp
5 WHERE 1 = 0;
Table created.
SQL> DECLARE
2 v_table_name user_tables.table_name%TYPE := 'NEW_EMP';
3 BEGIN
4 SELECT *
5 BULK COLLECT INTO package_name.t_emp
6 FROM emp;
7
8 EXECUTE IMMEDIATE
9 'BEGIN ' ||
10 ' FORALL i IN 1 ..package_name.t_emp.COUNT ' ||
11 ' INSERT INTO ' || v_table_name ||
12 ' VALUES package_name.t_emp (i); ' ||
13 'END;';
14 END;
15 /
PL/SQL procedure successfully completed.
SQL> SELECT empno, ename
2 FROM new_emp;
EMPNO ENAME
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
7900 JAMES
7902 FORD
7934 MILLER
14 rows selected.
SQL> -
Insert SQL does not work properly when called using CALL
I have a stored procedure (TEST_SP) which is used to insert a record in this perticular case. The SQL statement is 2526 characters long. I'm using
dim Params : Params=chr(1) & "Insert query" & Chr(1) & "=300"
runsql=&"{call TEST_SP(?,?)}"&Params
dim db : db=dbSelect("",0,"","")
dbExecSQL db,runsqlto execute the stored procedure. I'm facing an issue when the 2000th character on the insert SQL (pUPDSQL) is a single quote, where the SQL is not getting executed (i.e. record is not getting created).
The same stored procedure and the same SQL when run as below
runsql=runsql&"DECLARE "
runsql=runsql&"PUPDSQL VARCHAR2(4000); "
runsql=runsql&"PRES VARCHAR2(300); "
runsql=runsql&"BEGIN "
runsql=runsql&"PUPDSQL := 'INSERT query..."
runsql=runsql&"PRES:=300; "
runsql=runsql&"MRT_LKIDFULUP(PUPDSQL => PUPDSQL,PRES => PRES); "
runsql=runsql&"END; "
dim db : db=dbSelect("",0,"","")
dbExecSQL db,runsqlis working fine. Does anyone know if there is a limitaion in ODBC Call function or any explanation to above behaviour? I'm connecting to a Oracle 11g database using Microsoft ODBC for Oracle driver on Window 7
The stored procedures:
create or replace procedure TEST_SP(pUPDSQL IN VARCHAR2,pRES OUT VARCHAR2)
AS
BEGIN
DECLARE
emsg VARCHAR2(100);
BEGIN
if pUPDSQL<>'-1' then
emsg:='Cant exec UPDATE';
EXECUTE IMMEDIATE pUPDSQL;
if SQL%RowCount=0 then
pRES:='ERR:No row updated';
return;
end if;
end if;
pRES:='OK:';
EXCEPTION
WHEN OTHERS THEN
pRES:='ERR:' || emsg;
END;
END;Edited by: BluShadow on 11-Dec-2012 15:47
added {noformat}{noformat} tags for readability. Please read {message:id=9360002} and learn to do this yourself in future.... I'm facing an issue when the 2000th character on the insert SQL (pUPDSQL) is a single quote, ...Perhaps you need two single quotes? like:
runsql=runsql&"PUPDSQL := 'INSERT query...Values(..,..,,,''This value in two single quotes'',..,...)' "
... I'm connecting to a Oracle 11g database using Microsoft ODBC ...Dump windoze ODBC and better use the Oracle client ODBC.
:p -
Execute Immediate in Oracle 10g
Hi , I have a small doubt regarding execute immediate.
As per my knowledge we use execute immediate for writing DDL(create,truncate,...) statements to execute in the procedure or function.
But i have seen in my organization , some of the senior people(already left organization) used to write inserts , updates , deletes also in execute immediate even there is not much dynamic logic involved.
But as per my knowledge execute immediate can be badly used by most of the hackers with SQL injection I guess!!!!!
Is there any reason that they use execute immediate instead of writing the code directly??? Or is there any advantage in writing like this.???Using execute immediate to create tables and other DDL is fundamentally undesirable, and should be avoided at all cost.
The use of execute immediate you seem to outline, should be avoided too. Apparently those seniors were unaware of the goal of PL/SQL and the disadvantage of execute immediate.
If I could vote to remove execute immediate from PL/SQL, I would be immediately in favor, especially in packages, procedures and functions,as they are stored, which means pre-compiled.
Sybrand Bakker
Senior Oracle DBA -
Need help with EXECUTE IMMEDIATE
I have created a CHAR string in my form that contains a UPDATE statement. This statement is passed into my procedure and in the procedure, the EXECUTE IMMEDIATE is supposed to run the UPDATE statement. THIS IS NOT THE CASE for some reason. NEWVALUE is record is also passed into the procedure.
this is the UPDATE_STATEMENT statement prepared by my forms application:
'UPDATE xtable SET ACTION_CODE_DESC =''a b c'',INACTIVE =''N'' WHERE ACTION_CODE = newValue.ACTION_CODE'
The CHAR values are surrounded by a pair of single quotes. The UPDATE statement starts and ends with single quotes.
In my procedure I have this statement:
PROCEDURE JKUPD_ACTION_CODE
( newValue in etmst_action_code%rowtype
,UPDATE_STATEMENT in CHAR
,perr_count out number
AS
BEGIN
EXECUTE IMMEDIATE UPDATE_STATEMENT ;
IF SQL%NOTFOUND
THEN .......
I keep getting ORA-00900: invalid SQL statement and dont understand why this is happening.
Any ideas anyone?
Thanks :)I haven't seen a version indication for this thread, but there should be 2 (different!) functions that come with Oracle that might do what you want.
If all you want to do is dynamically execute text representing a SQL command check the on-line documentation (if there is any) for dbms_sql.execute and/or dbms_utility.exec_ddl. Make sure the string passed in are syntactically correct :) -
Error in PL/SQL Block of Trigger
Hi all,
I have written a trigger whose PL/SQL block contains a simple select statment among many other statements.
Now I find that, if the select statement returns no rows the trigger does not continue its operation further and aborts there itself. And if the select statement returns some rows, then it works fine.
I tried to execute a simplified PL/SQL block of the trigger in SQL*Plus and following were the results:
declare
tempdate date;
begin
select trdt into tempdate from inv_trans;
if sql%notfound then
null;
end if;
end;
When no data is present in inv_trans table, the result was:
declare
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 4
And when the table inv_trans had data, the result was:
PL/SQL procedure successfully completed.
Why is the piece of code flashing an error when I have already given a treatment if no data is found.
Why is it taking "No Data in table" as an abnormal condition and not normal?
THanks in advance
Warm Regards
ManuIn your case you have to use a cursor:
declare
cursor c_cur is
select trdt from inv_trans;
r_cur c_cur%rowtype;
begin
open c_cur;
fetch c_cur into r_cur;
if c_cur%notfound then
[pre]
Maybe you are looking for
-
I have a new PC (using windows 7 ....didn't like windows 8) and want to sync with my iTunes account to access apps as well as sync my iPad and iPhone. I've authorized the new PC on iTunes but it won't recognize it. I have removed the old pc from my a
-
Battery powered monitor for mac mini..
I'm wondering if there is any battery powered small monitor that i can buy as mac mini monitor..the idea is i can use mac mini while on the go..
-
Final cut express 1.0.1
Hello Just started to use final cut express And after following instructions from the "fce for dummies" manual I successfully captured a clip from my new sony dv camcorder. however I now have audio issues which are: The audio cannot be heard when I i
-
Hello, I have some footage that requires the mpeg-2 component. As I do not have final cut I bought this off apple and installed, but it doesn't work. I have searched many forums and followed the advice and made sure it is in the right folder but noth
-
What drive is used as superdrive in the new Macbook
Hello everyone For the first time ever, I'm soon the owner of a Mac I'm going to by a Macbook with superdrive, but can anyone tell me what model and manufacturer Apple uses for this drive?