Scheduling of PL/SQL block.
Hello,
I am using APEX 4.1 and i want to build application in which I want to send a mail on a particular date and also want to schedule a PLSQL block to run automatically on specfic time or date.
Thanks
Hello Pankaj Kumar,
Here is the Scheduling API - APEX_PLSQL_JOB :
http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21676/apex_plsql_job.htm#BGBFGBIB
But if you are using Oracle Database 10g or higher I will suggest use of [url http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_sched.htm#CIHHBGGI]DBMS_SCHEDULER package, the know-how is provided by @Tobias Arnhold in the following blog post:
http://www.apex-at-work.com/2009/06/dbmsscheduler-examples.html
Here is the Mail API - APEX_MAIL :
http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21676/apex_mail.htm#CIHDIEJI
Hope it helps!
Regards,
Kiran
Similar Messages
-
Use Chains, or PL/SQL Block of calls.
I currently have a half dozen cron jobs that kick off different batches of processing. Originally, these were generally a sequence of C programs that did different operations (fetch student info from student record system and load into IdM system, process directory changes, etc). Over the years, most of the program logic has been rewritten as PL/SQL packages and the cron jobs basically drop into SQL*PLUS and do things like:
prompt "Do Spbpers delta"
execute simon.employee_maint.Spbpers_Delta;
commit;
prompt "Do People.Update_From_Employees"
execute simon.People_Maint.Update_From_Employees;
commit;
prompt "Do SGBSTDN_Full"
execute Simon.Bstudent_Maint.Sgbstdn_Full;
commit;
prompt "Do SPRIDEN_Full (Student)"
execute Simon.Bstudent_Maint.Spriden_Full;
These procedures generally connect to other Oracle databases and get or push data around, and are hitting a number of different databases. The biggest of these scripts has 45 execute statements in it. (This script started in 1992.....)
Anyway, we are getting some issues with and it is time to clean things up. This is my first foray into Scheduler and I am hoping to get some philosophical guidance on how best I should restructure things. One obvious thing, is to break up the big script into a couple of smaller ones. In some cases, order matters and in other, it doesn't - although I would prefer not to have several jobs hitting the admin system at the same time.
I have been playing a bit with the scheduler, mostly via the EM web interface, and have come up with a few questions - some pretty specific, others more stylistic.
1) Procedures as jobs - it seemed to want stand alone procedures, and NOT procedures that were part of a package. True?
2) How fine grained should I make the steps in a chain? For example, I call 5 procedures in the same package (student_maint), each to to some specific aspect of the processing (each represents a different source table). Should I create 5 programs, and make them 5 steps in the chain, or just have 5 calls in a PL/SQL block in one program?
3) I don't care what order these 5 run in, but I don't want more than one running at once - thoughts on approaches to this?
4) I will on occasion want to turn off sets of these tasks (like when the remote system is going to be down for an upgrade) - how best to structure things to make this easy to do (and how do I do this?)
The Scheduler system seems to be a very rich and flexible environment, with a lot more options and features than I need, but I feel I should do more than just scheduling a single program with 45 procedure calls in it....Hi,
I can try to answer some of these questions
1) Procedures as jobs - it seemed to want stand alone procedures, and NOT procedures that were part of a package. True?
False. The EM interface does have this restriction, but if you use dbms_scheduler directly there is no such restrisction. Even in the EM interface you can workaround this by using a PL/SQL block which calls the package procedure (although argument handling is a little less flexible this way).
2) How fine grained should I make the steps in a chain? For example, I call 5 procedures in the same package (student_maint), each to to some specific aspect of the processing (each represents a different source table). Should I create 5 programs, and make them 5 steps in the chain, or just have 5 calls in a PL/SQL block in one program?
The answer to this depends on what you are doing. If the 5 steps run serially one after the other, using one pl/sql block may be easier. If you want some pieces to run in parallel, then creating a simple chain is better. A bit more effort spent setting up the chain will result in much faster execution times if you can run pieces in parallel.
3) I don't care what order these 5 run in, but I don't want more than one running at once - thoughts on approaches to this?
This has come up on the forum a few times and there are basically two different approaches. One is to use dbms_lock to ensure that only one runs at a time. This is the easiest way and the way that I recommend.
The other way is to set up a job class with a resource consumer group and put into effect a resource consumer plan that specifies that only one session from that resource consumer group can run at a time. This is easily extensible to cases where you want 2 or more running at a time from a certain job class (which dbms_lock doesn't support).
Code on how to set this up and more discussion is located here
Run Jobs One After Another
4) I will on occasion want to turn off sets of these tasks (like when the remote system is going to be down for an upgrade) - how best to structure things to make this easy to do (and how do I do this?)
Jobs and programs can be disabled. But if a job or chain tries to run a disabled program it will result in a failure (though it will be retried if you say that the job can be restarted).
[ 5) ] The Scheduler system seems to be a very rich and flexible environment, with a lot more options and features than I need, but I feel I should do more than just scheduling a single program with 45 procedure calls in it....
The Scheduler was intended to accommodate a wide range of usage from simple one-off background tasks to complex sequences of interrelated tasks. As with any other software development you should use it in the simplest way possible that does what you need it to do.
Hope this helps. Feel free to post any further questions.
-Ravi -
Spawning multiple Processes in PL/SQL Block
Hi All
Does anyone know if it is possible within PL/SQL block to 'spawn' multiple versions of a procedure as parallel processes.
What I would like to do is something like
WHILE x = 'CONTINUE LOOP
load process1...load process2..load process3.
I could create a UNIX script to run the procedure as a background process multiple times but I would prefer to use PL/SQL solution if one exists.
Many thanks inadvanceHi Martin,
you should have a look into the package "dbms_Job". With the routines in this package it is possible to submit the execution of stored procedures by the Oracle job scheduler.
If you are in 10g you could alternatively use the "dbms_Scheduler" package.
Have a nice day.
Björn Hachmann -
Display an Alert message in PL/SQL block in APEX
Hi,
we are getting an oracle exception while inserting a new row. As it is having the unique constaint on a coulumn.
Now the problem iis we need to Display an "Alert message" based on the input field validation. That java script code for alert has to be embeded nside a PL/SQL block in Oracle APEX Application.
we tried doing this with below code:
Begin
INSERT INTO <<table name>>(ID,NAME) VALUES (s1,:TXT_s2);
exception when others then
htp.p('<script language="javascript">');
htp.p('alert("Exception");');
htp.p('</script>');
end;
If anybody knows .... please reply.
Thanks,
Subarna
Edited by: user9955252 on Apr 21, 2010 1:47 AMHello,
APEX Forum is here : Oracle Application Express (APEX)
Regards -
Display an Alert message from PL/SQL block in APEX
Hi,
we are getting an oracle exception while inserting a new row. As it is having the unique constaint on a coulumn.
Now the problem iis we need to Display an "Alert message" based on the input field validation. That java script code for alert has to be embeded nside a PL/SQL block in Oracle APEX Application.
we tried doing this with below code:
Begin
INSERT INTO <<table name>>(ID,NAME) VALUES (s1,:TXT_s2);
exception when others then
htp.p('<script language="javascript">');
htp.p('alert("Exception");');
htp.p('</script>');
end;
If anybody knows .... please reply.
Thanks,
SubarnaIf your end goal is showing a pretty error message instead of the message that the tables unique constraint raises try the following. This logic will show a nice message and not try to insert non-unique data.
(1) Create a validation of type "Function Returning Error Text".
(2) Place similar code like the following in your validation. Notice that if the unique name does not exist the no_data_found returns null allowing the validation to pass.
DECLARE
v_error varchar2(100);
BEGIN
SELECT 'A person by this name already exists.'
INTO v_error
FROM your_table
WHERE your_name = :P1_YOUR_NAME;
RETURN v_error;
EXCEPTION
WHEN no_data_found THEN
RETURN NULL;
END; -
Performance: Operations in Cursor vs. Operations in PL/SQL block
Why does I have a better performance when I program operations in complex cursors instead of programming the same statement in a pl/sql block in a stored procedure?
Operation in a Cursor:
CURSOR c IS
DECODE(name,'Peter','dog','cat') animal
...The same Operation in a PL/SQL block:
begin
if name = 'Peter'
then
animal = 'dog';
else
animal = 'cat';
end if;
end;
...I know that a parsed cursor is placed in the Shared Pool and reference
a context area in the PGA.
Does anybody have an idea?
Message was edited by:
madMaybe because if you can write only a SQL query, it is faster than to write PL/SQL code that will do the same job. See following thread for a analog discussion: Re: pl/sql table
-
How to test for différent Select into a single PL/SQL block ?
Hi,
I am relatively new to PL/SQL and I am trying to do multiple selects int a single PL/SQL block. I am confronted to the fact that if a single select returns no data, I have to go to the WHEN DATA_NOT_FOUND exception.
Or, I would like to test for different selects.
In an authentification script, I am searching in a table for a USER ID (USERID) and an application ID, to check if a user is registered under this USERID for this APPLICATION.
There are different possibilities : 4 possibilities :
- USERID Existing or not Existing and
- Aplication ID found or not found for this particular USERID.
I would like to test for thes 4 possibilities to get the status of this partiular user regardin this application.
The problem is that if one select returns no row, I go to the exception data not found.
In the example below you see that if no row returned, go to the exception
DECLARE
P_USERID VARCHAR2(400) DEFAULT NULL;
P_APPLICATION_ID NUMBER DEFAULT NULL;
P_REGISTERED VARCHAR2(400) DEFAULT NULL;
BEGIN
SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
WHERE USERID = :P39_USERID AND APPLICATION_ID = :APP_ID ;
:P39_TYPE_UTILISATEUR := 'USER_REGISTERED';
EXCEPTION
WHEN NO_DATA_FOUND THEN
:P39_TYPE_UTILISATEUR := 'USER_NOT_FOUND';
END;I would like to do first this statement :
SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
WHERE USERID = :P39_USERID Then to do this one if the user is found :
SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES
WHERE USERID = :P39_USERID AND APPLICATION_ID = :APP_ID ;etc...
I basically don't want to go to the not found exception before having tested the 4 possibilities.
Do you have a suggestion ?
Thank you for your kind help !
ChristianSurely there are only 3 conditions to check?
1. The user exists and has that app
2. The user exists and doesn't have that app
3. The user doesn't exist
You could do this in one sql statement like:
with mimic_data_table as (select 1 userid, 1 appid from dual union all
select 1 userid, 2 appid from dual union all
select 2 userid, 1 appid from dual),
-- end of mimicking your table
params_table as (select :p_userid userid, :p_appid appid from dual)
select pt.userid,
pt.appid,
decode(min(case when dt.userid = pt.userid and dt.appid = pt.appid then 1
when dt.userid = pt.userid then 2
else 3
end), 1, 'User and app exist',
2, 'User exists but not for this app',
3, 'User doesn''t exist') user_app_check
from mimic_data_table dt,
params_table pt
where pt.userid = dt.userid (+)
group by pt.userid, pt.appid;
:p_userid = 1
:p_appid = 2
USERID APPID USER_APP_CHECK
1 2 User and app exist
:p_userid = 1
:p_appid = 3
USERID APPID USER_APP_CHECK
1 3 User exists but not for this app
:p_userid = 3
:p_appid = 2
USERID APPID USER_APP_CHECK
3 2 User doesn't exist -
How to use the WHENEVER SQLERROR EXIT statement in a PL/SQL block.
Hi,
I am getting the following error when trying to add the following statement in an PL/SQL block.
WHENEVER SQLERROR EXIT SQL.SQLCODE
[exec] ERROR at line 23:
[exec] ORA-06550: line 23, column 12:
[exec] PLS-00103: Encountered the symbol "SQLERROR" when expecting one of the
[exec] following:
[exec] := . ( @ % ;
How can i use the above statement in the PL/SQL Block? I have only IF statement in that block( between BEGIN and END).
ThanksHi,
Usually there's always more than one solution.
Can you post an example of what you're trying to accomplish?
That would be useful.
(Place the tag before and after your example to maintain formatting en spacing, see the [fac|http://forums.oracle.com/forums/help.jspa] regarding available tags) -
No Data Found: Exception in SQL inside PL/SQL block
Hi Friends
I am trying to execute an SQL SELECT stmt inside a PL/SQL block. But when i execute the procedure, it gives me No Data Found Exception.
I know it is because no row is fetched in the query, but the condition of the SELECT query i have specified is being satisfied, i have checked it by running it on the SQL prompt.
But somehow, it is not running from inside the PL/SQL procedure.Can anybody help me out on this as to why is this happening?? I am giving my code for reference and have Highlighted the Query inside it:
CREATE OR REPLACE procedure insert_sfdc_account
as
--DECLARE
CURSOR C1 IS
SELECT customer_code, name1, name2, name3, name4, phone_number, fax, web_address, industry_sector, customer_profile, customer_type,
address, city, postal_code, country_key, zzcust_type, vat_code
FROM load_cust_general
WHERE account_group = 'ZSIT';
v_cust_cur c1%ROWTYPE;
-- type sales_tab is table of load_cust_sales_area%rowtype;
v_sales_area load_cust_sales_area%ROWTYPE;
-- v_sales_area sales_tab;
v_salesorg varchar2(10);
v_sales_district varchar2(10);
v_salesoff varchar2(10);
v_custgrp varchar2(10);
v_salesgrp varchar2(10);
v_type varchar2(20);
v_nature varchar2(10);
v_partner_code varchar2(10);
v_parent_cust varchar2(20);
v_credit_blk varchar2(20);
BEGIN
open c1;
loop
fetch c1 into v_cust_cur;
exit when c1%NOTFOUND;
for i in (SELECT customer_code, salesorg from load_cust_partner
where customer_code = v_cust_cur.customer_code ) LOOP
dbms_output.put_line(v_cust_cur.customer_code );
SELECT partner_code into v_partner_code from load_cust_partner
where customer_code = i.customer_code and salesorg = i.salesorg and partner_function = 'Z1';
dbms_output.put_line(v_partner_code||i.customer_code);
SELECT salesorg, sales_district, salesoff, salesgrp, custgrp INTO v_salesorg, v_sales_district, v_salesoff, v_salesgrp, v_custgrp FROM load_cust_sales_area
WHERE customer_code = i.customer_code and salesorg = i.salesorg;
dbms_output.put_line(v_salesorg||i.salesorg);
SELECT parent_customer INTO v_parent_cust from load_cust_hierarchy
WHERE customer_code = i.customer_code and salesorg = i.salesorg and hierarchy_type = 'G'; dbms_output.put_line(v_parent_cust);
SELECT credit_block INTO v_credit_blk from load_cust_company_cod
WHERE customer_code = i.customer_code;
dbms_output.put_line(v_credit_blk);
for j in (SELECT account_group, customer_type from load_cust_general
where customer_code IN (select customer_code from load_cust_partner
where partner_code = i.customer_code and salesorg = i.salesorg and partner_function = 'ZS'))
LOOP
-- exit when j%NOTFOUND;
dbms_output.put_line(j.account_group);
if (j.account_group = 'ZDIS') THEN
v_type := 'DISAC';
v_nature := '06';
-- EXIT ;
else
v_type := 'SPACC';
v_nature := '01';
END IF;
dbms_output.put_line(v_type||' '||v_nature);
END LOOP;
INSERT INTO sfdc_account
(SAP_ACCOUNT_ID__C, NAME, TYPE, RECORDTYPEID, PARENTID, PHONE, FAX, WEBSITE, OWNERID, MARKETING_DOMAIN__C,
INDUSTRIAL_SECTOR__C, ABC_CLASSIFICATION__C, NAME_1__C, NAME_2__C, NAME_3__C, NAME_4__C, PAYMENT_STATUS__C,
CUSTOMER_GROUP__C, ADDRESS_STREET__C, CITY__C, POSTAL_CODE__C, COUNTRY__C, SALES_OFFICE__C, SALESORG__C,
SALESDISTRICT__C, SALESGROUP__C, NATURE__C, VATCODE__C)
VALUES((i.customer_code||i.salesorg), (v_cust_cur.Name1||' '||v_cust_cur.name2), ' ', v_type, v_parent_cust,
v_cust_cur.phone_number, v_cust_cur.fax, v_cust_cur.web_address, v_partner_code, SUBSTR(v_cust_cur.industry_sector,1,2),
v_cust_cur.industry_sector, v_cust_cur.customer_profile, v_cust_cur.name1, v_cust_cur.name2, v_cust_cur.name3,
v_cust_cur.name4, v_credit_blk, v_custgrp, v_cust_cur.address, v_cust_cur.city, v_cust_cur.postal_code,
v_cust_cur.country_key, v_salesoff, v_salesorg, v_sales_district,
v_salesgrp, v_nature, v_cust_cur.vat_code);
end loop;
end loop;
CLOSE c1;
-- Delete data from Load Table
-- EXECUTE IMMEDIATE 'TRUNCATE TABLE load_cust_general';
/* truncate table load_cust_partner;
truncate table load_cust_hierarhy;
truncate table load_cust_sales_area;
truncate table load_cust_company_cod;
commit;
exception
when others then
raise_application_error( -20001, substr( sqlerrm, 1, 150 ) );
END;
Kindly Help.....
Thanks and RegardsCreate the procedure again and execute it in SQL*Plus environment and paste the output:
CREATE OR REPLACE procedure insert_sfdc_account
as
--DECLARE
CURSOR C1 IS
SELECT customer_code, name1, name2, name3, name4, phone_number, fax, web_address, industry_sector, customer_profile, customer_type,
address, city, postal_code, country_key, zzcust_type, vat_code
FROM load_cust_general
WHERE account_group = 'ZSIT';
v_cust_cur c1%ROWTYPE;
-- type sales_tab is table of load_cust_sales_area%rowtype;
v_sales_area load_cust_sales_area%ROWTYPE;
-- v_sales_area sales_tab;
v_salesorg varchar2(10);
v_sales_district varchar2(10);
v_salesoff varchar2(10);
v_custgrp varchar2(10);
v_salesgrp varchar2(10);
v_type varchar2(20);
v_nature varchar2(10);
v_partner_code varchar2(10);
v_parent_cust varchar2(20);
v_credit_blk varchar2(20);
BEGIN
open c1;
loop
fetch c1 into v_cust_cur;
exit when c1%NOTFOUND;
for i in (SELECT customer_code, salesorg from load_cust_partner
where customer_code = v_cust_cur.customer_code ) LOOP
SELECT partner_code into v_partner_code from load_cust_partner
where customer_code = i.customer_code and salesorg = i.salesorg and partner_function = 'Z1';
SELECT salesorg, sales_district, salesoff, salesgrp, custgrp INTO v_salesorg, v_sales_district, v_salesoff, v_salesgrp, v_custgrp FROM load_cust_sales_area
WHERE customer_code = i.customer_code and salesorg = i.salesorg;
dbms_output.put_line('Customer_Code : '|| i.customer_code);
dbms_output.put_line('SalesOrg : '|| i.salesorg);
SELECT parent_customer INTO v_parent_cust from load_cust_hierarchy
WHERE customer_code = i.customer_code and salesorg = i.salesorg and hierarchy_type = 'G';
dbms_output.put_line('Successfully Executed SQL st. Error is somewhere else');
SELECT credit_block INTO v_credit_blk from load_cust_company_cod
WHERE customer_code = i.customer_code;
for j in (SELECT account_group, customer_type from load_cust_general
where customer_code IN (select customer_code from load_cust_partner
where partner_code = i.customer_code and salesorg = i.salesorg and partner_function = 'ZS'))
LOOP
-- exit when j%NOTFOUND;
if (j.account_group = 'ZDIS') THEN
v_type := 'DISAC';
v_nature := '06';
-- EXIT ;
else
v_type := 'SPACC';
v_nature := '01';
END IF;
END LOOP;
INSERT INTO sfdc_account
(SAP_ACCOUNT_ID__C, NAME, TYPE, RECORDTYPEID, PARENTID, PHONE, FAX, WEBSITE, OWNERID, MARKETING_DOMAIN__C,
INDUSTRIAL_SECTOR__C, ABC_CLASSIFICATION__C, NAME_1__C, NAME_2__C, NAME_3__C, NAME_4__C, PAYMENT_STATUS__C,
CUSTOMER_GROUP__C, ADDRESS_STREET__C, CITY__C, POSTAL_CODE__C, COUNTRY__C, SALES_OFFICE__C, SALESORG__C,
SALESDISTRICT__C, SALESGROUP__C, NATURE__C, VATCODE__C)
VALUES((i.customer_code||i.salesorg), (v_cust_cur.Name1||' '||v_cust_cur.name2), ' ', v_type, v_parent_cust,
v_cust_cur.phone_number, v_cust_cur.fax, v_cust_cur.web_address, v_partner_code, SUBSTR(v_cust_cur.industry_sector,1,2),
v_cust_cur.industry_sector, v_cust_cur.customer_profile, v_cust_cur.name1, v_cust_cur.name2, v_cust_cur.name3,
v_cust_cur.name4, v_credit_blk, v_custgrp, v_cust_cur.address, v_cust_cur.city, v_cust_cur.postal_code,
v_cust_cur.country_key, v_salesoff, v_salesorg, v_sales_district,
v_salesgrp, v_nature, v_cust_cur.vat_code);
end loop;
end loop;
CLOSE c1;
-- Delete data from Load Table
-- EXECUTE IMMEDIATE 'TRUNCATE TABLE load_cust_general';
/* truncate table load_cust_partner;
truncate table load_cust_hierarhy;
truncate table load_cust_sales_area;
truncate table load_cust_company_cod;
commit;
exception
when others then
raise_application_error( -20001, substr( sqlerrm, 1, 150 ) );
END;
SQL> set serveroutput on
SQL> exec insert_sfdc_account; -
Call to concurrent program in a pl/sql block does not COMMIT data to table
I have the following PL/SQL block.
apps.create_po(x_org_id,x_document_num,x_agent_name,x_vendor_id,x_vendor_site_id,x_ship_to_location,x_bill_to_location,x_creation_date,new_isbn,new_print_key,new_unit_setup_cost,new_unit_run_cost,x_item,x_category_id,x_item_description,x_unit_of_measure,x_quantity,x_unit_price,x_ship_to_org_id,x_promise_date,x_qty_rcv_tolerance, x_deliver_to_location,x_destination_org_id, x_destination_subinventory,x_segment2,x_segment4);
COMMIT;
FND_GLOBAL.APPS_INITIALIZE(v_user_id,v_resp_id,201);
v_po_req_id := apps.fnd_request.submit_request('PO','POXPOPDOI',NULL,NULL,NULL,
NULL,'STANDARD',NULL,'Y',NULL,'APPROVED',NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
DBMS_OUTPUT.PUT_LINE('Request ID is:' || v_po_req_id);
IF v_po_req_id <> 0 THEN
dbms_lock.sleep(60);
dbms_output.Put_line('Sleep executed');
COMMIT;
select PHASE_CODE,STATUS_CODE INTO v_phase_code,v_status_code
FROM FND_CONCURRENT_REQUESTS
WHERE REQUEST_ID = v_po_req_id;
dbms_output.put_line('After commit Phase and status codes are = '||v_phase_code || v_status_code);
ELSE
ROLLBACK;
END IF;
dbms_output.put_line('New Po is' || x_document_num);
dbms_output.put_line('Quantity Is'|| x_quantity);
apps.receive_po(x_document_num,x_quantity);
v_rcv_req_id := apps.fnd_request.submit_request('PO','RVCTP',NULL,NULL,NULL,
'BATCH',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
DBMS_OUTPUT.PUT_LINE('Request ID is:' || v_rcv_req_id);
IF v_rcv_req_id <> 0 THEN
COMMIT;
DBMS_OUTPUT.PUT_LINE('COMMITED RECEIVING');
ELSE
ROLLBACK;
END IF;
Presently when this block runs, i can see the new PO number created. Commit is also successfully executed. The last output for the program is
New Po is 20651
Quantity Is 450
But due to some reason, the receiving program(receive_po) cannot retrieve the same PO from the base table.
But once this pl/sql block is complete, and i call the receving procedure from a different session, the Po is retrieved and receiving against the PO is executed successfully.
Can someone please suggest a work around ? Is the code missing something ? Since POXPOPDOI is a concurrent program which is executed as an asyncronous process, the commit statement after the call to concurent program does not work but the commit is executed only after it exits the pl/sql block.Thanks for responding.
receive_po() program just inserts the data into RCV_HEADERS_INTERFACE and RCV_TRANSACTIONS_INTERFACE tables based on the PO that is created in the previous step. So basically the new PO created has to be received and the receive_po() just inserts data into the interface tables so that RVCTP can be called after that for receiving.
Here is the code for the procedure.
SET SERVEROUTPUT ON;
--FND_GLOBAL.APPS_INITIALIZE(3,20707,201);
--Procedure for receiving interface to load data to RCV_HEADERS_INTERFACE and RCV_TRANSACTIONS_INTERFACE
CREATE OR REPLACE PROCEDURE receive_po (x_ponum IN VARCHAR2,x_quantity IN NUMBER) AS
v_vendor_site_id NUMBER;
v_vendor_id NUMBER;
v_agent_id NUMBER;
v_ship_to_organization_id NUMBER;
v_item_id NUMBER;
v_uom_code varchar2(25);
v_subinventory varchar2(25);
v_ship_to_location_id NUMBER;
BEGIN
--header information in variables
dbms_output.put_line('Entering Receiving Insert Procedure');
dbms_output.put_line('Po number ='||x_ponum||'$');
dbms_output.put_line('Quantity is ='||x_quantity||'$');
select pvsa.vendor_site_id into v_vendor_site_id
FROM po_headers_all pha,po_vendors pv, po_vendor_sites_all pvsa
where pha.vendor_id = pv.vendor_id
and pv.vendor_id = pvsa.vendor_id
and pha.segment1 = x_ponum;
dbms_output.put_line('Vendor Site ID is' ||v_vendor_site_id);
select pv.vendor_id into v_vendor_id
FROM po_headers_all pha,po_vendors pv, po_vendor_sites_all pvsa
where pha.vendor_id = pv.vendor_id
and pv.vendor_id = pvsa.vendor_id
and pha.segment1 = x_ponum;
dbms_output.put_line('Vendor ID is' ||v_vendor_id);
select plla.SHIP_TO_ORGANIZATION_ID into v_ship_to_organization_id
from PO_HEADERS_ALL pha, PO_LINE_LOCATIONS_ALL plla
where pha.PO_HEADER_ID = plla.PO_HEADER_ID
and pha.segment1 = x_ponum;
dbms_output.put_line('Ship to org is' ||v_ship_to_organization_id);
select agent_id into v_agent_id
FROM po_headers_all
WHERE segment1 = x_ponum;
dbms_output.put_line('Agent ID is' ||v_agent_id);
--printing header table information
dbms_output.put_line('vendor id is:'||v_vendor_id);
dbms_output.put_line('vendor site id is:'||v_vendor_site_id);
dbms_output.put_line('agent id is:'||v_agent_id);
dbms_output.put_line('ship to organization id is:'||v_ship_to_organization_id);
--line information in variables
--derive item id
select pla.item_id into v_item_id
from po_headers_all pha, po_lines_all pla
where pha.po_header_id = pla.po_header_id
and pha.org_id = pla.org_id
and pha.segment1 = x_ponum;
--derive uom
select pla.unit_meas_lookup_code into v_uom_code
from po_headers_all pha, po_lines_all pla
where pla.po_header_id = pha.po_header_id
and pla.org_id = pha.org_id
and pha.segment1 = x_ponum;
--derive subinventory
select pda.destination_subinventory into v_subinventory
from po_headers_all pha, po_lines_all pla,po_distributions_all pda
where pha.po_header_id = pla.po_header_id
and pla.po_header_id = pda.po_header_id
and pla.po_line_id = pda.po_line_id
and pha.org_id = pla.org_id
and pla.org_id = pda.org_id
and pha.segment1 = x_ponum;
--derive ship to location id
select ship_to_location_id into v_ship_to_location_id
from po_headers_all
where segment1 = x_ponum;
--printing transaction table details
dbms_output.put_line('item id is:'||v_item_id);
dbms_output.put_line('UOM is:'||v_uom_code);
dbms_output.put_line('subinventory is:'||v_subinventory);
dbms_output.put_line('ship to location id is:'||v_ship_to_location_id);
--insert data into the receiving interface header table
INSERT INTO RCV_HEADERS_INTERFACE
HEADER_INTERFACE_ID ,
GROUP_ID ,
PROCESSING_STATUS_CODE ,
RECEIPT_SOURCE_CODE ,
TRANSACTION_TYPE ,
LAST_UPDATE_DATE ,
LAST_UPDATED_BY ,
LAST_UPDATE_LOGIN,
CREATION_DATE ,
CREATED_BY ,
VENDOR_ID ,
VENDOR_SITE_ID ,
SHIP_TO_ORGANIZATION_ID ,
EXPECTED_RECEIPT_DATE ,
EMPLOYEE_ID ,
VALIDATION_FLAG
SELECT
RCV_HEADERS_INTERFACE_S.NEXTVAL,
RCV_INTERFACE_GROUPS_S.NEXTVAL,
'PENDING',
'VENDOR',
'NEW', -- 'CANCEL',
sysdate,
3,
3,
sysdate,
3,
v_vendor_id,
v_vendor_site_id,
v_ship_to_organization_id,
sysdate+5,
v_agent_id,
'Y'
FROM DUAL;
commit;
--insert data into the interface transaction table
for i in 1..1 loop
INSERT INTO RCV_TRANSACTIONS_INTERFACE
(INTERFACE_TRANSACTION_ID ,
HEADER_INTERFACE_ID ,
GROUP_ID ,
LAST_UPDATE_DATE ,
LAST_UPDATED_BY ,
CREATION_DATE ,
CREATED_BY ,
LAST_UPDATE_LOGIN,
TRANSACTION_TYPE ,
TRANSACTION_DATE ,
PROCESSING_STATUS_CODE ,
PROCESSING_MODE_CODE ,
TRANSACTION_STATUS_CODE ,
QUANTITY ,
UNIT_OF_MEASURE ,
ITEM_ID ,
AUTO_TRANSACT_CODE ,
RECEIPT_SOURCE_CODE ,
SOURCE_DOCUMENT_CODE ,
SUBINVENTORY ,
DOCUMENT_NUM ,
SHIP_TO_LOCATION_ID ,
VALIDATION_FLAG
SELECT
RCV_TRANSACTIONS_INTERFACE_S.NEXTVAL,
RCV_HEADERS_INTERFACE_S.CURRVAL,
RCV_INTERFACE_GROUPS_S.CURRVAL,
SYSDATE,
3,
SYSDATE,
3,
3,
'RECEIVE', --'RECEIVE', -- 'SHIP', --'06-JAN-1998',--question here
sysdate,
'PENDING',
'BATCH',
'PENDING',
x_quantity,
v_uom_code,
v_item_id,
'DELIVER', -- 'RECEIVE', --'DELIVER',
'VENDOR',
'PO',
v_subinventory,
x_ponum,
v_ship_to_location_id,
'Y'
FROM DUAL;
end loop;
commit;
END receive_po;
I am really stuck and looking out for work arond. Please help.
Thanks,
Natasha -
My First while loop inside PL/SQL block not working , please help
Hi ,
I am new to PL/sql and struck at PL SQL blocks , please help to solve this .
declare
v_A number constant :=10 ;
j number constant := 3 ;
BEGIN
WHILE j < v_A
LOOP
DBMS_OUTPUT.PUT_LINE('Hai');
END LOOP;
END;
please help as how to resolve this .
Thanks in advance .btw it's a useful habit to use indentation to highlight the block structure. Also it's worth deciding what your convention will be for keywords (I use uppercase, lowercase is also fine as far as I'm concerned but I've set up my editor to uppercase them) and variables, database object names etc (I use lowercase), e.g:
DECLARE
v_a CONSTANT PLS_INTEGER := 10;
j CONSTANT PLS_INTEGER := 3;
i PLS_INTEGER := j;
BEGIN
WHILE i <= v_a LOOP
DBMS_OUTPUT.PUT_LINE(i);
i := i +1;
END LOOP;
END;or perhapsdeclare
v_a constant pls_integer := 10;
j constant pls_integer := 3;
i pls_integer := j;
begin
while i <= v_a loop
dbms_output.put_line(i);
i := i +1;
end loop;
end;When I see "declare" and "BEGIN" in the same block of code I worry about the standard of code I'm going to see... -
Bind Variable in SELECT statement and get the value in PL/SQL block
Hi All,
I would like pass bind variable in SELECT statement and get the value of the column in Dynamic SQL
Please seee below
I want to get the below value
Expected result:
select distinct empno ,pr.dept from emp pr, dept ps where ps.dept like '%IT' and pr.empno =100
100, HR
select distinct ename ,pr.dept from emp pr, dept ps where ps.dept like '%IT' and pr.empno =100
TEST, HR
select distinct loc ,pr.dept from emp pr, dept ps where ps.dept like '%IT' and pr.empno =100
NYC, HR
Using the below block I am getting column names only not the value of the column. I need to pass that value(TEST,NYC..) into l_col_val variable
Please suggest
----- TABLE LIST
CREATE TABLE EMP(
EMPNO NUMBER,
ENAME VARCHAR2(255),
DEPT VARCHAR2(255),
LOC VARCHAR2(255)
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (100,'TEST','HR','NYC');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (200,'TEST1','IT','NYC');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (300,'TEST2','MR','NYC');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (400,'TEST3','HR','DTR');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (500,'TEST4','HR','DAL');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (600,'TEST5','IT','ATL');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (700,'TEST6','IT','BOS');
INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (800,'TEST7','HR','NYC');
COMMIT;
CREATE TABLE COLUMNAMES(
COLUMNAME VARCHAR2(255)
INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('EMPNO');
INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('ENAME');
INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('DEPT');
INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('LOC');
COMMIT;
CREATE TABLE DEPT(
DEPT VARCHAR2(255),
DNAME VARCHAR2(255)
INSERT INTO DEPT(DEPT,DNAME) VALUES ('IT','INFORMATION TECH');
INSERT INTO DEPT(DEPT,DNAME) VALUES ('HR','HUMAN RESOURCE');
INSERT INTO DEPT(DEPT,DNAME) VALUES ('MR','MARKETING');
INSERT INTO DEPT(DEPT,DNAME) VALUES ('IT','INFORMATION TECH');
COMMIT;
PL/SQL BLOCK
DECLARE
TYPE EMPCurTyp IS REF CURSOR;
v_EMP_cursor EMPCurTyp;
l_col_val EMP.ENAME%type;
l_ENAME_val EMP.ENAME%type;
l_col_ddl varchar2(4000);
l_col_name varchar2(60);
l_tab_name varchar2(60);
l_empno number ;
b_l_col_name VARCHAR2(255);
b_l_empno NUMBER;
begin
for rec00 in (
select EMPNO aa from EMP
loop
l_empno := rec00.aa;
for rec in (select COLUMNAME as column_name from columnames
loop
l_col_name := rec.column_name;
begin
l_col_val :=null;
l_col_ddl := 'select distinct :b_l_col_name ,pr.dept ' ||' from emp pr, dept ps where ps.dept like ''%IT'' '||' and pr.empno =:b_l_empno';
dbms_output.put_line('DDL ...'||l_col_ddl);
OPEN v_EMP_cursor FOR l_col_ddl USING l_col_name, l_empno;
LOOP
l_col_val :=null;
FETCH v_EMP_cursor INTO l_col_val,l_ename_val;
EXIT WHEN v_EMP_cursor%NOTFOUND;
dbms_output.put_line('l_col_name='||l_col_name ||' empno ='||l_empno);
END LOOP;
CLOSE v_EMP_cursor;
END;
END LOOP;
END LOOP;
END;user1758353 wrote:
Thanks Billy, Would you be able to suggest any other faster method to load the data into table. Thanks,
As Mark responded - it all depends on the actual data to load, structure and source/origin. On my busiest database, I am loading on average 30,000 rows every second from data in external files.
However, the data structures are just that - structured. Logical.
Having a data structure with 100's of fields (columns in a SQL table), raise all kinds of questions about how sane that structure is, and what impact it will have on a physical data model implementation.
There is a gross misunderstanding by many when it comes to performance and scalability. The prime factor that determines performance is not how well you code, what tools/language you use, the h/w your c ode runs on, or anything like that. The prime factor that determines perform is the design of the data model - as it determines the complexity/ease to use the data model, and the amount of I/O (the slowest of all db operations) needed to effectively use the data model. -
How to unblock a material in scheduling agreement which is blocked previous
Dear All
Please let me know the procedure for making a material unblocked in scheduling agreement which was blocked previously .
Regards
Abhijit DasHai,
In MM02 basic data 1/purchasing views Xplant and plant specific mat status field make it blank.
Regards,
BSK -
Error while invoking webservice using UTL_HTTP from PL/SQL Block
Hi All,
I am invoking a webservice (SOAP Request) from a PL/SQL block using UTL_HTTP package.
I am able to send the complete request and am getting the required instance on the BPEL Console, but the process is erroring out while getting response back.
and the PL/SQL Block is ending in error mentioned below:
ERROR at line 1:
ORA-29266: end-of-body reached
ORA-06512: at "SYS.UTL_HTTP", line 1321
ORA-06512: at "APPS.CSM_BPEL_TEST_PKG", line 34
ORA-06512: at line 1
Package is completing successfully if i test in local DB and local BPEL.
But giving above error in client's.
Can anyone let me know what is the cause of this.
Thanks in advanceI got it working by making process Synchronous.
But with asynchronous process it is still same error.
Thanks... -
What is the wrong in this PL/SQL block
Hi a...
Can you please tell what is the wrong in this pl/sql block.
declare
TYPE TYP_NT_NUM IS TABLE OF NUMBER ;
v_tab TYP_NT_NUM := TYP_NT_NUM();
TYPE uname is VARRAY(30) of varchar2(100) ;
usr uname := uname ( 'u1','u2','u3','u4' );
TYPE pwd is VARRAY(30) of varchar2(100) ;
psw pwd := pwd('p1','p2','p3','p4');
x number(10):=0;
Cursor fcid IS Select distinct FC_ID From FCMASTER ;
Begin
Open fcid ;
--for ii in usr.first .. usr.last loop
Loop
Fetch fcid Into x ;
Exit When fcid%NOTFOUND ;
v_tab(fcid%ROWCOUNT) := x ;
End loop ;
For iii IN v_tab.FIRST .. v_tab.LAST Loop
dbms_output.put_line(v_tab(iii).FC_ID) ;
End loop ;
End loop; End of outer loop
End;
The error is
Error
[row:28,col:36] ORA-06550: line 28, column 36:
PLS-00487: Invalid reference to variable 'NUMBER'
ORA-06550: line 28, column 4:
PL/SQL: Statement ignored
Thanks in advance,
Palv_tab(iii).FC_ID
declare
type typ_nt_num is table of number;
v_tab typ_nt_num;
begin
select distinct object_id bulk collect into v_tab from all_objects where rownum <= 10;
for i in 1 .. v_tab.count loop
dbms_output.put_line(v_tab(i)) ;
end loop ;
end;
/
Maybe you are looking for
-
A lot of characters missing from "Character Viewer" .. can I get them?
Most musical symbols show an empty box. Other categories too... Could I've erased them? With CleanMyMac maybe?
-
Error in building schema after publishing PL/SQLwebservice
which return multiple rows. I am attaching the wsdl after generation please let me know if any wrong in wsdl. Procedure which is published is working fine in sql <?xml version = '1.0' encoding = 'UTF-8'?> <!--Generated by the Oracle JDeveloper Web Se
-
I am trying to pick up a .csv file that doesn't comform to a strict format, mainly because of human formatting errors in the file. I've tried to create a fixed length schema and a comma delimited schema but both fail as soon as they get a file that d
-
How to use GooglePlayServices libs in Native Extension of Android AIR app?
I am trying to use some features of Google Play Services lib but I could not make it work. I have added the reference to the google play service libs to the manifest file (from Flash Builder) <application android:enabled="true"> <meta-data android:n
-
Recovery Partition Satilite L455d-S597​6
How do I access the recovery partition? I need to restore my son's Laptop. Thanks