PL/SQL procedure to delete
this has been solved
Edited by: user13133295 on Oct 11, 2010 12:11 PM
Hello,
>> How would I write my delete process if I don't loop through APEX_application.g_f0x?
This is the whole point of the new Tabular Form logic – more declarative options. You are telling the APEX engine what you want to do – in your case, go through *"All Submitted Rows"* - and the APEX engine will take care of the details. No more G_Fxx arrays, and matching each array to its corresponding column, but using bind variable notation, with the name of the column.
In your specific case, just write the delete statement as if you are dealing with a single row. The APEX engine will apply this statement to all the relevant rows. It also means that your where clause should include only conditions that pertains to the application logic, and not to the Tabular Form itself.
>> By condition I am presuming you refering to the condition of the Process wher you set Item/Column is not null and pick APEX$ROW_SELECTOR instead of using it in the PL/SQL where clause like it did?
Yes. In your specific case, there is indeed a pre-defined condition that deals with NULL values. In other cases, you can use the PL/SQL option to define any condition you need.
Two general comments:
- The APEX engine takes care of all the necessary commit operations. In most cases (including this one) you don’t need to do it yourself.
- There is a field called Process Success Message. It is better to use this field than directly manipulating the apex_application.g_print_success_message variable.
Regards,
Arie.
♦ Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
♦ Author of Oracle Application Express 3.2 – The Essentials and More
Similar Messages
-
PL/SQL procedure for deleting rows
We have to delete rows from a table by initiating parallel processes depending on no of connections, and also variable commit frequency. The procedure has to start by itself in case of failure of 1 or more parallel processes, by identifying the position where it stopped. Please some one help me what would be th elogic needed to write the [rocedure.
Thanks in Advance
Edited by: 864979 on Jun 9, 2011 10:02 PMBe careful of how this is designed and coded. It is very easy to do it horribly wrong, causing contention and problems.
Have a look at DBMS_PARALLE_EXECUTE.
If the package is not available on your Oracle version, then look at {message:id=1534900} for a manual approach. -
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> -
Call PL/SQL procedure from htmldb_delete_message Javascript
Hi Guys,
I am a bit of a novice when it come to JavaScript; I have written a PL/SQL procedure that deletes multiple records based on a primary key:
PROCEDURE clear_alterations (p_eco IN VARCHAR2)
IS
BEGIN
DELETE FROM xxmel_apex_eco_alterations
WHERE eco = p_eco;
END clear_alterations;
I can run that straight from a normal button, but I want the htmldb_delete_message dialog box to pop up to confirm whether to delete or not. When the user clicks 'OK' I want the record to be deleted and if cancel, do nothing.
I have managed to get the confirmation box to appear but cant see how to call the PLSQL based on the 'OK' button being pressed.
Any help would be great,
Thanks
ChrisHi Cashy,
By using Ajax you can call that process. Create that process as a application process. If you are using ApEx4.0 you can create that process as page level.
This stuff you can call on the population of the delete message...check for the id through javascript then call the function.
Thanks and Regards
Maheswara -
URL Syntax for PL/SQL procedure
I am trying to call a PL/SQL procedure to delete a file attachment (from How To). I have modified the procedure to accept three other arguments (app, page, session). My delete-column link is:
#OWNER#.delete_my_file?p_file=#ID#,p_app=&APP_ID.,p_page=&APP_PAGE_ID.,&SESSION.
My procedure source is:
PROCEDURE DELETE_MY_FILE(p_file in number,p_app in number,p_page in number,
p_session in number) as
varLocation varchar(100);
BEGIN
DELETE FROM hr.file_subjects f
WHERE f.id = p_file;
--print the redirect back to the web browser, return to paqe
varLocation := '<script>window.location="f?p='||p_app||':'||
p_page||':'||p_session||'";</script>';
htp.p(varLocation);
END delete_my_file;
I assume that I can call a PL/SQL function or SPROC with multiple arguments, do I simply have the URL wrong?
I get the "...URL not found on server..." error.I already granted execute to public. I can run this SPROC from SQL*Plus with no issues. I was simply trying to expand upon the How TO example and pass multiple args to a SPROC that is called from a query region column link. If I put it at the page level process, then I have to use checkboxes (or something else) to indicate which files I want to delete and then call a page submit.
Is it not possible to call a PL/SQL SPROC with multiple args from a web link in HTMLDB? -
Execute CDC mappings from a PL/SQL procedure
Hi,
I´m using OWB 11.2.0.2 for Linux. I´ve created some CDC mappings to update cubes with changes coming from other tables and cubes (from the tables that implement those cubes with the relational option). The issues are:
- The CDC mappings run successfully from the OWB (Project Navigator - Start), but I cannot execute them from a procedure in PL/SQL with the following code:
PROCEDURE "PROC_RUNCDCMAPPINGS" IS
--inicializar variables aquí
RetVal NUMBER;
P_ENV WB_RT_MAPAUDIT.WB_RT_NAME_VALUES;
-- ventana principal
BEGIN
RetVal:= BARIK.CDC_LOAD_CUBO_RECARGA.MAIN(P_ENV);
RetVal:= BARIK.CDC_LOAD_CUBO_TOR.MAIN(P_ENV);
RetVal:= BARIK.CDC_LOAD_CUBO_TOAE.MAIN(P_ENV);
RetVal:= BARIK.CDC_LOAD_CUBO_VIAJES.MAIN(P_ENV);
RetVal:= BARIK.CDC_LOAD_CUBO_TICKETINCIDENCIA.MAIN(P_ENV);
RetVal:= BARIK.CDC_LOAD_CUBO_LIQMONEDERO.MAIN(P_ENV);
RetVal:= BARIK.CDC_LOAD_CUBOS_LIQTEMPORALES.MAIN(P_ENV);
COMMIT;
END;
It doesn´t report any error (the value for RetVal after execution is 0), but the cubes are not loaded with changes, and the changes stored in the J$_%tables are not consumed.
Some of the options that may impact in the mappings are:
- All the CDC are of Simple type
- There are more than one subscriber to consume the changes, as for some tables, its changes must feed more than one CDC.
- All the mappings include only one execution unit per mapping.
- The integration/load template is the default: DEFAULT_ORACLE_TARGET_CT
Other question is: As I explained, I need more than one subscriber because same updates must be consumed by different CDC mappings, to load different cubes, but I´ve not been able to assign the subscribers to only the tables associated with them, so all the subscribers are subscribed to all the changes in all the CDC tables, but as many of those subscribers never consume the changes of same tables, in the J$_% tables remains the not consumed records, and I haven´t found the way to purge those tables (other than the delete from J$_), nor to assign the tables with the subscribers (so the subscribers are only subscribed to their interested changes, that will be consumed, so the tables will be emptied after the consumption).
Any help with these problems will be greatly appreciated.
Tell me if more info is needed to clarify the situation.
Best regards,
AnaHi David,
Thank you for your reply.
These mappings are the mappings needed to update the cubes with the changes detected by the CDC system, they are located under the Mapping Templates folder and I´m using code templates for the control of the loading and the integration (the DEFAULT_ORACLE_TARGET_CT) mapping.
What I need is to execute these mappings within a PL/SQL procedure that will be invoked from different tools.
I´ve done it for regular mappings (not CDC mappings), and it works. The code is the same as for the CDC ones:
PROCEDURE "PROC_RUNLOADMAPPINGS" IS
--inicializar variables aquí
RetVal NUMBER;
P_ENV WB_RT_MAPAUDIT.WB_RT_NAME_VALUES;
-- ventana principal
BEGIN
RetVal:= BARIK.LOAD_CUBO_RECARGA.MAIN(P_ENV);
RetVal:= BARIK.LOAD_CUBO_TOR.MAIN(P_ENV);
RetVal:= BARIK.LOAD_CUBO_TOAE.MAIN(P_ENV);
RetVal:= BARIK.LOAD_CUBO_VIAJES.MAIN(P_ENV);
RetVal:= BARIK.LOAD_CUBO_TICKETINCIDENCIA.MAIN(P_ENV);
COMMIT;
END;
-- End of PROC_RUNLOADMAPPINGS;
,and when I run it, the mappings are executed, but with the CDC ones it doesn´t (even when no error is reported).
I know that they are deployed in the selected agent (in my case the Default_Agent), but when I start them from the OWB, the mapping packages are created in the DB schema, so, I thought that maybe I could invoke them....so what you tell me is that the only way to invoke them is from SQL*Plus? not from a regular PL/SQL procedure?
Thank you very much,
Ana -
PL/SQL procedure is 10x slower when running from weblogic
Hi everyone,
we've developed a PL/SQL procedure performing reporting - the original solution was written in Java but due to performance problems we've decided to switch this particular piece to PL/SQL. Everything works fine as long as we execute the procedure from SQL Developer - the batch processing 20000 items finishes in about 80 seconds, which is a serious improvement compared to the previous solution.
But once we call the very same procedure (on exactly the same data) from weblogic, the performance seriously drops - instead of 80 seconds it suddenly runs for about 23 minutes, which is 10x slower. And we don't know why this happens :-(
We've profiled the procedure (in both environments) using DBMS_PROFILER, and we've found that if the procedure is executed from Weblogic, one of the SQL statements runs noticeably slower and consumes about 800 seconds (90% of the total run time) instead of 0.9 second (2% of the total run time), but we're not sure why - in both cases this query is executed 32742-times, giving 24ms vs. 0.03ms in average.
The SQL is
SELECT personId INTO v_personId FROM (
SELECT personId FROM PersonRelations
WHERE extPersonId LIKE v_person_prefix || '%'
) WHERE rownum = 1;Basically it returns an ID of the person according to some external ID (or the prefix of the ID). I do understand why this query might be a performance problem (LIKE operator etc.), but I don't understand why this runs quite fast when executed from SQL Developer and 10x slower when executed from Weblogic (exactly the same data, etc.).
Ve're using Oracle 10gR2 with Weblogic 10, running on a separate machine - there are no other intensive tasks, so there's nothing that could interfere with the oracle process. According to the 'top' command, the wait time is below 0.5%, so there should be no serious I/O problems. We've even checked JDBC connection pool settings in Weblogic, but I doubt this issue is related to JDBC (and everything looks fine anyway). The statistics are fresh and the results are quite consistent.
Edited by: user6510516 on 17.7.2009 13:46The setup is quite simple - the database is running on a dedicated database server (development only). Generally there are no 'intensive' tasks running on this machine, especially not when the procedure I'm talking about was executed. The application server (weblogic 10) is running on different machine so it does not interfere with the database (in this case it was my own workstation).
No, the procedure is not called 20000x - we have a table with batch of records we need to process, with a given flag (say processed=0). The procedure reads them using a cursor and processes the records one-by-one. By 'processing' I mean computing some sums, updating other table, etc. and finally switching the record to processed=1. I.e. the procedure looks like this:
CREATE PROCEDURE process_records IS
v_record records_to_process%ROWTYPE;
BEGIN
OPEN records_to_process;
LOOP
FETCH records_to_process INTO v_record;
EXIT WHEN records_to_process%NOTFOUND;
-- process the record (update table A, insert a record into B, delete from C, query table D ....)
-- and finally mark the row as 'processed=1'
END LOOP;
CLOSE records_to_process;
END process_records;The procedure is actually part of a package and the cursor 'records_to_process' is defined in the body. One of the queries executed in the procedure is the SELECT mentioned above (the one that jumps from 2% to 90%).
So the only thing we actually do in Weblogic is
CallableStatement cstmt = connection.prepareCall("{call ProcessPkg.process_records}");
cstmt.execute();and that's it - there is only one call to the JDBC, so the network overhead shouldn't be a problem.
There are 20000 rows we use for testing - we just update them to 'processed=0' (and clear some of the other tables). So actually each run uses exactly the same data, same code paths and produces the very same results. Yet when executed from SQL developer it takes 80 seconds and when executed from Weblogic it takes 800 seconds :-(
The only difference I've just noticed is that when using SQL Developer, we're using PL/SQL notation, i.e. "BEGIN ProcessPkg.process_records; END;" instead of "{call }" but I guess that's irrelevant. And yet another difference - weblogic uses JDBC from 10gR2, while the SQL Developer is bundled with JDBC from 11g. -
Passing table data to pl sql procedure oaf
Hi All,
I have a requirement where i have to pass table data to plsql procedure.
In the first page i select the REQUISITION and click on RETURN button and it will take me to the next page.
and in the Next page i will click on APPLY button.
When i click on APPLY, it will call the procedure and will give input to the procedure whatever has been selected when i have selected requisition.
Please help. Please tell me the approach how to get this task done. A sample code will work.
Hope the requirement is clear.
Thanks in Advance.Hi Chinmay,
Refer below code for Your Requirement.
//Code For Quering Data
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Connection conn = pageContext.getApplicationModule(webBean).getOADBTransaction().getJdbcConnection();
String Query = "SELECT organization_id FROM hr_operating_units WHERE organization_id = fnd_global.org_id";
PreparedStatement stmt = conn.prepareStatement(Query);
resultset=stmt.executeQuery();
while (resultset.next())
orgId = (String)resultset.getString("ORGANIZATION_ID").toString();
conn.commit();
catch(Exception e)
e.printStackTrace();
//Code for Pass Resulted column to Procedure Input for delete Particular Record
Execute parameterized PL SQL procedure from OAF page
Let us try to call PL/SQL package from OAF page. We will try to remove selected line from Database.
Package Spec
CREATE OR REPLACE PACKAGE APPS.genpack_pkg
AS
PROCEDURE roll_delete_proc (orgId IN VARCHAR2);
END genpack_pkg;
Package Body
CREATE OR REPLACE PACKAGE BODY APPS.genpack_pkg
AS
PROCEDURE roll_delete_proc (orgId IN VARCHAR2)
AS
BEGIN
DELETE FROM pklist_roll_details_temp
WHERE roll_line_id = orgId;
COMMIT;
END roll_delete_proc;
END genpack_pkg;
//in Controller PFR
import java.sql.CallableStatement;
if (pageContext.getParameter("ActionsButton") != null)
String val = pageContext.getParameter("ActionsChoice");
if ("DELLN".equals(val))
CallableStatement cstmt = null;
for (OAViewRowImpl row = (OAViewRowImpl)tempvo.first(); row != null; row = (OAViewRowImpl)tempvo.next()) {
if ((row.getAttribute("Selectflag") == null) ||
(!row.getAttribute("Selectflag").toString().equals("Y"))) continue;
try {
int rollid = Integer.parseInt((String)row.getAttribute("orgId"));
Connection conn = am.getOADBTransaction().getJdbcConnection();
if (rollid == 1)
temphm.put(row.getAttribute("orgId").toString(), row.getAttribute("PoNumber").orgId());
tempvo.removeCurrentRow();
else
try
StringBuilder sb = new StringBuilder();
sb.append(rollid);
String strI = sb.toString();
System.out.println("Inside else in delete");
cstmt = conn.prepareCall("{call GENPACK_PKG.tpc_roll_delete_proc(?)}");
cstmt.setString(1, strI);
System.out.println("Oracle Callable Statment Execution Init for Delete");
cstmt.execute();
catch (SQLException e) {
throw new OAException(e.toString(), (byte)0);
}tempvo.removeCurrentRow();
catch (OAException e) {
throw new OAException("No row selected", (byte)3);
Thanks,
Dilip -
Get the report list in a PL/SQL procedure
Hi to all,
I need to get the list of the personal report of a specified user in a PL/SQL procedure, is this possible?
My procedure should delete not "standard" report of a specified portal user.
Then i must have the list of all user's reports and after do my delete logic.
Jhon DhonJhon -
It sounds to me that what you want to do is have a list that is generated based upon the identification of an individual. You can do this a number of ways, but I think you would want to write a straight query to accomplish this rather than a PL/SQL procedure. A query to accomplish what you're looking to do would look something like this:
SELECT
person_name,
person_id_number,
other info you need to see in the output
FROM
table_name (that contains the info you need to see)
WHERE
conditional clauses to obtain only data you wish to see
AND :p_person_id = table_name.person_id_number
The AND clause line will return the employee the user wishes to see based upon that person's ID number. This information is asked for in a parameter form before the report is run. The :p_person_id is referred to as a bind variable. You can read more about this on Metalink or OTN.
HTH,
Steve -
Procedure to delete base on a date
I'm trying to create a procedure to delete all the rows that are < than the date received by parameter.
Need some help since I'm not sure how can I compare the dates, in the table the field is defined as date also the param that I'm receiving.
After that I would like to display the number of rows deleted by the procedure.
create procedure xx (param in DATE)
AS
BEGIN
DELETE
FROM Exhibicion
WHERE EXHFCH < param
thanks for the help.Dario
It would looks something like
create or replace procedure xx ( the_date in date ) is
begin
delete from Exhibicion
where date < the_date;
dbms_output.put_line( 'Rows deleted '|| sql%rowcount );
end;
/Note, I have not actually run/testing this code, but it should be close.
Regards
Bob. -
Best Practice for ViewObjects when inserting data through pl/sql procedure
My applications is oracle form based enterprise level application and we are now developing new module in ADF 11g but there is restriction that all data insertion, updation, and deletion will be through oracle pl/sql procedures. Now my question is that adf pages should be binded with ViewObjects based on Entity Object or with Viewobjects not based on Entity / sql query. Currently I have developed pages with programmatic ViewObjects which are neither based on Entity Objects nor on sql query. In those view objects, i create transient attributes and then used it to create adf pages. Then on save, i extract the data from ViewObject's current row and pass it to procedure. This is working fine but just wondering whether this approach is ok or there is better alternative for that. Ideally i want to create ViewObjects based on EntityObject but don't finding any way to synchronize entityObjects with data inserted through procedures.
Hi,
I create a EO for the Database-View and override the doDML()-Method. For insert/update and delete I call the pl/sql-functions.
See "38.5 Basing an Entity Object on a PL/SQL Package API" in Oracle® Fusion Middleware Fusion Developer's Guide for Oracle Application Development
Framework. -
JDBC Receiver, Stored Procedure that Deletes
Hi,
I have a stored procedure that deletes fields in a table based on a lot of different criteria.
I can't use DELETE or SQL_QUERY ie Statement3 and 6 in http://help.sap.com/saphelp_nw04s/helpdata/en/2e/96fd3f2d14e869e10000000a155106/frameset.htm . I can only use this Stored Procedure.
This is my message type.
<MT_HEADER>
<Statement>
<ClearTable>
<action>.......attribute...set to EXECUTE
<table> .......maps to Stored Procedure
<isInput> ......attribute... set to TRUE
<type> ........attribute...set to STRING
However, I'm getting this error
ERROR: Invalid XML document format for stored procedure: 'type="<SQL-type>"' attribute is missing for element 'table' (Setting a SQL-type (e.g. INTEGER, CHAR, DATE etc.) is mandatory !)
Any ideas?Damien,
If you look in the link you have procided, the datatype for Stored Procedure every element needs to have a TYPE attribute asscoiated with it and you need to give the corresponding Datatype of that element,
<i>The attribute type=<SQL-Datatype> , which describes the valid SQL data type, is mandatory for all parameter types (IN, OUT, INOUT).
The following SQL data types are supported:
INTEGER, BIT, TINYINT, SMALLINT, BIGINT, FLOAT, REAL, DOUBLE, NUMERIC, DECIMAL, CHAR, VARCHAR, STRING, LONGVARCHAR, DATE, TIME, TIMESTAMP, BINARY, VARBINARY, LONGVARBINARY, BLOB (input and output),CLOB (input and output), CURSOR (output; only in conjunction with the Oracle JDBC driver).
</i>
Regards
Bhavesh -
Calling PL/SQL procedures from a Windows CMD script
Hello,
I am writing a Windows CMD script. From this script I want to call procedures from a PL/SQL package which selects, inserts or deletes rows from the database.
How do I go about logging into the database from the cmd script and calling PL/SQL procedures from there?
Does anyone have any examples of such scripts? Thanks in advance.No, it is not a job that needs to be scheduled.
The script will be used when needed to select info from a certain table and also to insert or delete certain info into/from this table (so, it is just simple sql statements which I have put into a package), but I'm sure how to log into the database and execute the procedures from this package in a cmd script. -
Block based on PL/SQL Procedure
Hello,
I have been thinking about building an architecture with
database views to support block querying and stored procedures
for DML. By doing this I keep the forms entirely seperated from
the table model, which is good maintenance. Changes to the data
model will affect the views and the stored procedures, not so
much the forms. Another advantage is that block-fields that come
from lookup-tables will be queryable and updateable without too
much programming. And of course perfomance is good since all SQL
is server-processed.
Does anyone know where to look for documenation on basing a
block on stored procedures ? The online help does not contain
too much on this.
Has anyone used this technique successfully and can tell me
about a few advantages of it ? Disadvantages ?
Regards
/Stefan Nilsson, Sigma
nullYes, I've tried that since Forms 5.0. I remember 3 possible
sources for the block, FROM CLAUSE SUBQUERY, TRANSACTIONAL
TRIGGERS , and PROCEDURES.
Advantages,
It is now easier to design screen with any functionality, like
blocks where you are going to manipulate columns from different
tables. Exactly what you have in mind when you mentioned about
views.
It also supports sources other than relational tables .like
the object tables or even non-Oracle data sources.
All you have to code are procedures to support the SELECT,
LOCK, INSERT, DELETE, and UPDATE functions.
Disadvantages,
You have to code advanced PL/SQL procedures. Price to pay for
excellent functionality.
I can't exactly remember the documentation, but there is a
book titlted Advanced Developers or domething...
Stefan Nilsson (guest) wrote:
: Hello,
: I have been thinking about building an architecture with
: database views to support block querying and stored procedures
: for DML. By doing this I keep the forms entirely seperated from
: the table model, which is good maintenance. Changes to the data
: model will affect the views and the stored procedures, not so
: much the forms. Another advantage is that block-fields that
come
: from lookup-tables will be queryable and updateable without too
: much programming. And of course perfomance is good since all
SQL
: is server-processed.
: Does anyone know where to look for documenation on basing a
: block on stored procedures ? The online help does not contain
: too much on this.
: Has anyone used this technique successfully and can tell me
: about a few advantages of it ? Disadvantages ?
: Regards
: /Stefan Nilsson, Sigma
null -
Regarding execution of pl/sql procedure using JSP
HI all
Please help me.
i am customizing a jsp page ,which is executing one sql procedure first then selecting data from the table in which procedure is inserting.
How can i pass parameter dynamically to the sql procedure ? ,which i am getting from an HTML page.
Please help me out.
regards
satendrathis is the sample code provided by oracle.
* This sample shows how to call PL/SQL blocks from JDBC.
import java.sql.*;
class PLSQL
public static void main (String args [])
throws SQLException, ClassNotFoundException
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
String url = "jdbc:oracle:oci8:@";
try {
String url1 = System.getProperty("JDBC_URL");
if (url1 != null)
url = url1;
} catch (Exception e) {
// If there is any security exception, ignore it
// and use the default
// Connect to the database
Connection conn =
DriverManager.getConnection (url, "scott", "tiger");
// Create the stored procedures
init (conn);
// Cleanup the plsqltest database
Statement stmt = conn.createStatement ();
stmt.execute ("delete from plsqltest");
// Close the statement
stmt.close();
// Call a procedure with no parameters
CallableStatement procnone = conn.prepareCall ("begin procnone; end;");
procnone.execute ();
dumpTestTable (conn);
procnone.close();
// Call a procedure with an IN parameter
CallableStatement procin = conn.prepareCall ("begin procin (?); end;");
procin.setString (1, "testing");
procin.execute ();
dumpTestTable (conn);
procin.close();
// Call a procedure with an OUT parameter
CallableStatement procout = conn.prepareCall ("begin procout (?); end;");
procout.registerOutParameter (1, Types.CHAR);
procout.execute ();
System.out.println ("Out argument is: " + procout.getString (1));
procout.close();
// Call a procedure with an IN/OUT prameter
CallableStatement procinout = conn.prepareCall ("begin procinout (?); end;");
procinout.registerOutParameter (1, Types.VARCHAR);
procinout.setString (1, "testing");
procinout.execute ();
dumpTestTable (conn);
System.out.println ("Out argument is: " + procinout.getString (1));
procinout.close();
// Call a function with no parameters
CallableStatement funcnone = conn.prepareCall ("begin ? := funcnone; end;");
funcnone.registerOutParameter (1, Types.CHAR);
funcnone.execute ();
System.out.println ("Return value is: " + funcnone.getString (1));
funcnone.close();
// Call a function with an IN parameter
CallableStatement funcin = conn.prepareCall ("begin ? := funcin (?); end;");
funcin.registerOutParameter (1, Types.CHAR);
funcin.setString (2, "testing");
funcin.execute ();
System.out.println ("Return value is: " + funcin.getString (1));
funcin.close();
// Call a function with an OUT parameter
CallableStatement funcout = conn.prepareCall ("begin ? := funcout (?); end;");
funcout.registerOutParameter (1, Types.CHAR);
funcout.registerOutParameter (2, Types.CHAR);
funcout.execute ();
System.out.println ("Return value is: " + funcout.getString (1));
System.out.println ("Out argument is: " + funcout.getString (2));
funcout.close();
// Close the connection
conn.close();
// Utility function to dump the contents of the PLSQLTEST table and
// clear it
static void dumpTestTable (Connection conn)
throws SQLException
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("select * from plsqltest");
while (rset.next ())
System.out.println (rset.getString (1));
stmt.execute ("delete from plsqltest");
rset.close();
stmt.close();
// Utility function to create the stored procedures
static void init (Connection conn)
throws SQLException
Statement stmt = conn.createStatement ();
try { stmt.execute ("drop table plsqltest"); } catch (SQLException e) { }
stmt.execute ("create table plsqltest (x char(20))");
stmt.execute ("create or replace procedure procnone is begin insert into plsqltest values ('testing'); end;");
stmt.execute ("create or replace procedure procin (y char) is begin insert into plsqltest values (y); end;");
stmt.execute ("create or replace procedure procout (y out char) is begin y := 'tested'; end;");
stmt.execute ("create or replace procedure procinout (y in out varchar) is begin insert into plsqltest values (y); y := 'tested'; end;");
stmt.execute ("create or replace function funcnone return char is begin return 'tested'; end;");
stmt.execute ("create or replace function funcin (y char) return char is begin return y || y; end;");
stmt.execute ("create or replace function funcout (y out char) return char is begin y := 'tested'; return 'returned'; end;");
stmt.close();
}
Maybe you are looking for
-
ITunes Match - and my departure from Apple
I am a music enthusiats. I bought my frist CD in 1990, about 2 years before I even owned a CD Player. My cassette tape collection was in the thousands and I kne it was only a matter of time before I made the switch to the new technology. Oh ya, an
-
Acrobat 9.3 + Windows 7 - Print Comments List CRASHES App
When trying to print comments within a PDF (via Comments View), Acrobat will crash. This happens across MULTIPLE machines Win7, WinXP, and Adobe 9.0 and Adobe 9.3. I'm supporting a user who NEEDS this ASAP! Any help would be VERY MUCH appreciated. TH
-
Trouble with siri 11/13/11
Is anyone else having trouble with Siri tonight?
-
Re: Is this a bug in onClose?
The problem is that we have no way to prevent JavaFX of really closing a stage. I don't know why the stage re-appears after the first close. But I guess the onClose isn't called anymore because JavaFX thinks the stage is already closed. Or something
-
Public Sector Procurement - Origin Acceptance?
My client is a government agency. In the procurement process they have described a process of providing acceptance of goods at the suppliers plant prior to the delivery and receipt at the ordering plant. I have searched for functionality to meet thi