Appeal procedure set up by IMMEDIATE EXECUTION
SQL> Create table bipul_test (a number(3), b number(2), c number(5), d varchar2(10), status varchar2(10));
Table Created.
SQL> desc bipul_test
Name Null? Type
----------------------------------------- -------- ----------------------------
A NUMBER(3)
B NUMBER(2)
C NUMBER(5)
D VARCHAR2(10)
STATUS VARCHAR2(10)
SQL> insert into bipul_test values(1,1,1,'a', null);
SQL> insert into bipul_test values(1,1,1,'b', null);
SQL> insert into bipul_test values(2,1,2,'c', null);
SQL> insert into bipul_test values(2,2,2,'d', null);
SQL> insert into bipul_test values(null, null, null, 'x',null);
SQL> commit;
SQL> select * from bipul_test;
A B C D STATUS
---------- ---------- ---------- ---------- ----------
1 1 1 a
1 1 1 b
2 1 2 c
2 2 2 d
x
Package: my_packageProcedure: proc2, proc3
CREATE OR REPLACE PACKAGE SRGUPTA.my_package AS
-- PROCEDURE proc2;
PROCEDURE proc2 (status OUT varchar2);
PROCEDURE proc3 (Proc_name IN VARCHAR2, status IN OUT varchar2);
END my_package;
/
CREATE OR REPLACE PACKAGE BODY SRGUPTA.my_package
IS
-- PROCEDURE proc2
PROCEDURE proc2(status OUT varchar2)
AS
n number(2);
BEGIN
update bipul_test set status ='SUCCESS' where A=1;
commit;
status:='FAILURE';
end proc2;
PROCEDURE proc3 (proc_name varchar2, status IN OUT varchar2)
AS
x varchar2(100):=null;
BEGIN
--EXECUTE IMMEDIATE 'BEGIN '||proc_name||'; END;';
EXECUTE IMMEDIATE 'BEGIN '||proc_name||'(status); END;';
if status='FAILURE' then
update bipul_test set status ='FAILURE' where A=2;
commit;
end if;
end proc3;
END my_package;
/
The Code of the appellant:set feedback on
set serveroutput on
DECLARE status VARCHAR2(100):='';
begin
my_package.proc3('my_package.proc2', status);
end;
/
EXIT;
Without THE normal execution mode param works very well. Above code is an effort through which I tried to capture the value of OUT to the appellant PROC3 param.PROC3 call PROC2 with immediate execution. Now if PROC2 have a parameter OUT and I want to capture in PROC3, is it possible?
Out of desire to my code:
SQL> select * from bipul_test;
A B C D STATUS
---------- ---------- ---------- ---------- ----------
1 1 1 a SUCCESS
1 1 1 b SUCCESS
2 1 2 c FAILURE
2 2 2 d FAILURE
x
Published by: handsome June 3, 2011 06:29
SQL> Create table bipul_test (a number(3), b number(2), c number(5), d varc
(10));
Table created.
SQL> insert into bipul_test values(1,1,1,'a', null);
1 row created.
SQL>
SQL> insert into bipul_test values(1,1,1,'b', null);
1 row created.
SQL> insert into bipul_test values(2,1,2,'c', null);
1 row created.
SQL> insert into bipul_test values(2,2,2,'d', null);
1 row created.
SQL> insert into bipul_test values(null, null, null, 'x',null);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from bipul_test;
A B C D STATUS
---------- ---------- ---------- ---------- ----------
1 1 1 a
1 1 1 b
2 1 2 c
2 2 2 d
x
SQL> CREATE OR REPLACE PACKAGE my_package AS
2 -- PROCEDURE proc2;
3 PROCEDURE proc2(status OUT varchar2);
4 PROCEDURE proc3(Proc_name IN VARCHAR2, status IN OUT varchar2);
5 END my_package;
6 /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY my_package
2 IS
3 -- PROCEDURE proc2
4 PROCEDURE proc2(status OUT varchar2)
5 AS
6 n number(2);
7 BEGIN
8 update bipul_test set status ='SUCCESS' where A=1;
9 commit;
10 status:='FAILURE';
11 end proc2;
12
13 PROCEDURE proc3 (proc_name varchar2, status IN OUT varchar2)
14 AS
15 x varchar2(100):=null;
16 BEGIN
17 --EXECUTE IMMEDIATE 'BEGIN '||proc_name||'; END;';
18 EXECUTE IMMEDIATE 'BEGIN '||proc_name||'(:1); END;' USING IN OUT status;
19
20 if status='FAILURE' then
21 update bipul_test set status ='FAILURE' where A=2;
22 commit;
23 end if;
24 end proc3;
25 END my_package;
26 /
Package body created.
SQL> set serverout on
SQL> DECLARE
2 status VARCHAR2(100):='';
3 begin
4 my_package.proc3('my_package.proc2', status);
5 dbms_output.put_line(status);
6 end;
7 /
FAILURE
PL/SQL procedure successfully completed.
SQL>
Tags: Database
Similar Questions
-
Set null in immediate execution
Hi I have a query like this
immediately run 'update | XYZ | 'set r_msg =' | null;
It does not work will advise me is there a typo or syntax error
What is the correct...Is xyz a variable containing the name of the table?
SQL> declare xyz varchar2(20) := 'emp'; begin execute immediate 'update ' || xyz || ' set sal = :x' using to_char(null); end; / PL/SQL procedure successfully completed. SQL> select ename, sal from emp / ENAME SAL ---------- --------------- SMITH ALLEN WARD JONES MARTIN BLAKE CLARK SCOTT KING TURNER ADAMS JAMES FORD MILLER 14 rows selected.
If not, what is xyz?
-
Changing table via the package with immediate execution (problem)
Hello
I have a unusual problem. I have a package that contains the procedure that via execute immediate statement, creates a table on which he performs different actions for example:
-alter table some_owner.dummy_table noparallel
-create index some_owner.idx_name on some_owner.dummy_table (column)...
But I only managed to run move and create synonym table/public via execute immediate statement. Actions as alter table and create index fails with error ORA-01031: insufficient privileges.
Note If call these commands outside the package (a simple script) this all done OK.
I found a way, where I set the AUTHID CURRENT_USER command create package statement. In this way all the actions executed OK.
I wonder why I can't change the table via the package with immediate execution on a table that is in the tablespace "SOME_TABLESPACE" and the title of owner "SOME_OWNER", without putting the AUTHID command on the package.
There must be a problem why a package cannot change the table which is owned by the user 'SOME_OWNER '.
All useful responses would be appreciated.
I have a unusual problem.
No - you don't have. This question has been answered SEVERAL times on this forum and others.
But I only managed to run move and create synonym table/public via execute immediate statement. Actions as alter table and create index fails with error ORA-01031: insufficient privileges.
OK - your username doesn't have privileges to do these operations or only received privileges through roles.
Roles are DISABLED in named PL/SQL blocks that use of the AUTHOR's rights.
Note If call these commands outside the package (a simple script) this all done OK.
I found a way, where I set the AUTHID CURRENT_USER command create package statement. In this way all the actions executed OK.
Of course - the roles are NOT disabled in named PL/SQL blocks that use the rights of the APPELLANT or in anonymous blocks.
I wonder why I can't change the table via the package with immediate execution on a table that is in the tablespace "SOME_TABLESPACE" and the title of owner "SOME_OWNER", without putting the AUTHID command on the package.
Well now you know!
-
How how to escape double match in immediate execution in the trigger
Hi all
Please inform me what is the error in this procedure.
I think that the problem in the way to escape double match.
SQL > create or replace procedure P2
2 is
3. start
4 run immediately 'create or replace trigger t2.
5 |' before insertion '
6: ' on tb_test'
7: ' for each row '
8: ' declare '
9: ' start '
* 10 |' immediate execution "create table t1 as select distinct (NVL (soundex (namess),"'NONE "')) test ' *;
11: ' end; »
12 end;
13
14.
CAUTION: Procedure created with compilation errors.
SQL > show error
Errors of PROCEDURE P2:
LINE/COL ERROR
-------- -----------------------------------------------------------------
10/83 PLS-00103: encountered the symbol "NONE" when expecting one of
What follows:
* & = - + ; <>/ is mod remains not return rem
return < an exponent (*) > <>or! = or ~ = > = < = <>and or
as like2 like4 likec between using | Member in bulk
submultiset
SQL >Hello
Try the code below:
create or replace procedure P2
is
Start
run immediately "create or replace trigger t2 before insertion
on tb_test
for each line
declare
Start
run immediately "create table t1 as select distinct (NVL (soundex (account_number),"NONE")) of the test";
end;';
end;
/ -
difference btw dbms_sql.execution and immediate execution
Hello
IAM using 10g, difference btw immediate.please dbms_sql.execution and execution to tell me.797525 wrote:
IAM using 10g, difference btw immediate.please dbms_sql.execution and execution to tell me.
SQL all (and all the anonymous PL/SQL blocks) are analyzed by Oracle as a SQL cursors. These cursor structures are stored in the Shared Pool in the SGA (shared memory area which are essentially the "brain" of the database instance).
Once a cursor was created for a statement SQL, how to use and interface with this SQL cursor on the server (from the point of view of the customer)?
We use on the client side, a calling interface (or API) that allows our code to interact with this SQL cursor on the server. This interface can be ODBC. Or BDE. Or ADO. Or many other 3-4 letters for database interfaces.
PL/SQL is also a language of 'customer' from a SQL perspective. Such as Java and c#, the code PL/SQL will be calls to the SQL engine to analyze and create SQL cursors.
Of course, PL/SQL differs in 2 areas. It runs in the process of the Oracle server. It is the neighbour of the SQL engine.
For this reason, PL/SQL is much more perfectly integrated with the SQL than Java or c#.
But even in spite of this integration, you still need an interface in the client (PL/SQL) to interact with the SQL cursor, that you have created. In PL/SQL, there are a number of such interfaces customer.
There are explicit and implicit cursors. And there are sliders DBMS_SQL and reference. And there are implicit cursors created through immediate enforcement.
The difference between DBMS_SQL and immediate execution is therefore a difference in customer language interface. The SQL cursor on the server (in the shared Pool) doesn't know what customer interface is used. He cares not.
Client side, each of these client interfaces to a SQL cursor has a different function. And determines which one to use.
run immediately , it's fast and easy for dynamic SQL, but it cannot be used to determine the structure (called projection SQL) returned by a cursor to Select . So despite the dynamic SQL code, we must always know the encoding of time, just what this slider will return to consume its production.
DBMS_SQL to 'describe' the cursor SQL projection. So, we can create a dynamic Select SQL cursor. We can question its interface describe in order to determine the number, names and the data types of the columns returned. It can be removed these column values dynamically and consume the cursor.
There are therefore a major difference in the two feature sets. Tools for interfacing with the same SQL cursor.
So the main points to remember are:
-all SQL liquidation as SQL cursors on the server
-you have different interfaces in the language of the client to interact with a SQL cursor+
+ Your mission as a programmer, if you choose to accept it, is to determine which of these client interfaces is better suited to meet the requirements in your code.
This message will self-destruct in... 5.4.3 2...
-
Update in immediate execution with rownum
Can I put in an UPDATE by immediate execution that only maximum 10 lines will be updated?
It is:
Thanks in advanceEXECUTE IMMEDIATE 'UPDATE A_PAZIENTI_ESAMI SET '|| ' NREFERTO = :1, '|| ' DATA_REFERTO = :2, '|| ' ANNOREFERTO = :3, '|| ' DATA_EROGAZ = :4, '|| ' STATO_REFERTO = :5, '|| ' MEDICO_E = :6 '|| ' WHERE '|| WHERE_CLAUSE_ESA -- || ' and rownum <= 10' -- this is my doubt -- USING AP_REFERTOB.NREFERTO, AP_REFERTOB.DATARF, EXTRACT (YEAR FROM AP_REFERTOB.DATARF) , AP_REFERTOB.DATAEROGA, STATOREFERTO, AP_REFERTOB.K_MED; COMMIT;
Hello
your query works very well. It updates only the first 10 rows based on the place where the condition.Thank you.
-
SQL dynamic immediate execution
Hi all
We have a table where we keep the query that will be executed and using bind variables.
But im facing some problems when I try to use it in immediate execution.
guess
function validate is
varaux varchar2 (200);
Start
for r1 in (select query,
using_bind
from table_1) loop
run immediately r1.query in varaux using r1.using_bind;
Return varaux;
end loop;
Returns a null value.
end;
I know that's not the way to do it, but can you give me instructions in the topic...
Thank you
Bruna
Published by: Bruna on January 4, 2013 03:07>
We have a table where we keep the query that will be executed and using bind variables.But im facing some problems when I try to use it in immediate execution.
>
No - the problems you are experiencing are because your function uses invalid syntax. The problems have NOTHING to do with 'run immediately '. This works for me and no changes have been made to the dynamic part.create or replace function fn_validate return varchar2 is varaux varchar2(200); begin for r1 in (select 'select ename from emp where empno = :1' query, 7369 using_bind from dual) loop execute immediate r1.query into varaux using r1.using_bind; return varaux; end loop; return null; end; declare myVar varchar2(200); begin myVar := fn_validate(); dbms_output.put_line(myVar); end; SMITH
-
sql dynamic and immediate execution
Hello all;
Just curious... Why developers are still using dynamic sql... and run immediately, because I always thought that dynamic sql were negative and the use of immediate execution as well...
or did I miss something...I like this white paper on the topic: SQL in PL/SQL
http://www.Oracle.com/technetwork/database/features/PLSQL/overview/doing-SQL-from-PLSQL-129775.PDF -
HELP-immediate execution in PL/SQL has received the error ORA-00904: invalid identifier
What is the problem with the following codes from PL/SQL (actually it comes to Oracle Metalink Note: 313175.1):
===========
declare
cursor c1 is select * from $ semantic;
v_statement VARCHAR2 (255);
v_nc number (10);
v_nt number (10);
Start
immediate execution
"select count (*) from $ semantics" in v_nc;
immediate execution
' select count (distinct s_table_name) of semantics$ "in v_nt;
dbms_output.put_line
('Edit' | v_nc |) 'columns ' | v_nt | "tables");
to r1 c1 loop
v_statement: = 'ALTER TABLE ' | R1.s_owner | '.' || R1.s_table_name;
v_statement: = v_statement | «change (' |)» R1.s_column_name | ' ';
v_statement: = v_statement | R1.s_data_type | ' (' | r1.s_char_length;)
v_statement: = v_statement | ' CHAR))';
immediately run v_statement;
end loop;
dbms_output.put_line ('Done');
end;
/
=====
Executed once the codes as sysdba against 10gr 2 database, I got this error:
From build to select columns to change
Editing columns 4428 35249
declare
*
ERROR on line 1:
ORA-00904: invalid identifier
ORA-06512: at line 22
I see nothing wrong with the line of "immediate execution". I appreciate your help!
Thank you.Hello
Try to print the offending instruction using exception, I used small test cases by changing the pl/sql block, you may need to change to respond to all other types of data in this table.CREATE TABLE semantics$ AS SELECT USER AS owner, table_name, data_type AS s_data_type, column_name, data_length AS s_char_length FROM cols WHERE table_name = 'MY_OBJECTS'; DECLARE CURSOR c1 IS SELECT * FROM semantics$; v_statement VARCHAR2 (255); v_nc NUMBER (10); v_nt NUMBER (10); BEGIN EXECUTE IMMEDIATE 'select count(*) from semantics$' INTO v_nc; EXECUTE IMMEDIATE 'select count(distinct table_name) from semantics$' INTO v_nt; DBMS_OUTPUT.put_line( 'ALTERing ' || v_nc || ' columns in ' || v_nt || ' tables'); FOR r1 IN c1 LOOP v_statement := 'ALTER TABLE ' || r1.owner || '.' || r1.table_name; v_statement := v_statement || ' modify (' || r1.column_name || ' '; v_statement := v_statement || r1.s_data_type || '(' || r1.s_char_length; IF (r1.s_data_type = 'NUMBER') THEN v_statement := v_statement || '))'; ELSE v_statement := v_statement || ' CHAR))'; END IF; DBMS_OUTPUT.put_line (v_statement); -- EXECUTE IMMEDIATE v_statement; END LOOP; DBMS_OUTPUT.put_line ('Done'); EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.put_line ('Statement = ' || v_statement); DBMS_OUTPUT.put_line (SUBSTR (SQLERRM, 1, 200)); RAISE; END;
_ Output
ALTERing 13 columns in 1 tables ALTER TABLE MY_OBJECTS modify (OWNER VARCHAR2(30 CHAR)) ALTER TABLE MY_OBJECTS modify (OBJECT_NAME VARCHAR2(30 CHAR)) ALTER TABLE MY_OBJECTS modify (SUBOBJECT_NAME VARCHAR2(30 CHAR)) ALTER TABLE MY_OBJECTS modify (OBJECT_ID NUMBER(22)) ALTER TABLE MY_OBJECTS modify (DATA_OBJECT_ID NUMBER(22)) ALTER TABLE MY_OBJECTS modify (OBJECT_TYPE VARCHAR2(19 CHAR)) ALTER TABLE MY_OBJECTS modify (CREATED DATE(7 CHAR)) ALTER TABLE MY_OBJECTS modify (LAST_DDL_TIME DATE(7 CHAR)) ALTER TABLE MY_OBJECTS modify (TIMESTAMP VARCHAR2(19 CHAR)) ALTER TABLE MY_OBJECTS modify (STATUS VARCHAR2(7 CHAR)) ALTER TABLE MY_OBJECTS modify (TEMPORARY VARCHAR2(1 CHAR)) ALTER TABLE MY_OBJECTS modify (GENERATED VARCHAR2(1 CHAR)) ALTER TABLE MY_OBJECTS modify (SECONDARY VARCHAR2(1 CHAR)) Done
Concerning
Published by: OrionNet on January 5, 2009 23:53
Published by: OrionNet on January 5, 2009 23:55
-
Procedure failed with ORA-01403, associated with immediate execution, captured
This procedure compiles without error. Its purpose is to copy the sequence of one schema to another object. After it failed with ORA-01403, I added exception code of capture (see the comments in the code).
A few notes:
1. I started the proceedings with exec copy_sequence ('ADDRESS_SEQ', 'SST', 'TEST1');
2. the first sql string is built correctly since I can see in the console output:
Select last_number in the all_sequences where sequence_owner = upper('TSS') and upper('ADDRESS_SEQ') = sequence_name
I can run this SQL command, and returns a real value;
Here is the procedure
SET SERVEROUTPUT ON;
create or replace procedure copy_sequence (seq VARCHAR2, prod_schema VARCHAR2, VARCHAR2 test_schema)
as
Val number (21);
s_sql varchar2 (200);
Start
s_sql: = ' select last_number in the all_sequences where sequence_owner = upper('''|| prod_schema ||'') ') and sequence_name = upper('''||) Seq | " ')';
-immediate' select last_number in the Vale of all_sequences where sequence_owner = upper('''|| prod_schema ||'') ') and sequence_name = upper('''||) Seq | " ')';
Dbms_output.put_line ('sql 1 ' | s_sql);
execute immediate s_sql in val; ---!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! The code does not work here!
Dbms_output.put_line ('val' |) Val);
s_sql: = 'delete the sequence'. test_schema |'. ' || FF.;
Dbms_output.put_line ('sql 2 ' | s_sql);
-execution immediate s_sql;
s_sql: = 'create the sequence'. test_schema |'. ' || Seq |' minvalue maxvalue 1 999999999999999999999 begin by ' | Val | 'increment of 1';
Dbms_output.put_line ('sql 3 ' | s_sql);
-execution immediate s_sql;
-Add the following after procedure thown ORA-01403: no data found
exception when TOO_MANY_ROWS then DBMS_OUTPUT.put_line ('TOO_MANY_ROWS error');
When NO_DATA_FOUND then DBMS_OUTPUT.put_line ('error NO_DATA_FOUND');
While some other then raise_application_error (-20011, "Unknown Exception in this procedure");
end;
/
Hoek wrote:
The user (no SYSTEM, SYS, and SYSTEM are special, you should not use them unless you have TO) execution of the procedure must have the necessary privileges granted directly, bypassing a role...
??? There is nothing special about SYS or SYSTEM in what concerns them stored procedures. SYS by default is granted directly SELECT ANY SEQUENCE, so it does not work for the owner of MS by SYS. SYSTEM is therefore not:
Scott@pdborcl12 > create sequence s;
Order of creation.
Scott@pdborcl12 > create or replace
2 procedure system.p1
3 is
number of v_last_value 4;
5. start
6. Select last_number
7 in v_last_value
8 of all_sequences
9 where sequence_owner = 'SCOTT '.
10 and s = sequence_name ';
11 end;
12.Created procedure.
Scott@pdborcl12 > system.p1 exec.
BEGIN system.p1; END;*
ERROR on line 1:
ORA-01403: no data found
ORA-06512: at "SYSTEM. "P1", line 5
ORA-06512: at line 1Scott@pdborcl12 > grant select on s to the system;
Grant succeeded.
Scott@pdborcl12 > system.p1 exec.
PL/SQL procedure successfully completed.
SY.
-
Warnings of compilation of a stored procedure in NDS (immediate execution);
CREATE OR REPLACE PROCEDURE P_PRO1 AS
P_VAR VARCHAR2 (1000): =' CREATE OR REPLACE PROCEDURE PROC1 AS
X CONSTANT BOOLEAN: = TRUE;
BEGIN
IF X THEN
DBMS_OUTPUT. PUT_LINE('||)
Q'! 'REAL'!'
*||'); *
ON THE OTHER
DBMS_OUTPUT. PUT_LINE('||)
Q'! 'FALSE'!'
*||'); *
END IF;
END;';
BEGIN
RUN IMMEDIATELY P_VAR;
END;
ALTER SESSION SET PLSQL_WARNINGS = ' ENABLE: ALL ';
Set serveroutput on
EXECUTE P_PRO1; -(No warning messages)
I don't have any compilation warnings by running the above query. In fact, the procedure PROC1, which is compiled by "Execute Immediate" should produce the bcz of warning messages all types of warnings are ENABLED through Alter session, but there are no warnings when running the main proceedings and no log of warnings in the table of user_errors also. Whence the PROC1 warning went?
NDS would only know to run the query given at runtime,
then the PROC1 procedure is compiled at runtime in the main proceedings P_PRO1 will produce warning or not?
If so, den how to check that the warning message?
Thanks for the reply,
Shafir.You create dynimically then you are the person who needs to print the WARNING.
You can do this by querying the table ALL_ERRORS
select * from all_errors where name = 'PROC1' and type = 'PROCEDURE'
-
Hello, I'm on 11.2.0.4, and I'm trying to write a procedure with parameter that runs immediately a DDL.
How can I write this while I'm on the parameter which will always be 0?
SYS@db1 AS SYSDBA > create or replace procedure set_rm_tws (o_status NUMBER)
as
Start
o_status: = 0;
run immediately ' alter system set resource_manager_plan = "DEFAULT_PLAN" scope = "both"' using o_status;
end;
/
Created procedure.
SYS@db1 AS SYSDBA > var o_status number
SYS@db1 AS SYSDBA > exec set_rm_tws(:o_status);
BEGIN set_rm_tws(:o_status); END;
*
ERROR on line 1:
ORA-00922: missing or not valid option
ORA-06512: at "SYS." SET_RM_TWS', line 5
ORA-06512: at line 1
Hello Vili Dialis
You will get all the information of the execution. What you get is simple no and not an exception.
create or replace procedure set_rm_tws (o_status NUMBER)
as
Start
o_status: = 0;
run immediately ' alter system set resource_manager_plan = "DEFAULT_PLAN" scope = "both"' using o_status;
EXCEPTION, THEN THAN OTHERS
THEN o_status: = 1;
END;
/
If you have a problem with running so that you can get the 1 in the variable o_status.
The help of the o_status should be deleted.
I hope it helps.
Best regards, David
-
Appeal procedure in another procedure using the Out parameter slider - lesson
Hello
I am new to Oracle development so first I wonder if it is a good place with a simple way of the of on how to create stored procedures? I'm looking for the most part at this stage for a quick read.
Second, currently have hacked and slashed my way into getting one built. It has 3 parameters and an output parameter sys_refcursor. This procedure works.
I want to have another created procedure that will call the above procedure and loop through each row in the setting out and write to a file. Can someone point me to an example of this by any chance?
Thanks for the help.
Hello
e28d78d3-c6c6-4BCE-b14f-0f6bf26fa17c wrote:
Thanks for the reply.
Here's what I have, but I'm getting many errors. When I seem to fix one that I get a new one. Kind of like what it show me all questions vs one question at a time. I never know if I create another error of my attempts at fixing what, in my view, could be the problem. In any case, something to get used to.
When you do any type of programming, take baby steps. Write less code as possible, test what you wrote ' worm and, if it contains errors, correct them and test again.
The PL/SQL compiler tries to show all errors, but often it is impossible to say what is a separate mistake, and which is a consequence of a previous error. For example, the DECLARE statements in your code are perfectly valid PL/SQL statements, but they are the mistakes in the sense that they are not what you think, and you may not use them. PL/SQL does not know that (I don't really know that, either, but I'm willing to guess in this case). The works of compiler on the explanation that you really wanted to say SAID, until what it becomes obvious, maybe several lines later, that something makes no sense, but at this time, there is no way he could say that the undesirable DECLARE was the cause.
So here is where I am stuck currently. What I want should first, run the stored procedure and I think I do as you suggest. Which returns data in the output parameter, which is of type sys_refcursor. I think I would need to loop through each element that cursor and output to the file using the dbms_output you reference and like I did below. This should be it. Sounds simple enough, but it's where some of the basics for me.
For example, by creating the procedure some examples have the name of the procedure and then some "AS", "IS". When use the beginning and the end and when not I need?
There is no difference betwwen
CREATE PROCEDURE... AS and
CREATE PROCEDURE... Use IS the one you prefer. You must always one or the other, however.
PL/SQL is written in blocks. The basic structure of a block is
DECLARE - optional, sometimes involved
...
BEGIN
...
-Optional EXCEPTION; forget it for now
...
END;
Almost all of the PL/SQL code is part of a block. In fact, you could argue that anything not in a block isn't really PL/SQL. (For example, CREATE PROCEDURE is really an SQL, PL/SQL not, it indicates the SQL that some PL/SQL compiler is coming.)
You should always BEGIN and END keywords in a PL/SQL block; None is never optional.
I think I'm doing the for loop correctly but I get an error on the portion of loop-end. It is a part of these simple things that become I think that.
That's what I have:
CREATE OR REPLACE PROCEDURE APPS.boact_report_3
AS
DECLARE v_cur SYS_REFCURSOR;
DECLARE v_file_out UTL_FILE.file_type;
BEGIN
I said earlier, DECLARED may be implied. It's one of those places if there is nothing after CREATE PROCEDURE... IS and before STARTING, it is supposed to be a statement.
You can have as many statements (0, 1, 2 or more) that you want in this section of the statement. The semicolon at the end of each of them is all the separation you need each other; you don't need any keyword as STATED.
Open the v_cur for
bo_report (p_sv_id, p_start_date, p_end_date, out v_cur); -stored procedure that girls v_cur witch is a sys_refcursor parameter. It works
END;
BEGIN
Don't forget, how to call a procedure is
bo_report (x, y, z);
not
bo_report (x, y, z OUT);
The key words are only necessary (and only used) in the declaration of a procedure, not in his appeal. When you create a procedure, you decide if each argument is going to be an argument IN, an OUT argument, or IN OUT argument, and you tell the compiler that you decide. When you call a procedure, you have no choice; each argument is IN, OUT or IN OUT has already been decided, and suffice to say compiling what are the variables (or expressions) that you use to play these predetermined roles.
Dbms_output.put_line ('Date: ');
v_file_out: =.
UTL_FILE.fopen (' / public/scripts/smorau02 ', 'w_act.csv', 'W');
FOR x IN v_cur
LOOP
() UTL_FILE.put_line
v_file_out,
x.cl_num | ','
|| x.wa_id | ','
|| x.Description | ','
|| x.a_date | ','
|| x.a_by | ','
|| x.v_Name | ','
|| x.SITE_NAME | ','
|| x.stage | ','
|| x.in_queue);
END LOOP;
UTL_FILE.fclose (v_file_out);
END;
Thanks again for the help.
You have not to send the code to bo_report, so I can't run the procedure. I do not notice any obvious mistakes immediately superior.
-
problem with immediate execution
Hi all
I use 10g db.
I wrote a database procedure. When I call front end (forms 6i) I get the error message
and here is my procedureORA-00911: invalid character ORA-06512:at schema.update_tables line 10
What could be gone bad?create or replace procedure update_tables is BEGIN declare lstring varchar(100) := 'update '; lvalue varchar2(10) := 'LVM'; begin for i in (select table_name,column_name from user_tab_columns where column_name like '%_COMPANY') loop lstring := lstring||i.table_name || ' set '||i.column_name || '= ' || chr(39) || lvalue || chr(39) || ' ; ' ; execute immediate lstring; end loop; end; END; /
Thank you...
Published by: GD on May 19, 2012 21:36Is chr (39) a quote on your system?
Did you try my example or something else?
(I've tried before, I posted it).Here is a complete example.
I changed it to my previous post to use a variable binding to remove the tank (39).
It will also help if lvalue contains a quote.create table hutest (my_company varchar2(30)); Table created. insert into hutest values('djhg'); 1 row created. create or replace procedure update_tables is BEGIN declare lstring varchar(100) := 'update '; lvalue varchar2(10) := 'LVM'; begin for i in (select table_name,column_name from user_tab_columns where column_name like '%_COMPANY') loop lstring := lstring||i.table_name || ' set '||i.column_name || '= :val'; dbms_output.put_line(lstring); execute immediate lstring using lvalue; end loop; end; END; / Procedure created. set serveroutput on size 20000 exec update_tables update HUTEST set MY_COMPANY= :val <------ From dbms_output PL/SQL procedure successfully completed. select * from hutest; MY_COMPANY ------------------------------ LVM 1 row selected.
Published by: HU 2012-05-20 08:59
-
Problem in IMMEDIATE EXECUTION
I need to update some columns in a table.
But the columns are dynamic. I can update 1, 20r 3 or more columns of this table.
I tried running with the Execute immediate statement.
But I get the error message (ORA-01747)
: 1(below in code) contains the name of the column with the values. (Example:Column2 = Column2.value, Column3 = Column3.value)
There may be more than 3 or more columns to be updated.
CREATE OR REPLACE PROCEDURE PR_Bulk_CA(pn_SSCA_ID_VARRAY BULK_UPDATE_CA_VARRAY ,pv_set_string Varchar2 ,pn_success OUT number ) Is sql_stmt VARCHAR2(32000); BEGIN sql_stmt:= 'update table_A SET :1 WHERE ID IN (select ID from table_A ca where ca.status in (20700,20710,20720) and ca.id in (select * from table(:2)))'; EXECUTE IMMEDIATE sql_stmt USING pv_set_string,pn_SSCA_ID_VARRAY; COMMIT; pn_success:=0; EXCEPTION WHEN OTHERS THEN pn_success:=-1; END PR_Bulk_CA;
You can't pass the name of the column as a bind variable.
Replace your code (passing only the varray as a bind variable):
sql_stmt:= 'update table_A SET ' || pv_set_string || ' WHERE ID IN (select ID from table_A ca where ca.status in (20700,20710,20720) and ca.id in (select * from table(:1)))';
HTH
Maybe you are looking for
-
Hello, I have slow internet + it's always disconnect every hour, I tried to download a large file (200 MB) but connection always triggered and the cancellation of the queue! D:The Torrent stops download if you lose the connection and resume when you
-
Observer of events - Windows 7 Home edition
When I try to open the event viewer all get ic "MMC could not create a snap." Any help woud be welcome Jim Shepherd
-
SystemPrompt input type do only digital
Hi all I want SystemPrompt keyboard of only digital input field. By default it gives alphanumeric. How do I change this? Please help me. Thank you & best regards Sanjit
-
Without DECOMMISSIONING blackBerry smartphones
Hi all. I just completely updated my BB8310 to the latest version. Is it possible to downgrade my firmware and software than older? If so, how? Where can I find firmware please for Vodafone UK. Thank you
-
Hello My computer was formatted because he cannot join the homegroup. After formatting, I plug the cable that connects to the other computer. Then, I joined the homegroup. But, I clicked on the homegroup to leave and he successfully removed my comput