How to optimize the select query that is executed in a cursor for loop?
Hi Friends,
I have executed the code below and clocked the times for every line of the code using DBMS_PROFILER.
CREATE OR REPLACE PROCEDURE TEST
AS
p_file_id NUMBER := 151;
v_shipper_ind ah_item.shipper_ind%TYPE;
v_sales_reserve_ind ah_item.special_sales_reserve_ind%TYPE;
v_location_indicator ah_item.exe_location_ind%TYPE;
CURSOR activity_c
IS
SELECT *
FROM ah_activity_internal
WHERE status_id = 30
AND file_id = p_file_id;
BEGIN
DBMS_PROFILER.start_profiler ('TEST');
FOR rec IN activity_c
LOOP
SELECT DISTINCT shipper_ind, special_sales_reserve_ind, exe_location_ind
INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
FROM ah_item --464000 rows in this table
WHERE item_id_edw IN (
SELECT item_id_edw
FROM ah_item_xref --700000 rows in this table
WHERE item_code_cust = rec.item_code_cust
AND facility_num IN (
SELECT facility_code
FROM ah_chain_div_facility --17 rows in this table
WHERE chain_id = ah_internal_data_pkg.get_chain_id (p_file_id)
AND div_id = (SELECT div_id
FROM ah_div --8 rows in this table
WHERE division = rec.division)));
END LOOP;
DBMS_PROFILER.stop_profiler;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN TOO_MANY_ROWS
THEN
NULL;
END TEST;The SELECT query inside the cursor FOR LOOP took 773 seconds.
I have tried using BULK COLLECT instead of cursor for loop but it did not help.
When I took out the select query separately and executed with a sample value then it gave the results in a flash of second.
All the tables have primary key indexes.
Any ideas what can be done to make this code perform better?
Thanks,
Raj.
As suggested I'd try merging the queries into a single SQL. You could also rewrite your IN clauses as JOINs and see if that helps, e.g.
SELECT DISTINCT ai.shipper_ind, ai.special_sales_reserve_ind, ai.exe_location_ind
INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
FROM ah_item ai, ah_item_xref aix, ah_chain_div_facility acdf, ah_div ad
WHERE ai.item_id_edw = aix.item_id_edw
AND aix.item_code_cust = rec.item_code_cust
AND aix.facility_num = acdf.facility_code
AND acdf.chain_id = ah_internal_data_pkg.get_chain_id (p_file_id)
AND acdf.div_id = ad.div_id
AND ad.division = rec.division;ALSO: You are calling ah_internal_data_pkg.get_chain_id (p_file_id) every time. Why not do it outside the loop and just use a variable in the inner query? That will prevent context switching and improve speed.
Edited by: Dave Hemming on Dec 3, 2008 9:34 AM
Similar Messages
-
How to insert the select query result into table?
How to insert the select query result into table?
SELECT top 20 creation_time
,last_execution_time
,total_physical_reads
,total_logical_reads
,total_logical_writes
, execution_count
, total_worker_time
, total_elapsed_time
, total_elapsed_time / execution_count avg_elapsed_time
,SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,
((CASE statement_end_offset
WHEN -1 THEN DATALENGTH(st.text)
ELSE qs.statement_end_offset END
- qs.statement_start_offset)/2) + 1) AS statement_text
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st
ORDER BY total_elapsed_time / execution_count DESC;
Thanks,
Tirumala1. SELECT INTO
Below method will create table when data is inserted from one table to another table. Its useful when you need exactly same datatype as source table.
Use AdventureWorks2008R2;
Go
---Insert data using SELECT INTO
SELECT AddressLine1, City
INTO BothellAddresses
FROM Person.Address
where City = 'Bothell';
GO
---VERIFY DATA
Select AddressLine1, City
FROM BothellAddresses
---DROP TABLE
DROP TABLE BothellAddresses
GO
2. INSERT INTO SELECT
Below method will need table to be created prior to inserting data. Its really useful when table is already created and you want insert data from
another table.
Use AdventureWorks2008R2;
Go
---Create Table
CREATE TABLE BothellAddresses (AddressLine1 NVARCHAR(60), City NVARCHAR(30))
---Insert into above table using SELECT
INSERT INTO BothellAddresses(AddressLine1, City)
SELECT AddressLine1, City
FROM Person.Address
where City = 'Bothell';
---VERIFY DATA
Select AddressLine1, City
FROM BothellAddresses
---DROP TABLE
DROP TABLE BothellAddresses
GO
Regards,
Vishal Patel
Blog: http://vspatel.co.uk
Site: http://lehrity.com -
Replace the following open/fetch/close statements with a cursor FOR loop
Hi anyone could you please help me,
I would like to replace the following open/fetch/close statements with a cursor FOR loop.
Codes are:
CREATE OR REPLACE PROCEDURE COMOES.orchid_shipment_interface IS
-- get the com shipment header records
CURSOR c_com_shphdr ( p_dwn_end_dt DATE ) IS
SELECT custno client_id
, plheadno plheadno
, DECODE(carr_no,'FEDX',lading_no,'UPS',lading_no,carrier_pro_no) tracking_no
, carr_no||'/'||carr_method carrier_id
, plantid plant_id
, carr_no
, lading_no
, del_custaddr ship_to_id
, ol_type cfm_order_type
, del_custno
, shipterm freight_terms
, del_custattn attn_line
, custaddr
FROM com_plhead@com_pricing.world
WHERE status = '9'
AND (mod_dat) > p_dwn_end_dt;
-- get the com shipment address records
CURSOR c_com_shpadr (p_custaddr VARCHAR2) IS
SELECT name1 addr_name
, street1 addr_line1
, street2 addr_line2
, city city
, state state_cd
, zip zip
, country country_cd
, phone work_phone
, email email1
FROM com_address@com_pricing.world
WHERE addr_id = p_custaddr;
-- get the com shipment detail records
CURSOR c_com_shpdtl ( p_plheadno NUMBER) IS
SELECT pll.plheadno pllheadno
, pll.pllineno ord_line_no
, pll.ol_no erp_line_no
, pll.ol_segno
, pll.fg_id sku
, pll.qty_shipped ship_qty
, pll.ordno erp_ord_no
FROM com_plline@com_pricing.world pll
WHERE pll.plheadno = p_plheadno
AND NOT EXISTS (SELECT '1'
FROM com_pkg_int_interface@com_pricing.world cpi
WHERE pll.ordno = cpi.ordno
AND pll.ol_no = cpi.ol_no);
-- type declaration
-- type declaration of com table.
TYPE t_com_shphdr IS TABLE OF c_com_shphdr%ROWTYPE INDEX BY BINARY_INTEGER;
TYPE t_orchid_shphdr IS TABLE OF orchid_shipment_hdr_intf%ROWTYPE INDEX BY BINARY_INTEGER;
TYPE t_com_shpadr IS TABLE OF c_com_shpadr%ROWTYPE INDEX BY BINARY_INTEGER;
TYPE t_orchid_shpadr IS TABLE OF orchid_shipment_address_intf%ROWTYPE INDEX BY BINARY_INTEGER;
TYPE t_com_shpdtl IS TABLE OF c_com_shpdtl%ROWTYPE INDEX BY BINARY_INTEGER;
TYPE t_orchid_shpdtl IS TABLE OF orchid_shipment_dtl_intf%ROWTYPE INDEX BY BINARY_INTEGER;
lv_company_code com_customer.business_unit%TYPE;
lv_erp_ord_no com_plline.ordno%TYPE;
lv_actual_ship_date com_plline.confirm_date%TYPE;
lv_po_no com_oline.po_no%TYPE;
lv_ord_date com_oline.entrydate%TYPE;
lv_hdr_batch_ctrl_no download_batch_info.batch_ctrl_no%TYPE;
lv_adr_batch_ctrl_no download_batch_info.batch_ctrl_no%TYPE;
lv_dtl_batch_ctrl_no download_batch_info.batch_ctrl_no%TYPE;
lv_sku_desc com_salesitem.title%TYPE;
lv_ord_qty com_oldelseg.qty%TYPE;
lr_com_shphdr t_com_shphdr;
lr_orchid_shphdr t_orchid_shphdr;
lr_com_shpadr t_com_shpadr;
lr_orchid_shpadr t_orchid_shpadr;
lr_com_shpdtl t_com_shpdtl;
lr_orchid_shpdtl t_orchid_shpdtl;
-- variable declaration
ln_shphdr_seq NUMBER(10):= 0;
ln_shpadr_seg NUMBER(10):= 0;
ln_shpdtl_seq NUMBER(10):= 0;
cnt NUMBER(10):= 0;
cnt1 NUMBER(10):= 0;
ld_hdr_dwn_end_dt download_batch_info.download_end_tstamp%TYPE;
lc_hdr_dwn_status download_batch_info.dwn_status%TYPE;
ld_hdr_download_end_tstamp DATE;
ln_hdr_running_seq NUMBER(10) := 0;
ld_adr_dwn_end_dt download_batch_info.download_end_tstamp%TYPE;
lc_adr_dwn_status download_batch_info.dwn_status%TYPE;
ld_adr_download_end_tstamp DATE;
ln_adr_running_seg NUMBER(10) := 0;
ld_dtl_dwn_end_dt download_batch_info.download_end_tstamp%TYPE;
lc_dtl_dwn_status download_batch_info.dwn_status%TYPE;
ld_dtl_download_end_tstamp DATE;
ln_dtl_running_seq NUMBER(10) := 0;
BEGIN
-- get the batch control number details from batch information table for shipment header
BEGIN
SELECT batch_ctrl_no
, NVL(download_end_tstamp,TO_DATE('01/01/1980','MM/DD/YYYY'))
, dwn_status
INTO lv_hdr_batch_ctrl_no
, ld_hdr_dwn_end_dt
, lc_hdr_dwn_status
FROM comoes.download_batch_info
WHERE download_id = 'ORCHID_SHIPMENT_HDR_INTF';
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE (' No Data Found for ORCHID_SHIPMENT_HDR_INTF in Download Batch Info table...!!!');
RAISE;
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE (' Too Many Rows found for ORCHID_SHIPMENT_HDR_INTF in Download Batch Info table...!!!');
RAISE;
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE (' Following error occured while getting batch control number for ORCHID_SHIPMENT_HDR_INTF in Download Batch Info table...!!!'||SQLERRM);
RAISE;
END;
-- get the batch control number details from batch information table for shipment address
BEGIN
SELECT batch_ctrl_no
, NVL(download_end_tstamp,TO_DATE('01/01/1980','MM/DD/YYYY'))
, dwn_status
INTO lv_adr_batch_ctrl_no
, ld_adr_dwn_end_dt
, lc_adr_dwn_status
FROM comoes.download_batch_info
WHERE download_id = 'ORCHID_SHIPMENT_ADDRESS_INTF';
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE (' No Data Found for ORCHID_SHIPMENT_ADDRESS_INTF in Download Batch Info table...!!!');
RAISE;
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE (' Too Many Rows found for ORCHID_SHIPMENT_ADDRESS_INTF in Download Batch Info table...!!!');
RAISE;
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE (' Following error occured while getting batch control number for ORCHID_SHIPMENT_ADDRESS_INTF in Download Batch Info table...!!!'||SQLERRM);
RAISE;
END;
-- get the batch control number details from batch information table for shipment details
BEGIN
SELECT batch_ctrl_no
, NVL(download_end_tstamp,TO_DATE('01/01/1980','MM/DD/YYYY'))
, dwn_status
INTO lv_dtl_batch_ctrl_no
, ld_dtl_dwn_end_dt
, lc_dtl_dwn_status
FROM download_batch_info
WHERE download_id = 'ORCHID_SHIPMENT_DTL_INTF';
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE (' No Data Found for ORCHID_SHIPMENT_DTL_INTF in Download Batch Info table...!!!');
RAISE;
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE (' Too Many Rows found for ORCHID_SHIPMENT_DTL_INTF in Download Batch Info table...!!!');
RAISE;
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE (' Following error occured while getting batch control number for ORCHID_SHIPMENT_DTL_INTF in Download Batch Info table...!!!'||SQLERRM);
RAISE;
END;
-- if previous run is not sucess then do nothing and return.
OPEN c_com_shphdr ( ld_hdr_dwn_end_dt ) ;
LOOP
-- delete the collection for every cycle
lr_com_shphdr.DELETE;
lr_orchid_shphdr.DELETE;
lr_com_shpadr.DELETE;
lr_orchid_shpadr.DELETE;
lr_com_shpdtl.DELETE;
lr_orchid_shpdtl.DELETE;
-- fetch the order header records to collection
FETCH c_com_shphdr BULK COLLECT INTO lr_com_shphdr LIMIT 500;
-- where there is no record in the collection the exit from the loop
EXIT WHEN lr_com_shphdr.COUNT = 0;
-- build your logic there to populate the data into order header collection.
FOR i IN 1..lr_com_shphdr.COUNT
LOOP
-- accumulate header running sequence number
ln_hdr_running_seq := ln_hdr_running_seq + 1;
ln_shphdr_seq := ln_hdr_running_seq;
-- Get the business unit for the customer from com_customer
BEGIN
SELECT business_unit
INTO lv_company_code
FROM com_customer@com_pricing.world
WHERE custno = lr_com_shphdr(i).del_custno;
EXCEPTION
WHEN OTHERS THEN
lv_company_code := NULL;
END;
-- Get the ordno, confirm_date from COM_PLLINE
BEGIN
SELECT ordno
, confirm_date
INTO lv_erp_ord_no
, lv_actual_ship_date
FROM com_plline@com_pricing.world cpl
WHERE cpl.plheadno = lr_com_shphdr(i).plheadno
AND ROWNUM = 1;
EXCEPTION
WHEN OTHERS THEN
lv_erp_ord_no := NULL;
lv_actual_ship_date := NULL;
END;
-- Get the po_no, Entry_date from COM_OLINE
BEGIN
SELECT po_no
, entrydate
INTO lv_po_no
, lv_ord_date
FROM com_oline@com_pricing.world col
WHERE col.ordno = lv_erp_ord_no
AND ROWNUM = 1;
EXCEPTION
WHEN OTHERS THEN
lv_po_no := NULL;
lv_ord_date := NULL;
END;
-- To assign the Bol Number from Lading Number
IF lr_com_shphdr(i).carr_no NOT IN ('FEDX','UPS') THEN
lr_orchid_shphdr(i).bol_no := lr_com_shphdr(i).lading_no;
ELSE
lr_orchid_shphdr(i).bol_no := NULL;
END IF;
-- For each order header get the Shipment Delivery Adderss
OPEN c_com_shpadr ( lr_com_shphdr(i).custaddr);
FETCH c_com_shpadr BULK COLLECT INTO lr_com_shpadr;
-- where there is no record in the collection the exit from the loop
EXIT WHEN lr_com_shpadr.COUNT = 0;
-- biuld your logic here to populate the del address collection.
FOR j IN 1..lr_com_shpadr.COUNT
LOOP
-- accumulate the loop count into temp variable, so that will through tell each set of order header.
cnt := cnt + 1;
-- accumolate the header running sequence number.
ln_adr_running_seg := ln_adr_running_seg + 1;
ln_shpadr_seg := ln_adr_running_seg;
-- move the order address data into collection.
lr_orchid_shpadr(cnt).client_id := lr_com_shphdr(i).del_custno;
lr_orchid_shpadr(cnt).ord_no := lr_com_shphdr(i).plheadno;
lr_orchid_shpadr(cnt).tracking_no := lr_com_shphdr(i).tracking_no;
lr_orchid_shpadr(cnt).addr_name := lr_com_shpadr(j).addr_name;
lr_orchid_shpadr(cnt).attn_line := lr_com_shphdr(i).attn_line;
lr_orchid_shpadr(cnt).addr_line1 := lr_com_shpadr(j).addr_line1;
lr_orchid_shpadr(cnt).addr_line2 := lr_com_shpadr(j).addr_line2;
lr_orchid_shpadr(cnt).addr_line3 := NULL;
lr_orchid_shpadr(cnt).addr_line4 := NULL;
lr_orchid_shpadr(cnt).addr_line5 := NULL;
lr_orchid_shpadr(cnt).city := lr_com_shpadr(j).city;
lr_orchid_shpadr(cnt).state_cd := lr_com_shpadr(j).state_cd;
lr_orchid_shpadr(cnt).zip := lr_com_shpadr(j).zip;
lr_orchid_shpadr(cnt).zip_ext := NULL;
lr_orchid_shpadr(cnt).country_cd := lr_com_shpadr(j).country_cd;
lr_orchid_shpadr(cnt).tax_geo_cd := NULL;
lr_orchid_shpadr(cnt).work_phone := lr_com_shpadr(j).work_phone;
lr_orchid_shpadr(cnt).email1 := lr_com_shpadr(j).email1;
lr_orchid_shpadr(cnt).cre_dat := SYSDATE;
lr_orchid_shpadr(cnt).cre_usr := USER;
lr_orchid_shpadr(cnt).batch_ctrl_no := lv_adr_batch_ctrl_no;
END LOOP;
CLOSE c_com_shpadr;
-- For each order header get the order detail/delivery segment data
OPEN c_com_shpdtl ( lr_com_shphdr(i).plheadno );
FETCH c_com_shpdtl BULK COLLECT INTO lr_com_shpdtl;
-- where there is no record in the collection the exit from the loop
EXIT WHEN lr_com_shpdtl.COUNT = 0;
-- build your logic here to populate the order detail collection
FOR k IN 1..lr_com_shpdtl.COUNT
LOOP
-- accumulate the loop count into a temp variable, so that will through till each set of Order Header.
cnt1 := cnt1 + 1;
-- accumulate header running sequence number
ln_dtl_running_seq := ln_dtl_running_seq + 1;
ln_shpdtl_seq := ln_dtl_running_seq;
-- Get Quantity for the delvery from delevery segment table.
BEGIN
SELECT NVL(Qty,0)
INTO lv_ord_qty
FROM com_oldelseg@com_pricing.world cds
WHERE cds.ordno = lr_com_shpdtl(k).erp_ord_no
AND cds.ol_no = lr_com_shpdtl(k).erp_line_no
AND cds.ol_segno = lr_com_shpdtl(k).ol_segno;
EXCEPTION
WHEN OTHERS THEN
lv_ord_qty := NULL;
END;
-- Get Title for the salesitem from the salesitem table.
BEGIN
SELECT Title
INTO lv_sku_desc
FROM com_salesitem@com_pricing.world cs
WHERE cs.fg_id = lr_com_shpdtl(k).sku;
EXCEPTION
WHEN OTHERS THEN
lv_sku_desc := NULL;
END;
-- move the Order detail data into collection
lr_orchid_shpdtl(cnt1).client_id := lr_com_shphdr(i).client_id;
lr_orchid_shpdtl(cnt1).ord_no := lr_com_shphdr(i).plheadno;
lr_orchid_shpdtl(cnt1).ord_line_no := lr_com_shpdtl(k).ord_line_no;
lr_orchid_shpdtl(cnt1).erp_line_no := lr_com_shpdtl(k).erp_line_no;
lr_orchid_shpdtl(cnt1).sku := lr_com_shpdtl(k).sku;
lr_orchid_shpdtl(cnt1).tracking_no := lr_com_shphdr(i).tracking_no;
lr_orchid_shpdtl(cnt1).container_no := NULL;
lr_orchid_shpdtl(cnt1).ord_qty := lv_ord_qty;
lr_orchid_shpdtl(cnt1).ship_qty := lr_com_shpdtl(k).ship_qty;
lr_orchid_shpdtl(cnt1).price_point := NULL;
lr_orchid_shpdtl(cnt1).pick_invoice_no := NULL;
lr_orchid_shpdtl(cnt1).cancel_qty := NULL;
lr_orchid_shpdtl(cnt1).bldg_id := NULL; --lr_com_shpdtl(k).bldg_id;
lr_orchid_shpdtl(cnt1).sku_company := NULL; --lr_com_shpdtl(k).sku_company;
lr_orchid_shpdtl(cnt1).sku_desc := lv_sku_desc;
lr_orchid_shpdtl(cnt1).icc_cd1 := NULL; --lr_com_shpdtl(k).icc_cd1;
lr_orchid_shpdtl(cnt1).erp_ord_no := lr_com_shpdtl(k).erp_ord_no;
lr_orchid_shpdtl(cnt1).cre_dat := SYSDATE;
lr_orchid_shpdtl(cnt1).cre_usr := USER;
lr_orchid_shpdtl(cnt1).batch_ctrl_no := lv_dtl_batch_ctrl_no;
END LOOP;
CLOSE c_com_shpdtl;
-- build the logic to populate Order Header
lr_orchid_shphdr(i).client_id := lr_com_shphdr(i).client_id;
lr_orchid_shphdr(i).ord_no := lr_com_shphdr(i).plheadno;
lr_orchid_shphdr(i).tracking_no := lr_com_shphdr(i).tracking_no;
lr_orchid_shphdr(i).container_no := NULL; -- container number is not maintained in COM
lr_orchid_shphdr(i).carrier_id := lr_com_shphdr(i).carrier_id;
lr_orchid_shphdr(i).plant_id := lr_com_shphdr(i).plant_id;
lr_orchid_shphdr(i).erp_ord_no := lv_erp_ord_no;
lr_orchid_shphdr(i).erp_ord_no2 := NULL;
lr_orchid_shphdr(i).po_no := lv_po_no;
lr_orchid_shphdr(i).ship_to_id := lr_com_shphdr(i).ship_to_id;
lr_orchid_shphdr(i).ship_to_addr_id := lr_com_shphdr(i).custaddr;
lr_orchid_shphdr(i).scac := NULL; --lr_com_shphdr(i).scac;
lr_orchid_shphdr(i).actual_ship_date := lv_actual_ship_date;
lr_orchid_shphdr(i).cfm_order_type := lr_com_shphdr(i).cfm_order_type;
lr_orchid_shphdr(i).company_code := lv_company_code;
lr_orchid_shphdr(i).no_of_order_lines := NULL; --lr_com_shphdr(i).no_of_order_lines;
lr_orchid_shphdr(i).pick_invoice_no := NULL;
lr_orchid_shphdr(i).ord_date := lv_ord_date;
lr_orchid_shphdr(i).orig_tender_date := NULL;
lr_orchid_shphdr(i).orig_delv_date := NULL;
lr_orchid_shphdr(i).delivery_flag := NULL;
lr_orchid_shphdr(i).delv_date_from := NULL;
lr_orchid_shphdr(i).delv_date_to := NULL;
lr_orchid_shphdr(i).orig_carr_cd := NULL;
lr_orchid_shphdr(i).routing_comment := NULL;
lr_orchid_shphdr(i).segment_type := NULL;
lr_orchid_shphdr(i).back_order_flag := NULL;
lr_orchid_shphdr(i).addr_override_flag := NULL;
lr_orchid_shphdr(i).fmx_assigned_carr := NULL;
lr_orchid_shphdr(i).fmx_assigned_ship_date := NULL;
lr_orchid_shphdr(i).fmx_assigned_delv_date := NULL;
lr_orchid_shphdr(i).freight_terms := lr_com_shphdr(i).freight_terms;
lr_orchid_shphdr(i).fmx_load_id := NULL;
lr_orchid_shphdr(i).asn_type := NULL;
lr_orchid_shphdr(i).icc_cd1 := NULL; --lr_com_shphdr(i).icc_cd1;
lr_orchid_shphdr(i).trans_type := NULL;
lr_orchid_shphdr(i).ref_no1 := NULL;
lr_orchid_shphdr(i).ref_no2 := NULL;
lr_orchid_shphdr(i).ref_no3 := NULL;
lr_orchid_shphdr(i).ref_no4 := NULL;
lr_orchid_shphdr(i).cre_dat := SYSDATE;
lr_orchid_shphdr(i).cre_usr := USER;
lr_orchid_shphdr(i).batch_ctrl_no := lv_hdr_batch_ctrl_no;
-- logic to get total boxes and weight.
BEGIN
SELECT SUM(no_cartons), SUM(weight)
INTO lr_orchid_shphdr(i).total_boxes
, lr_orchid_shphdr(i).weight
FROM com_plline@com_pricing.world pll
WHERE pll.plheadno = lr_com_shphdr(i).plheadno;
EXCEPTION
WHEN OTHERS THEN
lr_orchid_shphdr(i).total_boxes := NULL;
lr_orchid_shphdr(i).weight := NULL;
END;
END LOOP;
-- initialize the variables for next loop cycle.
cnt := 0;
cnt1 := 0;
-- populate the shipment header interface table.
FOR x IN 1..lr_orchid_shphdr.COUNT
LOOP
ld_hdr_download_end_tstamp := lr_orchid_shphdr(x).cre_dat;
INSERT INTO orchid_shipment_hdr_intf
(record_qualifier
,client_id
,ord_no
,tracking_no
,container_no
,bol_no
,carrier_id
,plant_id
,erp_ord_no
,erp_ord_no2
,po_no
,ship_to_id
,ship_to_addr_id
,scac
,actual_ship_date
,cfm_order_type
,company_code
,no_of_order_lines
,pick_invoice_no
,total_boxes
,weight
,ord_date
,orig_tender_date
,orig_delv_date
,delivery_flag
,delv_date_from
,delv_date_to
,orig_carr_cd
,routing_comment
,segment_type
,back_order_flag
,addr_override_flag
,fmx_assigned_carr
,fmx_assigned_ship_date
,fmx_assigned_delv_date
,freight_terms
,fmx_load_id
,asn_type
,upl_status
,icc_cd1
,trans_type
,ref_no1
,ref_no2
,ref_no3
,ref_no4
,cre_dat
,cre_usr
,batch_ctrl_no)
VALUES
( 10
,lr_orchid_shphdr(x).client_id
,lr_orchid_shphdr(x).ord_no
,lr_orchid_shphdr(x).tracking_no
,lr_orchid_shphdr(x).container_no
,lr_orchid_shphdr(x).bol_no
,lr_orchid_shphdr(x).carrier_id
,lr_orchid_shphdr(x).plant_id
,lr_orchid_shphdr(x).erp_ord_no
,lr_orchid_shphdr(x).erp_ord_no2
,lr_orchid_shphdr(x).po_no
,lr_orchid_shphdr(x).ship_to_id
,lr_orchid_shphdr(x).ship_to_addr_id
,lr_orchid_shphdr(x).scac
,lr_orchid_shphdr(x).actual_ship_date
,lr_orchid_shphdr(x).cfm_order_type
,lr_orchid_shphdr(x).company_code
,lr_orchid_shphdr(x).no_of_order_lines
,lr_orchid_shphdr(x).pick_invoice_no
,lr_orchid_shphdr(x).total_boxes
,lr_orchid_shphdr(x).weight
,lr_orchid_shphdr(x).ord_date
,lr_orchid_shphdr(x).orig_tender_date
,lr_orchid_shphdr(x).orig_delv_date
,lr_orchid_shphdr(x).delivery_flag
,lr_orchid_shphdr(x).delv_date_from
,lr_orchid_shphdr(x).delv_date_to
,lr_orchid_shphdr(x).orig_carr_cd
,lr_orchid_shphdr(x).routing_comment
,lr_orchid_shphdr(x).segment_type
,lr_orchid_shphdr(x).back_order_flag
,lr_orchid_shphdr(x).addr_override_flag
,lr_orchid_shphdr(x).fmx_assigned_carr
,lr_orchid_shphdr(x).fmx_assigned_ship_date
,lr_orchid_shphdr(x).fmx_assigned_delv_date
,lr_orchid_shphdr(x).freight_terms
,lr_orchid_shphdr(x).fmx_load_id
,lr_orchid_shphdr(x).asn_type
,00
,lr_orchid_shphdr(x).icc_cd1
,lr_orchid_shphdr(x).trans_type
,lr_orchid_shphdr(x).ref_no1
,lr_orchid_shphdr(x).ref_no2
,lr_orchid_shphdr(x).ref_no3
,lr_orchid_shphdr(x).ref_no4
,lr_orchid_shphdr(x).cre_dat
,lr_orchid_shphdr(x).cre_usr
,lr_orchid_shphdr(x).batch_ctrl_no);
END LOOP;
-- populate the shipment address interface table.
FOR y IN 1..lr_orchid_shpadr.COUNT
LOOP
ld_adr_download_end_tstamp := lr_orchid_shpadr(y).cre_dat;
INSERT INTO orchid_shipment_address_intf
( record_qualifier
, client_id
, ord_no
, tracking_no
, addr_name
, attn_line
, addr_line1
, addr_line2
, addr_line3
, addr_line4
, addr_line5
, city
, state_cd
, zip
, zip_ext
, country_cd
, tax_geo_cd
, work_phone
, email1
, cre_dat
, cre_usr
, batch_ctrl_no)
VALUES ( 14
, lr_orchid_shpadr(y).client_id
, lr_orchid_shpadr(y).ord_no
, lr_orchid_shpadr(y).tracking_no
, lr_orchid_shpadr(y).addr_name
, lr_orchid_shpadr(y).attn_line
, lr_orchid_shpadr(y).addr_line1
, lr_orchid_shpadr(y).addr_line2
, lr_orchid_shpadr(y).addr_line3
, lr_orchid_shpadr(y).addr_line4
, lr_orchid_shpadr(y).addr_line5
, lr_orchid_shpadr(y).city
, lr_orchid_shpadr(y).state_cd
, lr_orchid_shpadr(y).zip
, lr_orchid_shpadr(y).zip_ext
, lr_orchid_shpadr(y).country_cd
, lr_orchid_shpadr(y).tax_geo_cd
, lr_orchid_shpadr(y).work_phone
, lr_orchid_shpadr(y).email1
, lr_orchid_shpadr(y).cre_dat
, lr_orchid_shpadr(y).cre_usr
, lr_orchid_shpadr(y).batch_ctrl_no);
END LOOP;
-- populate the shipment detail interface table.
FOR z IN 1..lr_orchid_shpdtl.COUNT
LOOP
ld_dtl_download_end_tstamp := lr_orchid_shpdtl(z).cre_dat;
INSERT INTO orchid_shipment_dtl_intf
( record_qualifier
, client_id
, ord_no
, ord_line_no
, erp_line_no
, sku
, tracking_no
, container_no
, ord_qty
, ship_qty
, price_point
, pick_invoice_no
, cancel_qty
, bldg_id
, sku_company
, sku_desc
, icc_cd1
, erp_ord_no
, cre_dat
, cre_usr
, batch_ctrl_no)
VALUES ( 20
, lr_orchid_shpdtl(z).client_id
, lr_orchid_shpdtl(z).ord_no
, lr_orchid_shpdtl(z).ord_line_no
, lr_orchid_shpdtl(z).erp_line_no
, lr_orchid_shpdtl(z).sku
, lr_orchid_shpdtl(z).tracking_no
, lr_orchid_shpdtl(z).container_no
, lr_orchid_shpdtl(z).ord_qty
, lr_orchid_shpdtl(z).ship_qty
, lr_orchid_shpdtl(z).price_point
, lr_orchid_shpdtl(z).pick_invoice_no
, lr_orchid_shpdtl(z).cancel_qty
, lr_orchid_shpdtl(z).bldg_id
, lr_orchid_shpdtl(z).sku_company
, lr_orchid_shpdtl(z).sku_desc
, lr_orchid_shpdtl(z).icc_cd1
, lr_orchid_shpdtl(z).erp_ord_no
, lr_orchid_shpdtl(z).cre_dat
, lr_orchid_shpdtl(z).cre_usr
, lr_orchid_shpdtl(z).batch_ctrl_no);
END LOOP;
COMMIT;
END LOOP;
CLOSE c_com_shphdr;
-- set the status to success
UPDATE comoes.download_batch_info
SET batch_ctrl_no = orchid_plhead_btch_ctrl_seq.NEXTVAL
, dwn_status = '90'
, download_end_tstamp = NVL(ld_hdr_download_end_tstamp,SYSDATE)
WHERE download_id = 'ORCHID_SHIPMENT_HDR_INTF'
AND batch_ctrl_no = lv_hdr_batch_ctrl_no;
UPDATE comoes.download_batch_info
SET batch_ctrl_no = orchid_address_btch_ctrl_seq.NEXTVAL
, dwn_status = '90'
, download_end_tstamp = NVL(ld_hdr_download_end_tstamp,SYSDATE)
WHERE download_id = 'ORCHID_SHIPMENT_ADDRESS_INTF'
AND batch_ctrl_no = lv_adr_batch_ctrl_no;
UPDATE comoes.download_batch_info
SET batch_ctrl_no = orchid_plline_btch_ctrl_seq.NEXTVAL
, dwn_status = '90'
, download_end_tstamp = NVL(ld_dtl_download_end_tstamp,SYSDATE)
WHERE download_id = 'ORCHID_SHIPMENT_DTL_INTF'
AND batch_ctrl_no = lv_dtl_batch_ctrl_no;
-- Update the download status to success in the interface table.
-- Shipment Header
COMMIT;
EXCEPTION
WHEN OTHERS THEN
-- load is not sucess then set the status to fail
UPDATE comoes.download_batch_info
SET dwn_status = '99'
WHERE download_id = 'ORCHID_SHIPMENT_HDR_INTF'
AND batch_ctrl_no = lv_hdr_batch_ctrl_no;
UPDATE comoes.download_batch_info
SET dwn_status = '99'
WHERE download_id = 'ORCHID_SHIPMENT_ADDRESS_INTF'
AND batch_ctrl_no = lv_adr_batch_ctrl_no;
UPDATE comoes.download_batch_info
SET dwn_status = '99'
WHERE download_id = 'ORCHID_SHIPMENT_DTL_INTF'
AND batch_ctrl_no = lv_dtl_batch_ctrl_no;
COMMIT;
DBMS_OUTPUT.PUT_LINE('Following error occured while executing ORCHID_SHIPMENT_INTF procedure...!!!'||SQLERRM);
RAISE;
END orchid_shipment_interface;Edited by: BluShadow on 03-Aug-2011 13:28
added {noformat}{noformat} tags. Please read {message:id=9360002} to learn to do this yourself. &nbPlease read the Forum FAQ on how to ask a question, particularly how to format code
SQL and PL/SQL FAQ
SQL and PL/SQL FAQ
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE (' Following error occured while getting batch control number for ORCHID_SHIPMENT_HDR_INTF in Download Batch Info table...!!!'||SQLERRM);
RAISE;http://tkyte.blogspot.com/2008/01/why-do-people-do-this.html -
How to identify the selection parameters of already executed transactions
Hi,
I like to identify the selection parameter of already executed transaction.
SM20 shows me which transaction was executed on which day and by whom.
But it does not give me it is executed with which kind of selection parameters.
For example, MD02/03 was executed many times, I like to know who execute it with parameter "2" for "create purchase req.".
How can I know it?
Regards,
Kenichi KanedaHi,
I don't think so that SAP stores this information anywhere. -
How to write the select query with complex where condition
Hi all,
Can u help me in writing following select query.
select * from zu1cd_corr where time_stamp between firstday and lastday .
In the above query time_stamp contains the date and time.
where as firstday and lastday contains the dates.
I need to compare the date in the time_stamp with the firstday and lastday.
But time_stamp contains the time also and it is char of 14 characters length.Hi,
If that is the case u can do as advait specified....
if the firstday and secondday are select-options then declare two more variables having 14 character length and then concatenate '000000' to firstday variable and '240000' to last day variable and then write ur query.
CLEAR : lv_firstday,
lv_lastday.
concatenate firstday '000000' to lv_firstday.
concatenate lastday '240000' to lv_lastday.
ranges : r_Date for zu1cd_corr-time_stamp.
r_date-sign = 'I'.
r_date-option = 'BT'.
r_Date-low = lv_firstday.
r_Date-high = lv_lastday.
append r_date.
select * from zu1cd_corr into table it_zu1cd_corr where time_stamp in r_Date.
I hope it helps.
Regards,
Nagaraj -
How to correct the error message that appears when installing photoshop CS5 for the third time
I need help so solve the error message that appears on my computer when I try to register the program for the third time. Please helpppppp!
If you're referring to the activations warning, simply call support to reset them.
Mylenium -
How to frame the select query for wildcard search.
Hi Experts,
I have an input field P_USERALIAS.This value could contain the actual value or the wildcard for example : user can enter P_USERALIAS as SAP123 or S or SAPABC123 . I need to generate a dynamic search on table USREFUS depending on what has been entered.Please help.
Useful answers will be rewarded.
Regards,
Shrita Sharma.THIS IS A TEST REPORT FOR WILDCARD SEARCH**
TABLES: USREFUS.
PARAMETERS: P_NAME1 TYPE string.
RANGES: R_NAME1 FOR USREFUS-USERALIAS.
DATA: T_usrefus LIKE usrefus OCCURS 0 WITH HEADER LINE.
*replace
if p_name1 cs '*'.
replace all occurrences of '*' in p_name1 with '%'.
SELECT * FROM usrefus
INTO TABLE T_usrefus
WHERE useralias like P_NAME1.
else.
SELECT * FROM usrefus
INTO TABLE T_usrefus
WHERE useralias = p_name1.
endif.
LOOP AT T_usrefus.
WRITE: / T_usrefus-useralias.
ENDLOOP.
**THANKS & REGARDS
SHRITA SHARMA. -
Performance optimization on select query for all entries
Hi All,
I want to optimize the select query in my Program.
The select query is taking lot of time to search the records for the given condition in the where clause
and more interestingly there are no records fetched from the database as the where condition does not matches.
It is taking more than 30 min to search the record and the result is no record found.
Below is my select query. I have also created the secondary Index for the same.
In My opinion FOR ALL ENTRIES is taking lot of time. Because there are more than 1200 records in internal table t_ajot
select banfn bnfpo bsart txz01 matnr Werks lgort matkl reswk menge meins flief ekorg
INTO CORRESPONDING FIELDS OF TABLE t_req
FROM eban
FOR ALL ENTRIES IN t_ajot
WHERE matkl >= t_ajot-matkl_low
AND matkl <= t_ajot-matkl_high
AND werks = t_ajot-werks
AND loekz = ' '
AND badat IN s_badat
AND bsart = 'NB'.
Please suggest.Hi,
that,
FOR ALL ENTRIES IN t_ajot
WHERE matkl >= t_ajot-matkl_low
AND matkl <= t_ajot-matkl_high
AND werks = t_ajot-werks
AND loekz = ' '
AND badat IN s_badat
AND bsart = 'NB'.
looks strange.
However:
How does your index look like?
What executoin plan do you get?
How do the statistics look like?
Whats the content of the variables t_ajot-... and s_badata?
Kind regards,
Hermann -
How to display a select query record in a tool tip?
hi,
How to display a select query record in a tool tip?
for example i have a report employee. when i move the mouse pointer over a employee name, the tool tip should display the respective department id, department name...of that employee name.
select dep_id, dep_name ....from department where employee.....Is it possible?
thanksDear Skud,
Yes its possible..select ''||ename||'' from emp
other wise you can use jQuery tooptip or some other JScript bundles.
Thanks and Regards
Maheswara -
How could I create a query that provides a default transaction type for those transactions not categorized?
So assuming I have:
* Transactions table (with transactions)
* Categories table
* transactions_categories table - allows to allocate multiple categories (with a percentage)
- tranactionID
- categoryID
- percentageAllocation
* Usage is such that only non-personal categories have been applied through out data. So there is a lot of transactions with no categories applied
Aim:
* Want to create a query that creates a list of all the allocated amounts, so would include as columns: transaction.tDate, transaction.tTitle, categories.name, allocatedAmount(calculated from percentage * transaction amount)
BUT:
* How could I include in the query, the entries that cover all transaction that haven't been allocated, to a default category "personal", where the allocated Amount would be 100% of the transaction value
* And also (if it were possible), for transactions that have been categorized but not for the complete transaction value (say only 50% was allocated to a category), how to to cover this off to.To default the value of the category:
select IIf(IsNull(Category),"Personal",Category) as Category,IIf(IsNull(Category),"100%",PercentageAllocation
) as PercentageAllocation from [yourtable]
What do you want to put the values of these ones:
And also (if it were possible), for transactions that have been categorized but not for the complete transaction
value (say only 50% was allocated to a category), how to to cover this off to.
Fouad Roumieh -
How can i use index in select query.. facing problem with the select query.
Hi Friends,
I am facing a serious problem in one of the select query. It is taking a lot of time to fetch data in Production Scenario.
Here is the query:
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelat LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelatrprctr
WHERE rldnr = c_telstra_accounting
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
And rzzlstar in r_lstar
AND rpmax = c_max_period.
There are 5 indices present for Table ZTFTELAT.
Indices of ZTFTELAT:
Name Description
0 Primary key( RCLNT,RLDNR,RRCTY,RVERS,RYEAR,ROBJNR,SOBJNR,RTCUR,RUNIT,DRCRK,RPMAX)
005 Profit (RCLNT,RPRCTR)
1 Ledger, company code, account (RLDNR,RBUKRS, RACCT)
2 Ledger, company code, cost center (RLDNR, RBUKRS,RCNTR)
3 Account, cost center (RACCT,RCNTR)
4 RCLNT/RLDNR/RRCTY/RVERS/RYEAR/RZZAUFNR
Z01 Activity Type, Account (RZZLSTAR,RACCT)
Z02 RYEAR-RBUKRS- RZZZBER-RLDNR
Can anyone help me out why it is taking so much time and how we can reduce it ? and also tell me if I want to use index number 1 then how can I use?
Thanks in advance.Hi Shiva,
I am using two more select queries with the same manner ....
here are the other two select query :
***************1************************
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelpt LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelptrprctr
WHERE rldnr = c_telstra_projects
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
and rzzlstar in r_lstar
AND rpmax = c_max_period.
and the second one is
*************************2************************
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelnt LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelntrprctr
WHERE rldnr = c_telstra_networks
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
and rzzlstar in r_lstar
AND rpmax = c_max_period.
for both the above table program is taking very less time .... although both the table used in above queries have similar amount of data. And i can not remove the APPENDING CORRESPONDING. because i have to append the data after fetching from the tables. if i will not use it will delete all the data fetched earlier.
Thanks on advanced......
Sourabh -
How to optimize the below select query
SELECT mvke~matnr "Material Number
mbew~bwkey "Plant
mvke~mvgr1 "Line of Business
mara~meins "Unit of measure
mara~ntgew "Net weight
mara~mhdrz "Remaining shelf life
mara~zzmax_exp_days "Max expiry days
makt~maktx "Material Description
tvm1t~bezei "Line of Business description
mbew~stprs "Standard price
mbew~vprsv "Price control (S/V)
mbew~verpr "Variable Price
FROM mvke INNER JOIN mara
ON maramatnr EQ mvkematnr
INNER JOIN makt
ON maktmatnr EQ mvkematnr
INNER JOIN tvm1t
ON tvm1tmvgr1 EQ mvkemvgr1
INNER JOIN mbew
ON mbewmatnr EQ maramatnr
AND
mbewbwkey EQ mvkevkorg
INTO TABLE gt_matdata
WHERE mbew~matnr IN s_matnr AND
mbew~bwkey IN s_werks AND
mvke~mvgr1 IN s_mvgr1 AND
makt~spras EQ sy-langu AND
tvm1t~spras EQ sy-langu.
Please advice.
Thanks and Regards
Syed SamdaniHi,
You are taking different fields of data from five different tables it seems.
Well you can take separate internal tables and fire five separate select queries using the 'For All Entries' condition after the first select stmnt, so that u get all the related data. Then take your final internal table and merge all data from all these five internal tables into you final table.
Regards,
Jayadeep -
Using case when statement in the select query to create physical table
Hello,
I have a requirement where in I have to execute a case when statement with a session variable while creating a physical table using a select query. let me explain with an example.
I have a physical table based on a select table with one column.
SELECT 'VALUEOF(NQ_SESSION.NAME_PARAMETER)' AS NAME_PARAMETER FROM DUAL. Let me call this table as the NAME_PARAMETER table.
I also have a customer table.
In my dashboard that has two pages, Page 1 contains a table with the customer table with column navigation to my second dashboard page.
In my second dashboard page I created a dashboard report based on NAME_PARAMETER table and a prompt based on customer table that sets the NAME_ PARAMETER request variable.
EXECUTION
When i click on a particular customer, the prompt sets the variable NAME_PARAMETER and the NAME_PARAMETER table shows the appropriate customer.
everything works as expected. YE!!
Now i created another table called NAME_PARAMETER1 with a little modification to the earlier table. the query is as follows.
SELECT CASE WHEN 'VALUEOF(NQ_SESSION.NAME_PARAMETER)'='Customer 1' THEN 'TEST_MART1' ELSE TEST_MART2' END AS NAME_PARAMETER
FROM DUAL
Now I pull in this table into the second dashboard page along with the NAME_PARAMETER table report.
surprisingly, NAME_PARAMETER table report executes as is, but the other report based on the NAME_PARAMETER1 table fails with the following error.
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 16001] ODBC error state: S1000 code: 1756 message: [Oracle][ODBC][Ora]ORA-01756: quoted string not properly terminated. [nQSError: 16014] SQL statement preparation failed. (HY000)
SQL Issued: SET VARIABLE NAME_PARAMETER='Novartis';SELECT NAME_PARAMETER.NAME_PARAMETER saw_0 FROM POC_ONE_DOT_TWO ORDER BY saw_0
If anyone has any explanation to this error and how we can achieve the same, please help.
Thanks.Hello,
Updates :) sorry.. the error was a stupid one.. I resolved and I got stuck at my next step.
I am creating a physical table using a select query. But I am trying to obtain the name of the table dynamically.
Here is what I am trying to do. the select query of the physical table is as follows.
SELECT CUSTOMER_ID AS CUSTOMER_ID, CUSTOMER_NAME AS CUSTOMER_NAME FROM 'VALUEOF(NQ_SESSION.SCHEMA_NAME)'.CUSTOMER.
The idea behind this is to obtain the data from the same table from different schemas dynamically based on what a session variable. Please let me know if there is a way to achieve this, if not please let me know if this can be achieved in any other method in OBIEE.
Thanks. -
How to get the selected value in SelectOneMenu in backing bean
Hello all,
I need your help. I want to have 2 select menus with the second menu's items list are populated based on the selection in the first menu. I don't know how to get the selected value in the backing bean so that I can based on that select menu to populate the second menu's item list. Basically I need to access to the UI Component of the first select Menu and retrieve its selected value.
Could you help me out?
Thank you very much in advance,
LngoHi Lingo,
There r two ways of getting the values into the list. First one is hardcoding the values and the second one is use the list and get the values into the list by firing a query in the database.
Inorder to display the values in the second menu based on the first onces selection we need to add an attribute to the first selectonemenu known as valueChangeListener and we need to sumit the page.
Here is the sample code
<h:selectOneMenu id="catalogue"
binding="#{urbean.catalogue}" onchange="submit()"
valueChangeListener="#{urbean.categoryValueChange}"
<f:selectItem itemLabel="Select Catalogue" itemValue="" />
<f:selectItems value="#{urbean.catalogueList}" />
</h:selectOneMenu>
<h:selectOneMenu id="category"
binding="#{urbean.category}"> <f:selectItem itemLabel="Select Category" itemValue="" />
<f:selectItems value="#{urbean.categoryList}" />
< </h:selectOneMenu>
now in method called by valuechangelistener we need to write the similar code
public void categoryValueChange(ValueChangeEvent event) {
String rfnum = (String) event.getNewValue();
List categoryList = new ArrayList();
List tempList = new TablenameDAO().getActiveCatByCatalogueID(rfnum);
for (int i = 0; i < tempList.size(); i++) {
Tablename tablename = (Tablename ) tempList.get(i);
String value = "" + tablename .getrfnum();
String label = tablename .getname();
if (label == null) {
label = "";
SelectItem item = new SelectItem(value, label);
categoryList.add(item);
bean.setCategoryList(categoryList);
///getActiveCatByCatalogueID (rfnum) should bring the records which r based on the rfnum
if u follow this process i am damsure that u will get the values in to the secondlist based upon the first list
Thanks & Regards
Manidhar -
How to get the SQL Signon that Agent Jobs "Run As" or "Executed as User"
How to get the SQL Signon that Agent Jobs "Run As" or "Executed as User"?
I have an install SQL scripts that creates a Linked Server. I want to put some security on the Linked Server and only grant the Agent Job Signon (the "Run As" or "Executed as User") access to the linked server. I need to retrieve the
Agent Job Signon (something like "NT SERVICE\SQLAgent$FIDEV360BI02").
I could query certain jobs and SUBSTRING the Message column - using some form of the query below, which would return "Executed as user: NT SERVICE\SQLAgent$SSDEVBI02. The step succeeded." But that is pretty imprecise.
use msdb
SELECT [JobName] = JOB.name,
[Step] = HIST.step_id,
[StepName] = HIST.step_name,
[Message] = HIST.message,
[Status] = CASE WHEN HIST.run_status = 0 THEN 'Failed'
WHEN HIST.run_status = 1 THEN 'Succeeded'
WHEN HIST.run_status = 2 THEN 'Retry'
WHEN HIST.run_status = 3 THEN 'Canceled'
END,
[RunDate] = HIST.run_date,
[RunTime] = HIST.run_time,
[Duration] = HIST.run_duration,
[Retries] = HIST.retries_attempted
FROM sysjobs JOB
INNER JOIN sysjobhistory HIST ON HIST.job_id = JOB.job_id
-- CHANGE THIS
-- WHERE JOB.name like '%GroupMaster%' or Job.name like '%etlv%'
ORDER BY HIST.run_date, HIST.run_timeby default all sql jobs are executed as sql server agent account, unless otherwise a proxy is setup.
you can get the proxy information as Olaf mentioned, if the proxy_id is null for the step, it implies that the job step was executed as sql server service account and in such case it will be null
so, if it is null, it ran as sql server agent account.
so, one work around is get the sql server agent service account and if the proxy is null, that means it ran as sql server agent account, so, use isnull function. the disadvantage would be if the sql server agent account was switched, you might not get the
accurate information as the new account will show up though the job really ran as old account, to get this information, you need to get this from the logmessage column as you mentioned above.
try this code...
/*from sql 2008r2 sp1, you get the service accounts using tsql,otherwise you have to query the registry keys*/
declare @sqlserveragentaccount varchar(2000)
select @sqlserveragentaccount= service_account
from sys.dm_server_services
where servicename like '%sql%server%agent%'
select message,isnull(name,@sqlserveragentaccount) as AccountName
from sysjobhistory a inner join sysjobsteps b
on a.step_id=b.step_id and a.job_id=b.job_id
left outer join sysproxies c on c.proxy_id=b.proxy_id
Hope it Helps!!
Maybe you are looking for
-
I recently had a hard drive crash on my iMac. After replacing the drive, I discovered that TimeMachine had apparently been turned off for six months, and all my photos from that period were missing after the restore. In looking on the external driv
-
Page body not displaying in Design view
Using CS3, I am trying to edit a page in Design view, however the page does not appear. http://www.angeleyesgps.com/index2.html The page can be found here, showing the body content appearing, showing it is not commented out. As you scroll down the pa
-
When I sync iphone to itunes, why do my soundtracks not show as albums but via artist? IE: Pulp Fiction has 16 songs by different artists. In itunes I can pull up pulp fiction and play the 16 songs. In iphone sync the 16 songs are seperate and lis
-
I came to know that name has changed when I tried to shrink the file. Here is the error message I got: Shrink failed for LogFile "Tfs_TESTTFS_Log'. (Microsoft.SqlServer.Smo) Additonal information An exception occured while executing a Transact-SQL st
-
Drill Across fields mapping with calculate field
I create a calculation field in one view, then when config drill across, i set the calculation field to mapping to a Parameter of target view Save report Then, i open the report in view mode, click the view which config drill across, it get JavaScrip