How to use bulk in multiple cursors !!
Hello All,
I am having a following program that perfectly runs but its taking very huge time to complete it.
Can any one suggest how i can improve the performace of this code ..
thanks in advance - appreciate your help .
Here's the program.
==============
procedure Proc_Fmly_VehicleTA_Cnt is
CURSOR c_cur_fmly IS SELECT FAMID, NUM_AUTO, NUM_TVAN, VEHQ, VEHQL FROM FMLY;
CURSOR c_cur_eovb_auto IS SELECT FAMID, VEHICIB ,VEHICYB FROM EOVB WHERE VEHICYB = gv_eovb_vehicyb_automobiles ;
CURSOR c_cur_eovb_trucks IS SELECT FAMID, VEHICIB ,VEHICYB FROM EOVB WHERE VEHICYB = gv_eovb_vehicyb_trucks ;
v_total_automobiles number := 0 ;
v_total_trucks number := 0 ;
v_procedure errorlog.procedure_name%TYPE default 'Proc_Fmly_VehicleTA_Cnt';
v_location errorlog.location%TYPE;
BEGIN
v_location := 4 ;
-- global variables gv_eovb_vehicyb_automobiles = 100 gv_eovb_vehicyb_trucks = 110
-- <<Computing the owned vehicles - automobiles >>
-- INNER BLOCK
BEGIN
FOR i IN c_cur_fmly LOOP
FOR j IN c_cur_eovb_auto LOOP
IF ( i.FAMID = j.FAMID ) THEN
v_total_automobiles := v_total_automobiles + chk_notnull_blank( j.vehicib);
END IF;
END LOOP ;
UPDATE FMLY SET NUM_AUTO = v_total_automobiles WHERE famid = i.famid ;
v_total_automobiles := 0;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
v_err_code := SQLCODE;
v_err_msg := substr(SQLERRM, 1, 200);
INSERT INTO audit_table (error_number, error_message) VALUES (v_err_code, v_err_msg);
error_logging(p_error_code => substr(sqlerrm,1,9), p_error_message => substr(sqlerrm,12), p_package => 'PKG_FCI_APP',p_procedure => 'Proc_Fmly_VehicleTA_Cnt' , p_location => v_location);
END;
-- <<Computing the owned vehicles - trucks >>
-- INNER BLOCK
BEGIN
FOR i IN c_cur_fmly LOOP
FOR j IN c_cur_eovb_trucks LOOP
IF ( i.FAMID = j.FAMID ) THEN
v_total_trucks := v_total_trucks + chk_notnull_blank( j.vehicib);
END IF;
END LOOP ;
UPDATE FMLY SET NUM_TVAN = v_total_trucks WHERE famid = i.famid ;
v_total_trucks := 0;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
v_err_code := SQLCODE;
v_err_msg := substr(SQLERRM, 1, 200);
INSERT INTO audit_table (error_number, error_message) VALUES (v_err_code, v_err_msg);
error_logging(p_error_code => substr(sqlerrm,1,9), p_error_message => substr(sqlerrm,12), p_package => 'PKG_FCI_APP',p_procedure => 'Proc_Fmly_Vehicle_Cnt' , p_location => v_location);
END;
-- END OUTER BLOCK
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
v_err_code := SQLCODE;
v_err_msg := substr(SQLERRM, 1, 200);
INSERT INTO audit_table (error_number, error_message) VALUES (v_err_code, v_err_msg);
error_logging(p_error_code => substr(sqlerrm,1,9), p_error_message => substr(sqlerrm,12), p_package => 'PKG_FCI_APP',p_procedure => 'Proc_Fmly_VehicleTA_Cnt ', p_location => v_location);
END Proc_Fmly_VehicleTA_Cnt;
-- ignore error_logging procedure ; its a part of package.
thanks/kumar
Edited by: kumar73 on Sep 17, 2010 9:36 AM
Edited by: kumar73 on Sep 17, 2010 9:37 AM
btw your exception handler has a couple of problems (I've formatted it for you):
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR
( -20001, 'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM );
v_err_code := SQLCODE;
v_err_msg := SUBSTR(SQLERRM, 1, 200);
INSERT INTO audit_table (error_number, error_message) VALUES (v_err_code, v_err_msg);
error_logging
( p_error_code => substr(sqlerrm,1,9)
, p_error_message => substr(sqlerrm,12)
, p_package => 'PKG_FCI_APP'
, p_procedure => 'Proc_Fmly_VehicleTA_Cnt'
, p_location => v_location ); When RAISE_APPLICATION_ERROR raises the exception, the procedure will terminate and the error logging steps below it won't get called.
Also if you just want to re-raise an exception without adding any information or your own message etc, then you should use RAISE, not RAISE_APPLICATION_ERROR. If you're going to use RAISE_APPLICATION_ERROR it should be something like:
RAISE_APPLICATION_ERROR
( -20001
, 'Could not set automobile count to ' || v_total_automobiles || ' for family ' || i.famid
, TRUE );Notice the last parameter, TRUE, which tells it to keep the existing error stack (i.e. whatever Oracle error made it fail), which will then appear underneath your custom error message. You should never concatenate SQLERRM into a RAISE_APPLICATION_ERROR message. (And SQLCODE is just the error number that is already part of SQLERRM so there is no point including that anyway.)
Those changes give you something like:
EXCEPTION
WHEN OTHERS THEN
INSERT INTO audit_table (error_number, error_message)
VALUES (SQLCODE, SUBSTR(SQLERRM,1,200)); -- btw why SUBSTR? Why not log the entire message?
error_logging
( p_error_code => substr(sqlerrm,1,9)
, p_error_message => substr(sqlerrm,12)
, p_package => 'PKG_FCI_APP'
, p_procedure => 'Proc_Fmly_VehicleTA_Cnt'
, p_location => v_location );
RAISE_APPLICATION_ERROR
( -20001
, 'Could not set automobile count to ' || v_total_automobiles || ' for family ' || i.famid
, TRUE );
Similar Messages
-
How to use BULK COLLECT in ref cursor?
hi,
can we use bulk collect in ref cursor ? if yes then please give small example ..
thanksTry this:
create or replace type person_ot as object (name varchar2(10)) not final;
create or replace type student_ot under person_ot (s_num number) not final;
create type person_tt as table of person_ot;
create table persons of person_ot;
declare
lv_person_list person_tt;
lv_sql varchar2(1000);
ref_cur sys_refcursor;
begin
lv_sql:= 'select new student_ot(''fred'', 100) from dual
union all
select new student_ot(''sally'', 200) from dual';
open ref_cur for lv_sql;
fetch ref_cur bulk collect into lv_person_list;
close ref_cur;
for i in lv_person_list.first..lv_person_list.last loop
dbms_output.put_line(lv_person_list(i).name );
end loop;
forall i in lv_person_list.first..lv_person_list.last
insert into persons values lv_person_list(i);
end;
/ -
How to use BULK COLLECT in oracle forms
hi gurus,
I am using oracle forms
Forms [32 Bit] Version 10.1.2.0.2 (Production)
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProductionI wanna use bulk collect from database table lets say <employees>
while working on database level with collections and records it's working very well for me, but when I try to use that technique on oracle forms it hits me error
error 591 this feature is not supported in client side programmingI know I can use cursors to loop through the records of oracle tables ,
but I'm convenient while using collections and arrays
for example
Set Serveroutput On
Declare
Type Rec_T Is Record (
Empid Number ,
Empname Varchar2(100)
Type V_R Is Table Of Rec_T Index By Binary_Integer;
V_Array V_R;
Begin
Select Employee_Id , First_Name
Bulk Collect
Into V_Array
From Employees;
For Indx In V_Array.First..V_Array.Last Loop
Dbms_Output.Put_Line('employees id '||V_Array(Indx).Empid ||'and the name is '||V_Array(Indx).Empname);
End Loop;
End;I wanna use this same way on oracle forms , for certain purposes , please guide me how can I use ...
thanks...For information, you can use and populate a collection within the Forms application without using the BULK COLLECT
Francoisactually I want to work with arrays , index tables ,
like
record_type (variable , variable2);
type type_name <record_type> index by binary_integer
type_variable type_name;
and in main body of program
select something
bulk collect into type_variable
from any_table;
loop
type_variable(indx).variable , type_variable(indx).variable2;
end loop;
this is very useful for my logic on which I am working
like
type_variable(indx).variable || type_variable(indx-1);
if it's possible with cursors then how can I use cursor that can fullfill my this logic@Francois
if it's possible then how can i populate without using bulk collect?
thanks
and for others replies: if I can use stored procedures please give me any example..
thanks -
How to use Bulk Collect and Forall
Hi all,
We are on Oracle 10g. I have a requirement to read from table A and then for each record in table A, find matching rows in table B and then write the identified information in table B to the target table (table C). In the past, I had used two ‘cursor for loops’ to achieve that. To make the new procedure, more efficient, I would like to learn to use ‘bulk collect’ and ‘forall’.
Here is what I have so far:
DECLARE
TYPE employee_array IS TABLE OF EMPLOYEES%ROWTYPE;
employee_data employee_array;
TYPE job_history_array IS TABLE OF JOB_HISTORY%ROWTYPE;
Job_history_data job_history_array;
BatchSize CONSTANT POSITIVE := 5;
-- Read from File A
CURSOR c_get_employees IS
SELECT Employee_id,
first_name,
last_name,
hire_date,
job_id
FROM EMPLOYEES;
-- Read from File B based on employee ID in File A
CURSOR c_get_job_history (p_employee_id number) IS
select start_date,
end_date,
job_id,
department_id
FROM JOB_HISTORY
WHERE employee_id = p_employee_id;
BEGIN
OPEN c_get_employees;
LOOP
FETCH c_get_employees BULK COLLECT INTO employee_data.employee_id.LAST,
employee_data.first_name.LAST,
employee_data.last_name.LAST,
employee_data.hire_date.LAST,
employee_data.job_id.LAST
LIMIT BatchSize;
FORALL i in 1.. employee_data.COUNT
Open c_get_job_history (employee_data(i).employee_id);
FETCH c_get_job_history BULKCOLLECT INTO job_history_array LIMIT BatchSize;
FORALL k in 1.. Job_history_data.COUNT LOOP
-- insert into FILE C
INSERT INTO MY_TEST(employee_id, first_name, last_name, hire_date, job_id)
values (job_history_array(k).employee_id, job_history_array(k).first_name,
job_history_array(k).last_name, job_history_array(k).hire_date,
job_history_array(k).job_id);
EXIT WHEN job_ history_data.count < BatchSize
END LOOP;
CLOSE c_get_job_history;
EXIT WHEN employee_data.COUNT < BatchSize;
END LOOP;
COMMIT;
CLOSE c_get_employees;
END;
When I run this script, I get
[Error] Execution (47: 17): ORA-06550: line 47, column 17:
PLS-00103: Encountered the symbol "OPEN" when expecting one of the following:
. ( * @ % & - + / at mod remainder rem select update with
<an exponent (**)> delete insert || execute multiset save
merge
ORA-06550: line 48, column 17:
PLS-00103: Encountered the symbol "FETCH" when expecting one of the following:
begin function package pragma procedure subtype type use
<an identifier> <a double-quoted delimited-identifier> form
current cursorWhat is the best way to code this? Once, I learn how to do this, I apply the knowledge to the real application in which file A would have around 200 rows and file B would have hundreds of thousands of rows.
Thank you for your guidance,
SeyedHello BlueShadow,
Following your advice, I modified a stored procedure that initially was using two cursor for loops to read from tables A and B to write to table C to use instead something like your suggestion listed below:
INSERT INTO tableC
SELECT …
FROM tableA JOIN tableB on (join condition).I tried this change on a procedure writing to tableC with keys disabled. I will try this against the real table that has primary key and indexes and report the result later.
Thank you very much,
Seyed -
How to use ZendAMF with multiple services?
I followed Mihai Corlan's tutorial (http://corlan.org/2008/11/13/flex-and-php-remoting-with-zend-amf/) to create a remote service with Zend AMF, and it works great.
But, I can't figure out how to use multiple RemoteObjects. I keep getting the infamous:
faultCode:Client.Error.DeliveryInDoubt faultString:'Channel disconnected' faultDetail:'Channel disconnected
before an acknowledgement was received'
I set up my second RemoteObject the same way that I set up my first one. But, I can't get it to work.
Any suggestions? Has anyone seen examples of multiple services being used?
Thank you!
-LaxmidiI made a stupid php error.
If you can do a single remote, you can do multiple ones. It's straightforward.
-Laxmidi -
How to use BULK COLLECT in Oracle Forms 11g
Forms is showing error that "Feature is not support in Client Side Program" when i am trying to impliment Bulk collect in Forms 11g.
i need to load full data from DB to my form becuase using cursor is very slow....
Is there any method/Work around to achieve this ....declare
type arr is table of emp%rowtype ;
lv_arr arr;
begin
select * bulk collect in to lv_arr from emp;
/*written code here to process the data and write in to file*/
end;Unless you are inserting/updating the data you are holding in the array into a database table I don't think there is much peformance gain in using bulk-collect in conjunction with writing a file. Bulk processing will increase performance by minimizing context switches from the SQL to the PL/SQL engine, nothing more, nothing less.
In any case bulk processing is not available in forms, if you really need to make use of it you need to do it in a stored procedure.
cheers -
How to use bulk insert in utl_file
i am creating text file of employee list i go huge data i want to use bulk insert with utl_file is it possible if so, how pls help me.
If what you are asking, in some unknown version of Oracle, is whether using FORALL will increase the speed for writing a file to your hard disk the answer is no.
BULK COLLECT, however, might help. -
How to use BULK COLLECT, FORALL and TREAT
There is a need to read match and update data from and into a custom table. The table would have about 3 millions rows and holds key numbers. BAsed on a field value of this custom table, relevant data needs to be fetched from joins of other tables and updated in the custom table. I plan to use BULK COLLECT and FORALL.
All examples I have seen, do an insert into a table. How do I go about reading all values of a given field and fetching other relevant data and then updating the custom table with data fetched.
Defined an object with specifics like this
CREATE OR REPLACE TYPE imei_ot AS OBJECT (
recid NUMBER,
imei VARCHAR2(30),
STORE VARCHAR2(100),
status VARCHAR2(1),
TIMESTAMP DATE,
order_number VARCHAR2(30),
order_type VARCHAR2(30),
sku VARCHAR2(30),
order_date DATE,
attribute1 VARCHAR2(240),
market VARCHAR2(240),
processed_flag VARCHAR2(1),
last_update_date DATE
Now within a package procedure I have defined like this.
type imei_ott is table of imei_ot;
imei_ntt imei_ott;
begin
SELECT imei_ot (recid,
imei,
STORE,
status,
TIMESTAMP,
order_number,
order_type,
sku,
order_date,
attribute1,
market,
processed_flag,
last_update_date
BULK COLLECT INTO imei_ntt
FROM (SELECT stg.recid, stg.imei, cip.store_location, 'S',
co.rtl_txn_timestamp, co.rtl_order_number, 'CUST',
msi.segment1 || '.' || msi.segment3,
TRUNC (co.txn_timestamp), col.part_number, 'ZZ',
stg.processed_flag, SYSDATE
FROM custom_orders co,
custom_order_lines col,
custom_stg stg,
mtl_system_items_b msi
WHERE co.header_id = col.header_id
AND msi.inventory_item_id = col.inventory_item_id
AND msi.organization_id =
(SELECT organization_id
FROM hr_all_organization_units_tl
WHERE NAME = 'Item Master'
AND source_lang = USERENV ('LANG'))
AND stg.imei = col.serial_number
AND stg.processed_flag = 'U');
/* Update staging table in one go for COR order data */
FORALL indx IN 1 .. imei_ntt.COUNT
UPDATE custom_stg
SET STORE = TREAT (imei_ntt (indx) AS imei_ot).STORE,
status = TREAT (imei_ntt (indx) AS imei_ot).status,
TIMESTAMP = TREAT (imei_ntt (indx) AS imei_ot).TIMESTAMP,
order_number = TREAT (imei_ntt (indx) AS imei_ot).order_number,
order_type = TREAT (imei_ntt (indx) AS imei_ot).order_type,
sku = TREAT (imei_ntt (indx) AS imei_ot).sku,
order_date = TREAT (imei_ntt (indx) AS imei_ot).order_date,
attribute1 = TREAT (imei_ntt (indx) AS imei_ot).attribute1,
market = TREAT (imei_ntt (indx) AS imei_ot).market,
processed_flag =
TREAT (imei_ntt (indx) AS imei_ot).processed_flag,
last_update_date =
TREAT (imei_ntt (indx) AS imei_ot).last_update_date
WHERE recid = TREAT (imei_ntt (indx) AS imei_ot).recid
AND imei = TREAT (imei_ntt (indx) AS imei_ot).imei;
DBMS_OUTPUT.put_line ( TO_CHAR (SQL%ROWCOUNT)
|| ' rows updated using Bulk Collect / For All.'
EXCEPTION
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.put_line ('No Data: ' || SQLERRM);
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('Other Error: ' || SQLERRM);
END;
Now for the unfortunate part. When I compile the pkg, I face an error
PL/SQL: ORA-00904: "LAST_UPDATE_DATE": invalid identifier
I am not sure where I am wrong. Object type has the last update date field and the custom table also has the same field.
Could someone please throw some light and suggestion?
Thanks
udsI suspect your error comes from the »bulk collect into« and not from the »forall loop«.
From a first glance you need to alias sysdate with last_update_date and some of the other select items need to be aliased as well :
But a simplified version would be
select imei_ot (stg.recid,
stg.imei,
cip.store_location,
'S',
co.rtl_txn_timestamp,
co.rtl_order_number,
'CUST',
msi.segment1 || '.' || msi.segment3,
trunc (co.txn_timestamp),
col.part_number,
'ZZ',
stg.processed_flag,
sysdate
bulk collect into imei_ntt
from custom_orders co,
custom_order_lines col,
custom_stg stg,
mtl_system_items_b msi
where co.header_id = col.header_id
and msi.inventory_item_id = col.inventory_item_id
and msi.organization_id =
(select organization_id
from hr_all_organization_units_tl
where name = 'Item Master' and source_lang = userenv ('LANG'))
and stg.imei = col.serial_number
and stg.processed_flag = 'U';
... -
How to use OSD with Multiple DPs to remote locations
Hi
My SCCM 2012 R2 Primary site is located on my corporate office but i need to use OSD for multiple branch locations in different subnets.in My Organization there is network level DHCP server rather than Windows DHCP...
What would be the complete configuration in this case .. can some one provide the steps..
Shailendra DevHi,
The best way to forward the PXE boot requests to the DP/PXE server is to use IP Helpers in the routers/switches. I assume that the branch locations are without a DP. You can use DHCP scope options in the DHCP servers as well but you will end up with problems
when PXE-booting machines that run UEFI becuase it is not the same bootfile used and it is not really supported.
Maybe standalone media could be an option where you have the most of the TS on a USB stick/Drive.
Regards,>
Jörgen
-- My System Center blog ccmexec.com -- Twitter
@ccmexec -
How to use synonyms on multiple word search ?
We use context with multiword search like this one :
select * from my_table where contains(my_text,'the small building near the river')>0
Now we have specific synonyms in a thesaurus. How do we write the contains clause ?
contains(my_text,'syn(the,thes) and syn(small,thes) and syn(building,thes) and syn(near,thes) and syn (river,thes)')>0 does not fin the synonym for "small building"="house" for instance
contains(my_text,'syn(the small building near the river,thes)')>0 does only for synonyms on the full sentence.
More generally is there an Oracle Document which describes how to use SYN, FUZZY and combine them, since
the reference documentation gives only limited information on this ?
Have a nice dayThe thesaurus functionality is not currently built for stuff like this.
if you want to combine fuzzy and thesaurus, I am assuming you want to do fuzzy first, to correct any misspelling,
then thesaurus on the "corrected" spellings? You'd have to do something like:
1. take the query and run ctx_query.explain to break it down and do the fuzzy expansion
2. work through the fuzzy expansion and build a new query string by sticking SYN() around each
expanded word
As for thesaurus expansion and phrase, these are not compatible. Thesaurus expansions use "," and "|", and so
you cannot have a phrase of thesaurus expansions.
I see what you're getting at, but you would need sub phrase detection, phrase equivalence, etc., which is
currently beyond the thesaurus function capability.
You can use themes (ABOUT) on phrases, and it will do something like what you are describing. You might want
to check that out. -
How to use BULK INSERT for a data from a cursor?
Oracle 10G enterprise edition.
I tried to Bulk insert datas returning from a cursor, its returning error.
PLS-00302: component 'LAST' must be declared
I need some help to use the Bulk INSERT here.Can any one help me to specify what error i have made?
CREATE OR REPLACE PROCEDURE HOT_ADMIN.get_search_keyword_stats_prc
IS
CURSOR c_get_scenarios
IS
SELECT a.*,ROWNUM rnum
FROM (
SELECT TRUNC(r.search_date) sdate,
r.search_hits hits,
r.search_type stype,
r.search_qualification qual,
r.search_location loc,
r.search_town stown,
r.search_postcode pcode,
r.search_college college,
r.search_colname colname,
r.search_text text,
r.affiliate_id affiliate,
r.search_study_mode smode,
r.location_hint hint,
r.search_posttown ptown,
COUNT(1) cnt
FROM w_search_headers r
WHERE search_text IS NOT NULL
AND NVL(search_type,' ') <> 'C'
AND TRUNC(search_date)= TO_DATE(TO_CHAR(SYSDATE-1,'DD-MON-RRRR'))
GROUP BY TRUNC(r.search_date),
r.search_hits,
r.search_type,
r.search_qualification,
r.search_location,
r.search_town,
r.search_postcode,
r.search_college,
r.search_colname,
r.search_text,
r.affiliate_id,
r.search_study_mode,
r.location_hint,
r.search_posttown
ORDER BY cnt desc
) a
WHERE ROWNUM <=1000;
lc_get_data c_get_scenarios%ROWTYPE;
BEGIN
OPEN c_get_scenarios;
FETCH c_get_scenarios into lc_get_data;
CLOSE c_get_scenarios;
FORALL i IN 1..lc_get_data.last
INSERT INTO W_SEARCH_SCENARIO_STATS VALUES ( i.sdate,
i.hits,
i.stype,
i.qual,
i.loc,
i.stown,
i.pcode,
i.college,
i.colname,
i.text,
i.affiliate,
i.smode,
i.hint,
i.ptown,
i.cnt
COMMIT;
END;This isn't what you asked, but I've generally found it helpful to list the columns in an INSERT statement before the values. It is of course optional, but useful for reference when looking at the statement later
-
How to use Ajax Get Multiple Values in Tabular form?
Hi All-
I am trying to use AJAX to get multiple values in tabular form by using Denes Kubicek's example in the following link -
http://apex.oracle.com/pls/otn/f?p=31517:239:9172467565606::NO:::
Basically, I want to use the drop down list to populate rest of the values on the form.
I have created the example(Ajax Get Multiple Values, application 54522) on Oracle site -
http://apex.oracle.com/pls/apex/f?p=4550:1:0:::::
Workspace: iConnect
login: demo
password: demo
I was able to duplicate his example on page 1 (home page).
However, I want to use system generate tabular form to finish this example, and was not able to populate the data correctly.
Page 2 (method 2) is the one that I am having trouble to populate the column values. When I checked application item values in Session, and the values seems to be populated correctly.
This is what I have done on this page:
1. Create an Application Process On Demand - Set_Multi_Items_Tabular2:
DECLARE
v_subject my_book_store.subject%TYPE;
v_price my_book_store.price%TYPE;
v_author my_book_store.author%TYPE;
v_qty NUMBER;
CURSOR cur_c
IS
SELECT subject, price, author, 1 qty
FROM my_book_store
WHERE book_id = :temporary_application_item2;
BEGIN
FOR c IN cur_c
LOOP
v_subject := c.subject;
v_price := c.price;
v_author := c.author;
v_qty := c.qty;
END LOOP;
OWA_UTIL.mime_header ('text/xml', FALSE);
HTP.p ('Cache-Control: no-cache');
HTP.p ('Pragma: no-cache');
OWA_UTIL.http_header_close;
HTP.prn ('<body>');
HTP.prn ('<desc>this xml genericly sets multiple items</desc>');
HTP.prn ('<item id="f04_' || :t_rownum || '">' || v_subject || '</item>');
HTP.prn ('<item id="f05_' || :t_rownum || '">' || v_price || '</item>');
HTP.prn ('<item id="f06_' || :t_rownum || '">' || v_author || '</item>');
HTP.prn ('<item id="f07_' || :t_rownum || '">' || v_qty || '</item>');
HTP.prn ('</body>');
END;
2. Create two application items - TEMPORARY_APPLICATION_ITEM2, T_ROWNUM2
3. Put the following in the Page Header:
<script language="JavaScript" type="text/javascript">
function f_set_multi_items_tabular2(pValue, pRow){
var get = new htmldb_Get(null,html_GetElement('pFlowId').value,
'APPLICATION_PROCESS=Set_Multi_Items_Tabular2',0);
if(pValue){
get.add('TEMPORARY_APPLICATION_ITEM2',pValue)
get.add('T_ROWNUM2',pRow)
}else{
get.add('TEMPORARY_APPLICATION_ITEM2','null')
gReturn = get.get('XML');
if(gReturn){
var l_Count = gReturn.getElementsByTagName("item").length;
for(var i = 0;i<l_Count;i++){
var l_Opt_Xml = gReturn.getElementsByTagName("item")[i];
var l_ID = l_Opt_Xml.getAttribute('id');
var l_El = html_GetElement(l_ID);
if(l_Opt_Xml.firstChild){
var l_Value = l_Opt_Xml.firstChild.nodeValue;
}else{
var l_Value = '';
if(l_El){
if(l_El.tagName == 'INPUT'){
l_El.value = l_Value;
}else if(l_El.tagName == 'SPAN' && l_El.className == 'grabber'){
l_El.parentNode.innerHTML = l_Value;
l_El.parentNode.id = l_ID;
}else{
l_El.innerHTML = l_Value;
get = null;
</script>
Add the follwing to the end of the above JavaScript:
<script language="JavaScript" type="text/javascript">
function setLOV(filter, list2)
var s = filter.id;
var item = s.substring(3,8);
var field2 = list2 + item;
f_set_multi_items_tabular2(filter, field2);
4. Tabular form query:
select
"BOOK_ID",
"BOOK",
"SUBJECT",
"PRICE",
"AUTHOR",
"QTY",
"BOOK_ID" BOOK_ID_DISPLAY
from "#OWNER#"."MY_BOOK_STORE"
5. In Book_ID_DISPLAY column attribute:
Add the following code to element attributes: onchange="javascript:f_set_multi_items_tabular2(this.value,'#ROWNUM#');"
Changed to -> onchange="javascript:setLOV(this,'f03');"
Now, T_ROWNUM2 returns value as f03_0001. But, TEMPORARY_APPLICATION_ITEM2 returns as [object HTMLSelectElement]...
Please help me to see how I can populate the data with this tabular form format. Thanks a lot in advanced!!!
Ling
Updated code in Red..Ling
Lets start with looking at what the javascript code is doing.
function f_set_multi_items_tabular(pValue, pRow){
/*This will initiate the url for the demand process to run*/
var get = new htmldb_Get(null,html_GetElement('pFlowId').value,
'APPLICATION_PROCESS=Set_Multi_Items_Tabular',0);
if(pValue){
/*If there is an value than submit item name with value*/
get.add('TEMPORARY_APPLICATION_ITEM',pValue)
get.add('T_ROWNUM',pRow)
}else{
/*Else set the item TEMPORARY_APPLICATION_ITEM to null*/
get.add('TEMPORARY_APPLICATION_ITEM','null')
/*Submit the url and te returned document is of type XML*/
gReturn = get.get('XML');
if(gReturn){
/*There is something returned*/
var l_Count = gReturn.getElementsByTagName("item").length;
/*For all elements of the tag item*/
for(var i = 0;i<l_Count;i++){
/*Get the item out of the XML*/
var l_Opt_Xml = gReturn.getElementsByTagName("item")[i];
/*Get the id of the item*/
var l_ID = l_Opt_Xml.getAttribute('id');
/*Get the element in the original page with the same id as
**the item we have in the XML produced by the ondemand process
var l_El = html_GetElement(l_ID);
/*Now get the value of the item form the XML*/
if(l_Opt_Xml.firstChild){
var l_Value = l_Opt_Xml.firstChild.nodeValue;
}else{
/*There is no value*/
var l_Value = '';
if(l_El){
/*There is an element with the same id as the item we are processing*/
if(l_El.tagName == 'INPUT'){
/*The element is an input item just set the value*/
l_El.value = l_Value;
}else if(l_El.tagName == 'SPAN' && l_El.className == 'grabber'){
/*If it is a span elment and has the class grabber
**Then set the innerHTML of the parent to the value
**and the id of the parent to the id
l_El.parentNode.innerHTML = l_Value;
l_El.parentNode.id = l_ID;
}else{
/*Else set the value as innerHTML*/
l_El.innerHTML = l_Value;
get = null;
Now where it went wrong in your initial post
The XML that was returned by your XML process would be something like
<body>
<desc>this xml genericly sets multiple items</desc>
<item id="f02_1">CSS Mastery</item>
<item id="f03_1">22</item>
<item id="f04_1">Andy Budd</item>
<item id="f05_1">1</item>
</body>
When you don't use apex_item to create your tabular form a item in the table will look like
<input id="f02_0001" type="text" value="CSS Mastery" maxlength="2000" size="16" name="f05" autocomplete="off">
Notice the id's f02_1 and f02_0001 don't match.
So to make it work the XML would have to look like
<body>
<desc>this xml genericly sets multiple items</desc>
<item id="f02_0001">CSS Mastery</item>
<item id="f03_0001">22</item>
<item id="f04_0001">Andy Budd</item>
<item id="f05_0001">1</item>
</body>
To do that simply use lpad in the ondemand process like
HTP.prn ('<item id="f02_' || lpad(:t_rownum,4,'0') || '">' || v_subject || '</item>');
HTP.prn ('<item id="f03_' || lpad(:t_rownum,4,'0') || '">' || v_price || '</item>');
HTP.prn ('<item id="f04_' || lpad(:t_rownum,4,'0') || '">' || v_author || '</item>');
HTP.prn ('<item id="f05_' || lpad(:t_rownum,4,'0') || '">' || v_qty || '</item>');
Keep in mind that the above is based on your original post and #ROWNUM# not being lpadded with zero's.
Nicolette -
How to use bulk collect into clause
hi all,
i have requirement like this i want to change the query by passing the different table names in oracle database 10gr2.
like if i use first i pass the scott.emp table name select * from scott.emp;
then i want pass scott.dept table name select * from scott.dept;
using select * option in the select list.
how can i execute it.
give me any solution.
please reply....Hi,
i recently also ran into some serious trouble to make dynamic sql work.
It was about parallel pipelined function with strongly typed cursor (for "partition ... by hash(...)").
But in addition requiring dynamic SQL for the input to this cursor.
I couldn't make it work with execute immediate or something else.
So i used another way - I translated dynamic SQL into dynamically created static SQL:
1. create a base SQL data object type with abstract interface for code (e.g. some Execute() member function).
2. dynamically create a derived SQL data object type with concrete implementation of Execute() holding your "dynamic SQL" "in a static way"
3. delegate to Execute().
Let me quote my example from comp.databases.oracle.server, thread "dynamically created cursor doesn't work for parallel pipelined functions"
- pls. see below (it's an old one - with likely some odd stuff inside).
It might sound some kind of strange for DB programmer.
(I come from C++. Though this is not an excuse smile)
Maybe i just missed another possible option to handle the problem.
And it's a definitely verbose.
But i think it's at least a (last) option.
Actually i would be interested to hear, what others think about it.
best regards,
Frank
--------------- snip -------------------------
drop table parallel_test;
drop type MyDoit;
drop type BaseDoit;
drop type ton;
create type ton as table of number;
CREATE TABLE parallel_test (
id NUMBER(10),
description VARCHAR2(50)
BEGIN
FOR i IN 1 .. 100000 LOOP
INSERT INTO parallel_test (id, description)
VALUES (i, 'Description or ' || i);
END LOOP;
COMMIT;
END;
create or replace type BaseDoit as object (
id number,
static function make(p_id in number)
return BaseDoit,
member procedure doit(
p_sids in out nocopy ton,
p_counts in out nocopy ton)
) not final;
create or replace type body BaseDoit as
static function make(p_id in number)
return BaseDoit
is
begin
return new BaseDoit(p_id);
end;
member procedure doit(
p_sids in out nocopy ton,
p_counts in out nocopy ton)
is
begin
dbms_output.put_line('BaseDoit.doit(' || id || ') invoked...');
end;
end;
-- Define a strongly typed REF CURSOR type.
CREATE OR REPLACE PACKAGE parallel_ptf_api AS
TYPE t_parallel_test_row IS RECORD (
id1 NUMBER(10),
desc1 VARCHAR2(50),
id2 NUMBER(10),
desc2 VARCHAR2(50),
sid NUMBER
TYPE t_parallel_test_tab IS TABLE OF t_parallel_test_row;
TYPE t_parallel_test_ref_cursor IS REF CURSOR RETURN
t_parallel_test_row;
FUNCTION test_ptf (p_cursor IN t_parallel_test_ref_cursor)
RETURN t_parallel_test_tab PIPELINED
PARALLEL_ENABLE(PARTITION p_cursor BY any);
END parallel_ptf_api;
SHOW ERRORS
CREATE OR REPLACE PACKAGE BODY parallel_ptf_api AS
FUNCTION test_ptf (p_cursor IN t_parallel_test_ref_cursor)
RETURN t_parallel_test_tab PIPELINED
PARALLEL_ENABLE(PARTITION p_cursor BY any)
IS
l_row t_parallel_test_row;
BEGIN
LOOP
FETCH p_cursor
INTO l_row;
EXIT WHEN p_cursor%NOTFOUND;
select userenv('SID') into l_row.sid from dual;
PIPE ROW (l_row);
END LOOP;
RETURN;
END test_ptf;
END parallel_ptf_api;
SHOW ERRORS
PROMPT
PROMPT Serial Execution
PROMPT ================
SELECT sid, count(*)
FROM TABLE(parallel_ptf_api.test_ptf(CURSOR(SELECT t1.id,
t1.description, t2.id, t2.description, null
FROM parallel_test t1,
parallel_test t2
where t1.id = t2.id
) t2
GROUP BY sid;
PROMPT
PROMPT Parallel Execution
PROMPT ==================
SELECT sid, count(*)
FROM TABLE(parallel_ptf_api.test_ptf(CURSOR(SELECT /*+
parallel(t1,5) */ t1.id, t1.description, t2.id, t2.description, null
FROM parallel_test t1,
parallel_test t2
where t1.id = t2.id
) t2
GROUP BY sid;
PROMPT
PROMPT Parallel Execution 2
PROMPT ==================
set serveroutput on;
declare
v_sids ton := ton();
v_counts ton := ton();
-- v_cur parallel_ptf_api.t_parallel_test_ref_cursor;
v_cur sys_refcursor;
procedure OpenCursor(p_refCursor out sys_refcursor)
is
begin
open p_refCursor for 'SELECT /*+ parallel(t1,5) */ t1.id,
t1.description, t2.id, t2.description, null
FROM parallel_test t1,
parallel_test t2
where t1.id = t2.id';
end;
begin
OpenCursor(v_cur);
SELECT sid, count(*) bulk collect into v_sids, v_counts
FROM TABLE(parallel_ptf_api.test_ptf(v_cur)) t2
GROUP BY sid;
for i in v_sids.FIRST.. v_sids.LAST loop
dbms_output.put_line (v_sids(i) || ', ' || v_counts(i));
end loop;
end;
PROMPT
PROMPT Parallel Execution 3
PROMPT ==================
set serveroutput on;
declare
instance BaseDoit;
v_sids ton := ton();
v_counts ton := ton();
procedure CreateMyDoit
is
cmd varchar2(4096 char);
begin
cmd := 'create or replace type MyDoit under BaseDoit ( ' ||
' static function make(p_id in number) ' ||
' return MyDoit, ' ||
' overriding member procedure doit( ' ||
' p_sids in out nocopy ton, ' ||
' p_counts in out nocopy ton) ' ||
execute immediate cmd;
cmd := 'create or replace type body MyDoit as ' ||
' static function make(p_id in number) ' ||
' return MyDoit ' ||
' is ' ||
' begin ' ||
' return new MyDoit(p_id); ' ||
' end; ' ||
' ' ||
' overriding member procedure doit( ' ||
' p_sids in out nocopy ton, ' ||
' p_counts in out nocopy ton) ' ||
' is ' ||
' begin ' ||
' dbms_output.put_line(''MyDoit.doit('' || id || '')
invoked...''); ' ||
' SELECT sid, count(*) bulk collect into p_sids, p_counts ' ||
' FROM TABLE(parallel_ptf_api.test_ptf(CURSOR( ' ||
' SELECT /*+ parallel(t1,5) */ t1.id, t1.description,
t2.id, t2.description, null ' ||
' FROM parallel_test t1, parallel_test t2 ' ||
' where t1.id = t2.id ' ||
' ))) ' ||
' GROUP BY sid; ' ||
' end; ' ||
' end; ';
execute immediate cmd;
end;
begin
CreateMyDoit;
execute immediate 'select MyDoit.Make(11) from dual' into instance;
instance.doit(v_sids, v_counts);
if v_sids.COUNT > 0 then
for i in v_sids.FIRST.. v_sids.LAST loop
dbms_output.put_line (v_sids(i) || ', ' || v_counts(i));
end loop;
end if;
end;
--------------- snap ------------------------- -
How to use DirectCast for multiple selected rows?
Hi<o:p></o:p>
Me.SecondBindingSource.DataSource = DirectCast(parentForm.FirstBindingSource.Current, DataRowView) works perfect for single items but how do I do it if I've selected multiple rows on datagridOne and want to pass only the selected rows to datagridTwo using DirectCast?
Me.SecondBindingSource.DataSource = DirectCast(main.FirstBindingSource.Current, DataRowCollection) does not work??<o:p></o:p>You have to put the rows into a datatable. It is usually best if your original source is a datatable. The filter the original datatable. The selected rows of the datagrid are the same row numbers in the source datatable.
jdweng -
How to use IWEB for multiple websites?
Okay.
I have two websites. One on a 3rd party, one on .MAC.
Computer 1 = .MAC website
Computer 2= 3rd party website
I want to use computer 2 to edit my .MAC website and moved the DOMAIN file but haven't open it in iWEB on the second computer as I need to know how to open and not destroy the 3rd party website.
How is this done?
Thanks.You can rename the domain file to something descriptive of the site and open them manually. But I find it much safer to use iWebSites for managing multiple sites, over 25. I use iWebSites to manage multiple sites.. It lets me create multiple sites and multiple domain files.
If you have multiple sites in one domain file here's the workflow I used to split them into individual site files with iWebSites. Be sure to make a backup copy of your original Domain.sites files before starting the splitting process.
This lets me edit several sites and only republish the one I want.
Maybe you are looking for
-
When i try to import the databse to test server it is taking lot of time,around even after 2 hr..imp is not starting can anybody suggest me the same... {\code\} F:\Documents and Settings\deepali>imp system/deepali file=G:\16-08-08\fullsunsun day1.DMP
-
I am working on an application in Apex 3.2 and there is an IR that has a button <Export toExcel> that appears after the report is rendered. The button is template based that calls a url. The url is ir_csv_download();. When executed from this page it
-
I have a disc with hundreds of pdfs. I want to group them and print in order at a specified printer setting. (as opposed to opening them one at a time) Do I need special program / download? How can I do this.
-
Error 8 in iChat....but Skype works - any suggestions?
Hi everyone. I'm having trouble connecting to contacts I have been able to reach before. I have moved and am connected to a network someone left open somewhere in my neighbourhood..... Everytime I try connecting to a contact for a video or audiochat
-
What are the materials used in an iPad?
I would like to know the amount and all the chemicals, metals, and plastics that are used in creating the iPad. Thank you.