Raise warning in a PL/SQL procedure
Hi all,
I want to raise warning in a procedure.Is there any built-in procedure like raise_application_error , instead of raising error it must raise a warning.?
Thanx.
I am using Oracle warehouse Builder (OWB).
According to return condition of this procedure another procedure will run.
There are three conditions : ON SUCCESS,ON ERROR,ON WARNING
If I use raise_application_error , the procedure finishes with error.
I want to make the procedure finishes with warning , so ON WARNING condition will be chosen.
Similar Messages
-
How to raise Workflow error from pl/sql procedure
Hi,
I have this OWB mapping that runs a PL/SQL procedure. The mapping is deployed to Workflow and OEM. The workflow is scheduled and run from OEM,
and I can watch its progress/completion in the Workflow Monitor. Occasionally, the PL/SQL hits a situation I want to flag as an error to OWF so
that the OWF standard error process can be activated.
How can I do that? I try to raise an exception from the proc by calling OWF's core API (WF_CORE.RAISE etc.), but nothing happens.
From Workflow monitor no errors are detected, and the workflow seems to complete normally.
Any clues?
Regards
RolfRolf,
I am no workflow expert but it seems to me that you trying to build a workflow exception handler by using the engine APIs (WF_ENGINE). In particular, you could call the WF_ENGINE.ABORT_PROCESS API and set the status to exception. This can be called from an exception handler using the WF_ENGINE.HandleError API.
As far as I know, the WF_CORE API mentioned by you will simply return an exception to the caller, but this will not affect the process flow.
For more details, please take a look at the workflow documentation, in particular if you log into the metalink site (metalink.oracle.com), go to the document http://metalink.oracle.com/cgi-bin/cr/getfile_cr.cgi?282250 which is the user's guide and look under chapter 8 which deals with APIs.
Regards:
Igor -
Creating a CSV file from a pl/sql procedure
Hi Everyone,
I would like to know how to write a procedure in pl/sql where i need to check if they are any records in a table say "Table A".
If they are any records in the "Table A" then we need to write those records in the "Table A" to the CSV file.
If they are no records then we need to insert a record into the CSV file that "No records are found in "Table A".
Could anybody please help ?
Thanks in advancesee this
ops$tkyte@8i> create or replace procedure dump_table_to_csv( p_tname in varchar2,
2 p_dir in varchar2,
3 p_filename in varchar2 )
4 is
5 l_output utl_file.file_type;
6 l_theCursor integer default dbms_sql.open_cursor;
7 l_columnValue varchar2(4000);
8 l_status integer;
9 l_query varchar2(1000)
10 default 'select * from ' || p_tname;
11 l_colCnt number := 0;
12 l_separator varchar2(1);
13 l_descTbl dbms_sql.desc_tab;
14 begin
15 l_output := utl_file.fopen( p_dir, p_filename, 'w' );
16 execute immediate 'alter session set nls_date_format=''dd-mon-yyyy hh24:mi:ss''
17
18 dbms_sql.parse( l_theCursor, l_query, dbms_sql.native );
19 dbms_sql.describe_columns( l_theCursor, l_colCnt, l_descTbl );
20
21 for i in 1 .. l_colCnt loop
22 utl_file.put( l_output, l_separator || '"' || l_descTbl(i).col_name || '"'
23 dbms_sql.define_column( l_theCursor, i, l_columnValue, 4000 );
24 l_separator := ',';
25 end loop;
26 utl_file.new_line( l_output );
27
28 l_status := dbms_sql.execute(l_theCursor);
29
30 while ( dbms_sql.fetch_rows(l_theCursor) > 0 ) loop
31 l_separator := '';
32 for i in 1 .. l_colCnt loop
33 dbms_sql.column_value( l_theCursor, i, l_columnValue );
34 utl_file.put( l_output, l_separator || l_columnValue );
35 l_separator := ',';
36 end loop;
37 utl_file.new_line( l_output );
38 end loop;
39 dbms_sql.close_cursor(l_theCursor);
40 utl_file.fclose( l_output );
41
42 execute immediate 'alter session set nls_date_format=''dd-MON-yy'' ';
43 exception
44 when others then
45 execute immediate 'alter session set nls_date_format=''dd-MON-yy'' ';
46 raise;
47 end;
48 /
Procedure created.
ops$tkyte@8i> exec dump_table_to_csv( 'emp', '/tmp', 'tkyte.emp' );
PL/SQL procedure successfully completed. -
How do I delete cascade with a PL/SQL procedure?
This script will create a PL/SQL procedure that deletes cascade. This is a post to contribute to the Oracle community. Take the code as is and test it before you use it in production. Make sure this is what you want.
Procedure Delete Cascade (prc_delete_cascade)
Description
=============
The principle is very simple. The procedure uses a table called TO_BE_DELETED to keep a list of records to be deleted. This
table keeps the table name and the rowid of those records that need to be deleted. The procedure also uses a function called
DELETE_BOTT_ROW which takes one record of the table and tries to delete it. If the deletion fails with a foreign key constraint
violation, the function parses the SQL error message (SQLERRM) to get the name of the constraint. With the name of the constraint,
the function finds the name of the child table, all the child records that have references to the parent table primary or unique key,
and the parent key primary or unique key column name. Once the child records of the failed delete are identified, the function takes their table name and rowids
and records them into the TO_BE_DELETED table by inserting records of their table name and their rowids. Al the records inserted also contain the level (which
is 1 for the original records, 2 for child records, 3 for granchild records, etc.) and the sequence number of the order in wich they
are recorded. This way, when the function picks up a record to be deleted, it takes the one with the highest level and the highest
inserted sequence, or the "bottom" record. Once all the child records of the failed delete are appended to the TO_BE_DELETED table, it calls itself
recursevely, and the function takes the record at the "bottom" of the table and tries to delete it. If it succeeds, it calls
itself recursevely to delete the next record. If it fails, it goes and finds the child records as described before and once they are
inserted into the TO_BE_DELETED table, it calls itself again recursevely to try to delete again the "bottom" record. All records
that are successfully deleted are flagged as deleted usig the flag_del column so they are not pickt up again. Once all the (parent,
child, grandchild, etc.) records are deleted, the procedure ends without commiting, giving the option to the user to commit or
rollback deletions. The table TO_BE_DELETED is, at the end of the procedure, a list of all the records that were deleted, including their table names
and the order in with they were deleted. The user then can review its content and decide to commit or rollback.
Restrictions
============
1. Single tables only. The procedure only takes one table name and a WHERE clause to identified the records to be deleted.
2. Single columns only. Ther procedure only works with single-column primary, unique and foreign key constraints.
3. Single schema only.
4. Unpredictable results with circular references.
drop table to_be_deleted purge;
create table to_be_deleted
(tname varchar2(30) -- table name
,rid rowid -- rowid
,lvl number -- level: 1=parent, 2=child, 3=grandchild, etc.
,seq_ins number -- sequence order of record inserted
,flg_del char -- flag deleted: Y=record deleted
,seq_del number -- global order of record deletion
set serveroutput on size 1000000
create or replace procedure prc_delete_cascade
(p_tname varchar2 -- table name
,p_where varchar2 -- where clause identifying records to be cascade deleted
is
dummy char;
v_sqlcode number;
v_sqlerrm varchar2(32767);
v_param_val integer := 0;
v_sql varchar2(4000);
v_ret_cde number;
e_bad_params exception;
v_iter number;
v_plvl number;
v_seq_del number;
v_max_iter number := 1000000000;
function delete_bott_row
return number
is
v_sql varchar2(4000);
v_ptname varchar2(30); -- parent table name
v_ppkname varchar2(30); -- parent primary key constraint name
v_ppkcname varchar2(30); -- parnet primary key column name
v_prowid rowid;
v_crowid rowid;
v_ctname varchar2(30); -- child table name
v_cfkname varchar2(30); -- child foreign key constraint name
v_cfkcname varchar2(30); -- child foreign key column name
v_ins number;
v_seq_ins number;
v_sqlerrm varchar2(4000);
v_sqlcode number;
e_const_viol exception;
pragma exception_init(e_const_viol, -2292);
e_max_iter_reached exception;
begin
v_iter := v_iter + 1;
if v_iter >= v_max_iter then
raise e_max_iter_reached;
end if;
dbms_output.put_line('- Iter '||to_char(v_iter));
dbms_output.put_line('----------');
dbms_output.put_line('- Starting function delete_bott_row');
v_sql := 'select tname, rid, lvl, seq_ins from (select * from to_be_deleted where flg_del = ''N'' order by lvl desc, seq_ins desc) where rownum=1';
-- dbms_output.put_line('- SQL: '||v_sql);
execute immediate v_sql into v_ptname, v_prowid, v_plvl, v_seq_ins;
dbms_output.put_line('- Selected row: table name: '||v_ptname||', level: '||v_plvl||', seq: '||v_seq_ins);
v_sql := 'delete from '||v_ptname||' where rowid='''||v_prowid||'''';
dbms_output.put_line('- SQL: '||v_sql);
execute immediate v_sql;
dbms_output.put_line('- Row deleted !!!');
v_ret_cde := 1;
v_seq_del := v_seq_del + 1;
dbms_output.put_line('- Mark the row deleted');
v_sql := 'update to_be_deleted set flg_del = ''Y'', seq_del = '||to_char(v_seq_del)||' where tname='''||v_ptname||''' and rid='''||v_prowid||'''';
-- dbms_output.put_line('- SQL: '||v_sql);
execute immediate v_sql;
-- dbms_output.put_line('- Updated table to_be_deleted, row marked deleted');
-- dbms_output.put_line('- End of iter '||to_char(v_iter));
dbms_output.put_line('----------');
-- call function delete_bott_row recursively
v_ret_cde := delete_bott_row;
return 0;
exception
when no_data_found then
dbms_output.put_line('- Table to_be_deleted is empty, delete cascade has completed successfully.');
v_ret_cde := 0;
return 0;
when e_const_viol then
v_sqlcode := SQLCODE;
v_sqlerrm := SQLERRM;
v_ret_cde := v_sqlcode;
dbms_output.put_line('>Constraint Violation. Record has children');
-- dbms_output.put_line('Error code: '||to_char(v_sqlcode));
v_cfkname := substr(v_sqlerrm,instr(v_sqlerrm,'.')+1,instr(v_sqlerrm,')') - instr(v_sqlerrm,'.')-1);
dbms_output.put_line('>Child FK name: '||v_cfkname);
select table_name, column_name
into v_ctname, v_cfkcname
from user_cons_columns
where constraint_name=v_cfkname;
dbms_output.put_line('>Child table name: '||v_ctname||'. FK column name: '|| v_cfkcname);
select constraint_name, column_name
into v_ppkname, v_ppkcname
from user_cons_columns
where constraint_name = (select r_constraint_name
from user_constraints
where constraint_name=v_cfkname);
dbms_output.put_line('>Parent PK/UK name: '||v_ppkname||'. Parent PK/UK column: '||v_ppkcname);
v_sql := 'insert into to_be_deleted(tname, rid, lvl, seq_ins, flg_del) '||
'select '''||v_ctname||''', rowid, '||to_char(v_plvl+1)||', rownum, ''N'' '||
'from '||v_ctname||' '||
'where '||v_cfkcname||' =any (select '||v_ppkcname||' from '||v_ptname||' where rowid =any (select rid from to_be_deleted where tname = '''||v_ptname||'''))';
-- dbms_output.put_line('- SQL: '||v_sql);
execute immediate v_sql;
select count(*)
into v_ins
from to_be_deleted
where lvl = v_plvl+1
and tname = v_ctname
and flg_del = 'N';
dbms_output.put_line('>Found '||to_char(v_ins)||' child records which were added to table to_be_deleted');
v_ret_cde := delete_bott_row;
return v_ret_cde;
when e_max_iter_reached then
dbms_output.put_line('Maximum iterations reached. Terminating procedure.');
raise;
when others then
raise;
end delete_bott_row;
begin
dbms_output.put_line('Beginning');
dbms_output.put_line('================================');
-- validate p_table
begin
select 'Y'
into dummy
from user_tables
where table_name=upper(p_tname);
exception
when no_data_found then
v_param_val := 1;
dbms_output.put_line('Table '||p_tname||' does not exist.');
raise e_bad_params;
end;
dbms_output.put_line('- Parameter p_tname validated');
-- validate p_where
begin
execute immediate 'select ''Y'' from '||p_tname||' where '||p_where INTO dummy;
exception
when no_data_found then -- where clause returns no records
dbms_output.put_line('Record(s) not found. Check your where clause parameter');
v_param_val := 2;
raise e_bad_params;
when too_many_rows then -- found multiple records means it is ok
null;
when others then -- any other records means where clause has something wrong.
dbms_output.put_line('Where clause is malformed');
v_param_val := 2;
raise e_bad_params;
end;
dbms_output.put_line('- Parameter p_where validated');
if v_param_val > 0 then raise e_bad_params; end if;
v_iter := 0;
v_plvl := 1;
v_seq_del := 0;
v_sql := 'insert into to_be_deleted(tname, rid, lvl, seq_ins, flg_del) select '''||upper(p_tname)||''', rowid, '||to_char(v_plvl)||', rownum, ''N'' from '||p_tname||' where '||p_where;
dbms_output.put_line('- Inserting initial record');
dbms_output.put_line('- SQL: '||v_sql);
execute immediate v_sql;
dbms_output.put_line('- Record(s) inserted');
dbms_output.put_line('- Calling function delete_bott_row to delete last row of table to_be_deleted');
dbms_output.put_line('-----------------------------------');
v_ret_cde := delete_bott_row;
-- dbms_output.put_line('- Back from function delete_bott_row');
-- dbms_output.put_line('Return code: '||to_char(v_ret_cde));
dbms_output.put_line('- End of procedure');
exception
when e_bad_params then
dbms_output.put_line('Bad parameters, exiting.');
end;
show errors
spool prc_delete_cascade.log
-- Call to the procedure
exec prc_delete_cascade('xent','xent_id between 1669 and 1670')
select tname "Table Name", count(*) "Rows deleted"
from to_be_deleted
group by tname;
spool off
set lines 120
select *
from to_be_deleted
order by seq_del;
prompt Now commit or rollaback deletions.
-- commit;
-- rollback;Edited by: Rodolfo4 on Mar 23, 2011 10:45 AMInteresting.
I see a few areas where this could be useful. Elimiating specific test records from a Test DB for example.
Some comments:
<li>Since this is a recursive logic you must add a stop criteria. In this case I would add a max iteration variable. If that one is reached, raise an error message and let the procedure stop with that error.</li>
<li>The when others exception at the end should be removed completely</li>
<li>The when others exception in the middle should be replaced by a specific exception that handles the -2292 error</li>
<li>A list of tables where no record should be deleted could be usefull. If the logic would encounter such a table, it should also stop. This would be to prevent that data from some system critical tables could be deleted per accident.</li>
<li>The reference from the FK constraint to the PK constraint should include the table name and if possible the owner (as long as you use user_* views the owner is always the same. But we could extend this to the ALL_* views). I never met a system where different tables have the identical FK constraint names, however just make this fool proof.</li> -
How to make pl/sql procedure not auto-commit?
I wish to be able to execute a create statement, and then rollback if there is a problem with any sql that follows. It seems that you cannot rollback? Why is this?
(My problem is that I wish to execute a series of sql statements and run a rollback if anything before it fails, including the creation of the table)
set serveroutput on;
declare
rcount INTEGER;
PRAGMA AUTONOMOUS_TRANSACTION;
begin
execute immediate 'create table bsdconv_s1stc_code (id number)';
dbms_output.put_line('Table created successfully');
rollback;
exception
when others then dbms_output.put_line('Error while creating table. Probably already exists.');
end;Ni hao, Dong Yage!
I think using procedure and handling on call you might be able to do it.
SQL> create table test (i int);
Table created.
SQL> insert into test values (1);
1 row created.
SQL> select * from test;
I
1
SQL> set serveroutput on;
SQL> declare
2 rcount INTEGER;
3 PRAGMA AUTONOMOUS_TRANSACTION;
4 begin
5 execute immediate 'create table bsdconv_s1stc_code (id number)';
6 dbms_output.put_line('Table created successfully');
7 -- rollback;
8 exception
9 when others then
10 dbms_output.put_line('Error while creating table. Probably already exists.');
11 rollback;
12 end;
13 /
Table created successfully
PL/SQL procedure successfully completed.
SQL> desc bsdconv_s1stc_code
Name Null? Type
ID NUMBER
SQL> select * from test;
I
1
SQL> insert into test values (2);
1 row created.
SQL> set serveroutput on;
SQL> declare
2 rcount INTEGER;
3 PRAGMA AUTONOMOUS_TRANSACTION;
4 begin
5 execute immediate 'create table bsdconv_s1stc_code (id number)';
6 dbms_output.put_line('Table created successfully');
7 -- rollback;
8 exception
9 when others then
10 dbms_output.put_line('Error while creating table. Probably already exists.');
11 rollback;
12 execute immediate 'drop table bsdconv_s1stc_code';
13 end;
14 /
Error while creating table. Probably already exists.
PL/SQL procedure successfully completed.
SQL> select * from test;
I
1
2
SQL> rollback;
Rollback complete.
SQL> select * from test;
no rows selected
SQL> desc bsdconv_s1stc_code;
ERROR:
ORA-04043: object bsdconv_s1stc_code does not exist
On executing PL/SQL block secondly,
it raises exception, displays error messages and drops table
but main transaction is not rolled back.
This is because rollback belongs to only inseide of
AUTONOMOUS_TRANSACTION PL/SQL block.
Now, let us try using procedure.
SQL> grant create table to ushi;
SQL> create or replace
2 procedure create_table
3 is
4 PRAGMA AUTONOMOUS_TRANSACTION;
5 begin
6 execute immediate 'create table bsdconv_s1stc_code (id number)';
7 dbms_output.put_line('Table created successfully');
8 exception
9 when others then
10 dbms_output.put_line('Error while creating table. Probably already exists.');
11 execute immediate 'drop table bsdconv_s1stc_code';
12 raise;
13 end;
14 /
Procedure created.
SQL> select * from test;
no rows selected
SQL> begin
2 insert into test values (1);
3 create_table;
4 exception
5 when others then
6 dbms_output.put_line('Error on Creating table or Transaction');
7 rollback;
8 end;
9 /
Table created successfully
PL/SQL procedure successfully completed.
SQL> select * from test;
I
1
SQL> commit;
Commit complete.
SQL> desc bsdconv_s1stc_code
Name Null? Type
ID NUMBER
SQL> begin
2 insert into test values (2);
3 create_table;
4 exception
5 when others then
6 dbms_output.put_line('Error on Creating table or Transaction');
7 rollback;
8 end;
9 /
Error while creating table. Probably already exists.
Error on Creating table or Transaction
PL/SQL procedure successfully completed.
SQL> select * from test;
I
1
SQL> desc bsdconv_s1stc_code
ERROR:
ORA-04043: object bsdconv_s1stc_code does not exist -
Deploy warnings using a PL/SQL procedure (from a Public Transform Package)
OWB Version: 10.2
I am receiving the following warnings when I attempt to deploy a map that contains a reference to a custom pl/sql procedure that is setup in a public transformation package:
Warning
ORA-06550: line 115, column 32:
PLS-00112: end-of-line in quoted identifier
ORA-06550: line 115, column 9:
PLS-00103: Encountered the symbol "." when expecting one of the following:
:= . ( @ % ; not null range default character
I reviewed the OWB generated code and I discovered the OWB is a adding two double quotes in front of any reference to the package name. For example.....
BEGIN
COMMIT;
sql_stmt := 'ALTER SESSION DISABLE PARALLEL DML';
EXECUTE IMMEDIATE sql_stmt;
IF NOT ""ZZTEST"."INIT_SF_USER_CLAS_St" THEN
* note the "" in front of ZZTEST, which is the package name.
Has anyone else encountered this issue? I can manually correct the generated the code, but it would be overridden every the time the map is deployed. I encounter the same issue if I import a custom pl/sql procedure from the database into OWB using the Metadata Import Wizard and use the imported procedure in a map. However, I can setup an standalone procedure or function as a public transformation and the map deploys successfully. Please advise.
Regards,
MattYou have to create a job to start your procedure.
Example :
* http://psoug.org/reference/OLD/dbms_job.html
Then create a procedure to start your job, call it from your dashboard and you're done.
Success
Nico -
XML Data from PL/SQL procedure -- special character issue (eBS)
Hi All,
I am developing a report, where the XML data is created by a PL/SQL procedure. I chose this approach over a data template, since there is a lot of processing involved in producing the actual data, and it cannot be done by select-statements alone. The report is run as a regular concurrent request.
So far so good. There is a problem though. Every time the data contains special characters (ä, ö, umlauts), the concurrent request is completed with a warning, the log confirms that "One or more post-processing actions failed.", also there is no output file. The XML structure is valid as such. The report runs smoothly and produces the output when the XML data does not contain special characters.
I am producing the XML lines by using the standard FND_FILE.PUT_LINE procedure: Fnd_File.put_line(Fnd_File.output, '<?xml version="1.0" encoding="UTF-8"?>'); This seems like a character encoding issue, but declaring the UTF-8 encoding in this way does not solve the problem.
Any ideas what can be done to fix this? I have been searching Metalink but cannot find an answer. Many thanks for your kind help.
Best Regards, MatildaHi Rajesh,
One idea I have, is that it might be possible to modify the PL/SQL code into a "before report" type trigger, attached to a data template. The code would process the data and write the lines into a temporary table, from which the data template could retrieve them in a simple select-query. However, it would be neat to be able to solve this without adding an extra layer of processing, since BI Publisher supposedly supports PL/SQL procedures as the data source.
The data in this case is all correct, special characters are an intrinsic feature of the Finnish language. :)
Best Regards, Matilda -
Create table statement in a pl/sql procedure
Hi all.
I have a problem in Oracle 10g.
First of all I must say that I'm new in oracle 10.
I have a stored procedure in which I have the instruction "create table name_table as
select col1,col2,col3,..ecc
from table1, table2
where table1.col1 = table2.col2"
When I compile this procedure it gives me an error.
Is it changed the sintax????
Is there anyone that can help me???
Thanks all for the collaboration,
FabrizioA little mistake -- see it --
SQL> ed
Wrote file afiedt.buf
1 Create or replace procedure My_procedure as
2 begin
3 EXECUTE IMMEDIATE 'create table my_table(fld number(5));'
4* end;
SQL> /
Warning: Procedure created with compilation errors.
SQL>
SQL>
SQL> ed
Wrote file afiedt.buf
1 Create or replace procedure My_procedure as
2 str varchar2(200);
3 begin
4 str := 'create table my_table(fld number(5))';
5 EXECUTE IMMEDIATE(str);
6* end;
SQL> /
Procedure created.
SQL>
SQL>
SQL> Create or replace procedure My_procedure as
2 begin
3 EXECUTE IMMEDIATE 'create table my_table(fld number(5));'
4 end;
5 /
Warning: Procedure created with compilation errors.
SQL> ed
Wrote file afiedt.buf
1 Create or replace procedure My_procedure as
2 begin
3 EXECUTE IMMEDIATE 'create table my_table(fld number(5))';
4* end;
SQL> /
Procedure created.Regards.
Satyaki De.
N.B.: Please check the bolded line. You didn't write the ; outside the quotation. Otherwise, it will compile successfully. -
Thread safe operations on table in pl/sql procedure?
I am developing java application which will be running in N localizations simultaneously, each application will have M threads. Every thread takes an unique ID with status NOT_TAKEN from table Queue and changes its status to TAKEN.
Problem:
How to prevent thread from situation like this:
1. Thread A select first ID with status NOT_TAKEN
2. In the same time thread B select first (so it will be the same ID which selected thread A) ID with status NOT_TAKEN.
3. Thread A changes status of ID to TAKEN
4. Thread B changes status of ID to TAKEN
After this operation thread A and B are using the same ID.
What I did:
I have written pl/sql procedure which lock table Queue in exclusive mode, selects first ID, changes its status to TAKEN and unlocks the table. Because it is lock in exclusive mode so only one thread can run this procedure simultaneously.
Question:
How optimally should it be solved, because mine solution prevents from doing all other Updates on Queue table while it is locked, like changing status from TAKEN to OPERATION_DONE so it has performance issue.As Centinul has said, you need to lock just one row.
I would just add NOWAIT to the select statement to let the Java thread go and try again, instead of waiting for the other threads.
Example: (not tested)
-- Assuming structure of your QueueTable: ( IDCol is PK , StatusCol is VARCHAR2, ... )
-- or make it part of the package....
CREATE OF REPLACE
FUNCTION updateQueue( nQID QueueTable.IDCol%TYPE) RETURN VARCHAR2 AS
eLocked EXCEPTION;
PRAGMA EXCEPTION_INIT(eLocked,-54);
CURSOR curQueueTable IS SELECT 1 CNTR FROM QueueTable WHERE IDCol=nQID AND StatusCol='NOT_TAKEN' FOR UPDATE OF StatusCol NOWAIT;
recQueueTable curQueueTable%ROWTYPE;
cRtn VARCHAR2(1);
BEGIN
cRtn := 'Y';
BEGIN
OPEN curQueueTable;
FETCH curBuffSummary INTO recQueueTable;
CLOSE curQueueTable;
IF recQueueTable.CNTR IS NOT NULL AND recQueueTable.CNTR = 1 THEN
UPDATE QueueTable SET StatusCol = 'TAKEN' WHERE IDCol=nQID;
ELSE
-- Already updated
cRtn := 'N';
END IF;
-- You can control your transaction here as well
-- COMMIT;
-- But if realy should be done in the Java thread.
EXCEPTION
WHEN eLocked OR STANDARD.TIMEOUT_ON_RESOURCE THEN
-- Thread could not get exclusice row lock. Ignore error.
cRtn := 'N';
NULL;
WHEN OTHERS THEN
-- Handle other errors...
-- NULL; just kidding...
RAISE;
END;
RETURN cRtn;
END; Edited by: thomaso on Sep 18, 2009 10:30 AM -
TTClasses interface for PL/SQL procedure and fetching its results
Hi experts,
I am using TimesTen Release 11.2.1.3.0;
I created a simple PL/SQL procedure as follows in timesten-
Command> create or replace procedure employee(eno in emp.empno%type) is
> e_name emp.ename%type;
> begin
> select ename into e_name from emp where emp.empno = eno;
> dbms_output.put_line(e_name);
> end;
> /
And then I call it through TTClasses as
TTCmd cmd, compilecmd;
compilecmd.Prepare(conn,"alter procedure employee compile;",status);
cmd.Prepare(conn,"begin employee(1020); end;",status);
cmd.Execute(..);
cmd.FetchNext(..);
Here fetchNext is returning an error -
[TimesTen][TimesTen 11.2.1.3.0 ODBC Driver]Invalid cursor state
*** ODBC Error/Warning = 24000, TimesTen Error/Warning = 0
*** Unable to fetch row for statement: <begin employee(1020); end;>.terminate called after throwing an instance of 'TTError'
Aborted
How can I run PL/SQL procedures/functions on TimesTen through TTClasses interface?
Any help or input would be of great value.
ThanksThe issue here is nothing to do with TTClasses. Your PL/SQL procedure executes a SELECT statement (that returns just one row) using an implicit cursor within the PL/SQL procedure and retrieves the value of the ename column into the PL/SQL variable. However it does not them do anything with that value such as pass it back to the caller...
Similarly, the TTClasses code executes a statement that it is expecting to create an ODBC level cursor 9which thsi PL/SQL invocation will not of course) and it is then trying to fetch from a cursor that does not exist.
I would recommend that you take a look at the TimesTen PL/SQL documentation (Oracle® TimesTen In-Memory Database PL/SQL Developer's Guide Release 11.2.1) and refer to the section on IN, OUT and IN/OUT parameters. This will show you how you can use OUT parameters to return values to the caller. This technique works fine for ODBC, JDBC and OCi programs but does not sadly currently work with TTClasses. TTClasses has not yet been enhanced to support OUT and INOUT parameters. Of course as you have the source code for TTClasses you could make the necessary modifications yourself.
I will open a bug requesting that TTClasses support OUT and INOUT parameters but in the meantime if you need this kind of capability you will need to either modify TTClasses yourself or switch to using a different API.
Chris -
DB Adapter calling PL/SQL Procedure gives error
Created partner link, calling pl/sql procedure with one in variable and one out variable. Invoke works fine. Assigning pl/sql return value to output is causing run time error. "Rebuild" and "Deploy" works file.
Here is the error:
Assign_2
[2007/08/03 14:18:06]
Error in evaluate <from> expression at line "93". The result is empty for the XPath expression : "/ns3:OutputParameters/ns3:OUT_STATUS_CODE".
oracle.xml.parser.v2.XMLElement@ba1893
Copy details to clipboard
[2007/08/03 14:18:06]
"{http://schemas.xmlsoap.org/ws/2003/03/business-process/}selectionFailure" has been thrown.
- <selectionFailure xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
- <part name="summary">
<summary>
empty variable/expression result.
xpath variable/expression expression "/ns3:OutputParameters/ns3:OUT_STATUS_CODE" is empty at line 93, when attempting reading/copying it.
Please make sure the variable/expression result "/ns3:OutputParameters/ns3:OUT_STATUS_CODE" is not empty.
</summary>
</part>
</selectionFailure>
Any input would be appreciated..
Thanks.Thanks, it works.
In the “Assign Variables”
Changed from:
<copy>
<from variable="Invoke_1_ASNDBTest103_OutputVariable"
part="OutputParameters" query="/ns3:OutputParameters/ns3:OUT_STATUS_CODE"/>
<to variable="outputVariable" part="payload"
query="/ns2:ASNReturnStatus102"/>
</copy>
Changed to:
<copy>
<from variable="Invoke_1_ASNDBTest103_OutputVariable"
part="OutputParameters" query="/ns3:OutputParameters"/>
<to variable="outputVariable" part="payload"
query="/ns2:ASNReturnStatus102"/>
</copy>
So far so good, but one question, compiler gives warning…but everything works well.
Warning(97):
[Error ORABPEL-10041]: Trying to assign incompatible types
[Description]: in line 97 of "C:\HOME\jdevOAExt3\jdevhome\jdev\mywork\ASNTest101\BPELProcess1\bpel\BPELProcess1.bpel", <from> value type "{http://xmlns.oracle.com/pcbpel/adapter/db/APPS/XRX_BPEL_INSERT_ASN_TMP102/}OutputParameters anonymous type" is not compatible with <to> value type "{http://www.thiscompany.com/ns/sales}ASNReturnStatus102".
[Potential fix]: Please make sure that the return value of from-spec query is compatible with the to-spec query.
Also, instead of direct variable to variable copy, used expression to variable copy and it works. You can avoid the warning from the compiler.
Does not work ==> bpws:getVariableData('Invoke_1_ASNDBTest103_OutputVariable','payload','/ns3:OutputParameters/ns3:OUT_STATUS_CODE')
Works ==> bpws:getVariableData('Invoke_1_ASNDBTest103_OutputVariable','payload','/ns3:OutputParameters’)
So, why the compiler warning? -
Linking PL\SQL procedure as Concurrent Process
Hi.
I'm link PL-proc as concurrent process, and it runs without any
errors.
Now I need also run it as standart report, but can't generate
output file to store any words to.
help.
mailto: [email protected]Thanks for your response.
I am writing a BPEL PM process for inserting AP Invoices by inserting data into the interface tables, and then executing the corresponding concurrent program (APXIIMPT). I would like to trap any errors and send them back to the BPEL process.
One suggestion on how to do this is to write a pl/sql procedure which inserts the data, executes the concurrent program, collects any error messages, and passes them back via OUT parameters. Such a procedure could be called using an adapter from BPEL PM.
So the issue for this forum is how to make the single pl/sql procedure wait for completion of the concurrent process.
Alternatively, is there a business event raised when the concurrent process completes? -
Unable to capture the parameter values from a PL/SQL procedure
hi.
i'm trying to capture the parameter values of a PL/SQL procedure by calling inside a anonymous block but i'm getting a "reference to uninitialized collection error" ORA-06531.
Please help me regarding.
i'm using following block for calling the procedure.
declare
err_cd varchar2(1000);
err_txt VARCHAR2(5000);
no_of_recs number;
out_sign_tab search_sign_tab_type:=search_sign_tab_type(search_sign_type(NULL,NULL,NULL,NULL,NULL));
cntr_var number:=0;
begin
rt843pq('DWS','3000552485',out_sign_tab,no_of_recs,err_cd,err_txt);
dbms_output.put_line('The error is ' ||err_cd);
dbms_output.put_line('The error is ' ||err_txt);
dbms_output.put_line('The cntr is ' ||cntr_var);
for incr in 1 .. OUT_SIGN_TAB.count
loop
cntr_var := cntr_var + 1 ;
Dbms_output.put_line(OUT_SIGN_TAB(incr).ref_no||','||OUT_SIGN_TAB(incr).ciref_no||','||OUT_SIGN_TAB(incr).ac_no||','||OUT_SIGN_TAB(incr).txn_type||','||OUT_SIGN_TAB(incr).objid);
end loop;
end;
Error is thrown on "for incr in 1 .. OUT_SIGN_TAB.count" this line
Following is some related information.
the 3rd parameter of the procedure is a out parameter. it is a type of a PL/SQL table (SEARCH_SIGN_TAB_TYPE) which is available in database as follows.
TYPE "SEARCH_SIGN_TAB_TYPE" IS TABLE OF SEARCH_SIGN_TYPE
TYPE "SEARCH_SIGN_TYPE" AS OBJECT
(ref_no VARCHAR2(22),
ciref_no VARCHAR2(352),
ac_no VARCHAR2(22),
txn_type VARCHAR2(301),
objid VARCHAR2(1024))............We don't have your rt843pq procedure, but when commenting that line out, everything works:
SQL> create TYPE "SEARCH_SIGN_TYPE" AS OBJECT
2 (ref_no VARCHAR2(22),
3 ciref_no VARCHAR2(352),
4 ac_no VARCHAR2(22),
5 txn_type VARCHAR2(301),
6 objid VARCHAR2(1024))
7 /
Type is aangemaakt.
SQL> create type "SEARCH_SIGN_TAB_TYPE" IS TABLE OF SEARCH_SIGN_TYPE
2 /
Type is aangemaakt.
SQL> declare
2 err_cd varchar2(1000);
3 err_txt VARCHAR2(5000);
4 no_of_recs number;
5 out_sign_tab search_sign_tab_type:=search_sign_tab_type(search_sign_type(NULL,NULL,NULL,NULL,NULL));
6 cntr_var number:=0;
7 begin
8 -- rt843pq('DWS','3000552485',out_sign_tab,no_of_recs,err_cd,err_txt);
9 dbms_output.put_line('The error is ' ||err_cd);
10 dbms_output.put_line('The error is ' ||err_txt);
11 dbms_output.put_line('The cntr is ' ||cntr_var);
12 for incr in 1 .. OUT_SIGN_TAB.count
13 loop
14 cntr_var := cntr_var + 1 ;
15 Dbms_output.put_line(OUT_SIGN_TAB(incr).ref_no||','||OUT_SIGN_TAB(incr).ciref_no||','||OUT_SIGN_TAB(incr).ac_no||','||OUT_SIGN
TAB(incr).txntype||','||OUT_SIGN_TAB(incr).objid);
16 end loop;
17 end;
18 /
The error is
The error is
The cntr is 0
PL/SQL-procedure is geslaagd.Regards,
Rob. -
How to call a PL/SQL procedure from a Java class?
Hi,
I am new to the E-BusinessSuite and I want to develop a Portal with Java Portlets which display and write data from some E-Business databases (e.g. Customer Relationship Management or Human Resource). These data have been defined in the TCA (Trading Community Architecture) data model. I can access this data with PL/SQL API's. The next problem is how to get the data in the Java class. So, how do you call a PL/SQL procedure from a Java program?
Can anyone let me know how to solve that problem?
Thanks in advance,
Chang Si ChouHave a look at this example:
final ApplicationModule am = panelBinding.getApplicationModule();
try
final CallableStatement stmt = ((DBTransaction)am.getTransaction()).
createCallableStatement("{? = call some_pck.some_function(?, ?)}", 10);
stmt.registerOutParameter(1, OracleTypes.VARCHAR);
stmt.setInt(2, ((oracle.jbo.domain.Number)key.getAttribute(0)).intValue());
stmt.setString(3, "Test");
stmt.execute();
stmt.close();
return stmt.getString(1);
catch (Exception ex)
panelBinding.reportException(ex);
return null;
}Hope This Helps -
How to call a PL/SQL procedure from a xml Data Template
We have a requirement in which we need to call a pl/sql package.(dot)procedure from a Data Template of XML Publisher.
we have registered a Data Template & a RTF Template in the XML Publisher Responsibility in the Oracle 11.5.10 instance(Front End).
In the Data Query part of the Data Template , we have to get the data from a Custom View.
This view needs to be populated by a PL/SQL procedure.And this procedure needs to be called from this Data Template only.
Can anybody suggest the solution.
Thanks,
SachinCall the procecure in the After Parameter Form trigger, which can be scripted in the Data Template.
BTW, there is a specialized XML Publisher forum:
BI Publisher
Maybe you are looking for
-
In Address Book how can I stop the cursor from wandering while editing a page?
At times when I am editing a page in Address Book, the cursor wanders, so the text I am typing shows up in the wrong place. Often it deletes exist text. Why does this happen? How can I prevent it?
-
Package Error! join to tables in different schemas
Hi I get an error whwn I want to put my query into package I have two tables in different schemas and I joined them and it works when I compile it but in the SP it doesn't works Is anbody help me? please Table1 in Schema1 Table2 in Schema2 TableID is
-
Hello We made an debitor invoice with 647 lines, but SAP didn't made an account document this time: The accounting document has not yet been created - VF062. Can anyone help us? Regards Lone
-
Title says it all. I've had this issue on this machine for some time but not forever. Music playback is fine but anything video related freezes the program. When I launch the program in safe mode it works though. Clearly some add-on or file is causin
-
Why does my email sent box show I have 104 sent emails whilst in fact it is empty?