Handy SQL for the Oracle Applications (文档 ID 731190.1) |
![]() |
![]() |

In this Document
APPLIES TO:Oracle Inventory Management - Version 11.5.10 and laterInformation in this document applies to any platform. This document includes all versions of 11i and R12 and later ***Checked for relevance on 01-FEB-2016*** GOAL
NOTE: One customer had issues viewing the content of this note. They had to highlight the text to see the code snippets. The code snippets are following the standard Oracle KM guidelines with standard code widgets so should be the same as other code snippets used in other notes. The note was edited to bring it to the latest formats available. Sorry in advanced if you face this issue. Please highlight the text to see it.
SOLUTIONYes, there are a number of helpful SQL scripts that we will share below. The scripts are segmented by foundation technology scripts (FND/ATG/AOL), then other product areas like manufacturing. Many of the scripts prompt for information. None of the scripts do any updates. Note that occasionally table names or columns change overtime. Where possible, the scripts will note if they will work only on a specific release. Otherwise, they should work across 11i to R12 though the scripts will be focused on the latest code. 1. Database1.1 General Objects / Tables / Columns
PROMPT Find Object by Type, Name, Status
select object_name, object_type, owner, status from dba_objects where upper(object_name) like upper('%&object_name%') and object_type like upper('%'|| NVL('&object_type', 'TABLE')|| '%') and status like upper('%'|| NVL('&Status', '%')|| '%') order by object_name, object_type; PROMPT Find table indexes, keys, columns select index_name,column_position,column_name from all_ind_columns where table_name = '&EnterTableName' order by index_name, column_position; PROMPT Find tables and columns that include a table and/or column name specified. select table_name, column_name from dba_tab_columns where column_name like NVL(UPPER('&COLUMN_NAME'), column_name) and table_name like NVL(UPPER('&TABLE_NAME'), table_name); 1.2 Invalids / Compiling
PROMPT Find Invalids
select object_name, object_type, owner, status from dba_objects where status = 'INVALID'; PROMPT Compile Packages select 'alter package '|| object_name || ' compile '|| decode(object_type, 'PACKAGE', '', 'PACKAGE BODY', 'body')|| ';' from dba_objects where status = 'INVALID' and object_type like 'PACK%'; 1 .3 Bugs and Patching
PROMPT Find specific package version
select text from dba_source where name = upper( '&PackageName') and line < 3; PROMPT Find bugs already installed fixed in your system select bug_number from ad_bugs where bug_number ='&Bug_Number'; PROMPT Find patches applied select substr(patch_name,1,12) patch_num from ad_applied_patches where patch_name like '%&Patch_Number%';
NOTE: A specific bug maybe fixed by multiple patches so it might be good to look for the bug number, instead of the patch number to see if that bug is fixed already on your system. Another way is to look at the file version mentioned in the patch and check if you have that version or higher.
1.4 Other Objects
PROMPT Query view details of a specific view.
SELECT VIEW_NAME, TEXT FROM DBA_VIEWS WHERE VIEW_NAME = UPPER('&VIEW_NAME') and owner = 'APPS'; PROMPT Trigger details on a table. select TABLE_NAME, COLUMN_NAME, trigger_name, trigger_type, TRIGGER_BODY from dba_TRIGGERS WHERE TABLE_NAME like '%&EnterTableName%'; 1.5 Helpful SQL Syntax
1.5.1 Rowid:
2. Foundation (FND/ATG/AOL)2.1 SQL related to Oracle Application MessagesPROMPT ATG PROMPT Find Messages by Message Text select m.message_name, m.message_text, m.message_number, a.application_short_name from fnd_new_messages m, fnd_application a where upper(m.message_text) like upper('%&EnterMessageText%') and m.language_code = 'US' and m.application_id = a.application_id; PROMPT Find Messages by Message Short Name select m.message_name, m.message_text, m.message_number, a.application_short_name from fnd_new_messages m, fnd_application a where m.message_name like '%&EnterMessageName%' and m.language_code = 'US' and m.application_id = a.application_id; 2.2. Review Oracle Application Programsa. Looking for trace files (Also see Note 296559.1 for more examples on various versions / releases.)
PROMPT IDENTIFY CONCURRENT REQUEST FILE
PROMPT From Bug.3211206 PROMPT Use the following query to identify the correct trace file: PROMPT where "request" is the concurrent request id for the inventory transaction PROMPT worker. SELECT 'Request id: '||request_id , 'Trace id: '||oracle_Process_id, 'Trace Flag: '||req.enable_trace, 'Trace Name: '||dest.value||'/'||lower(dbnm.value)||'_ora_'||oracle_process_id||'.trc', 'Prog. Name: '||prog.user_concurrent_program_name, 'File Name: '||execname.execution_file_name|| execname.subroutine_name , 'Status : '||decode(phase_code,'R','Running') ||'-'||decode(status_code,'R','Normal'), 'SID Serial: '||ses.sid||','|| ses.serial#, 'Module : '||ses.module from fnd_concurrent_requests req, v$session ses, v$process proc, v$parameter dest, v$parameter dbnm, fnd_concurrent_programs_vl prog, fnd_executables execname where req.request_id = &request and req.oracle_process_id=proc.spid(+) and proc.addr = ses.paddr(+) and dest.name='user_dump_dest' and dbnm.name='db_name' and req.concurrent_program_id = prog.concurrent_program_id and req.program_application_id = prog.application_id and prog.application_id = execname.application_id and prog.executable_id=execname.executable_id; b. Another for programs and managers:
PROMPT Programs and Managers
PROMPT Provide various output of concurrent managers related to a specific program. PROMPT In this case using default of Item Supply/Demand program. SELECT fcq.processor_application_id, fcp.concurrent_program_name, fr.responsibility_id, fr.responsibility_key, fr.data_group_id, fr.request_group_id, fr.application_id, fa.application_short_name, fcq.concurrent_queue_id, fcq.CONCURRENT_QUEUE_NAME, fcq.MIN_PROCESSES, fcq.TARGET_PROCESSES, fcq.TARGET_NODE, fcq.SLEEP_SECONDS, fcq.CONTROL_CODE, fcq.DIAGNOSTIC_LEVEL, fcpr.* FROM fnd_application fa, fnd_concurrent_programs fcp, fnd_conc_processor_programs fcpp, fnd_responsibility fr, fnd_concurrent_queues fcq, fnd_concurrent_processes fcpr WHERE fcq.processor_application_id = fcpp.processor_application_id AND fcq.concurrent_processor_id = fcpp.concurrent_processor_id AND fcpp.concurrent_program_id = fcp.concurrent_program_id AND fcpp.program_application_id = fcp.application_id AND fcp.application_id = fa.application_id AND fcp.concurrent_program_name = NVL('&EnterProgramShortName', 'INXDSD') AND fr.application_id = 401 AND fr.data_group_id = fcq.data_group_id AND fcq.manager_type = '3' AND fcpr.concurrent_queue_id = fcq.concurrent_queue_id AND fcpr.queue_application_id = fcq.application_id -- AND fcpr.process_status_code = 'A' AND fcpr.instance_number = userenv('instance') ORDER BY dbms_random.random; c. Concurrent program statuses
PROMPT Concurrent program values
Select distinct lookup_code, meaning From Fnd_Lookup_Values Where Lookup_Type = 'CP_STATUS_CODE' order by lookup_code; A Waiting B Resuming C Normal D Cancelled E Error G Warning H On Hold I Normal M No Manager P Scheduled Q Standby R Normal S Suspended T Terminating U Disabled W Paused X Terminated Z Waiting d. Submitted Concurrent Programs
Select * From Fnd_Concurrent_Requests
Where Request_Id = &YourRequestID; Example Output: Phase_Code: C Status_Code: G Argument_Text: 207, 2, , Jbp1-M1-10, , Argument1: 207 Argument2: 2 Argument3: Null Argument4: JTP1-M1-10 CONCURRENT_PROGRAM_ID: 31534
e. Ensure trace is disabled
Update Fnd_Concurrent_Programs
Set Enable_Trace = 'N' where ENABLE_TRACE = 'Y';
2.3. Users and Responsibilitiesa. Basic user check
PROMPT Basic check for user details
select user_id, user_name, employee_id from fnd_user where user_name like '&EnterUserName%'; b. Active users
PROMPT Active Users
select fnd.user_name, icx.responsibility_application_id, icx.responsibility_id, frt.responsibility_name, icx.session_id, icx.first_connect, icx.last_connect, DECODE ((icx.disabled_flag),'N', 'ACTIVE', 'Y', 'INACTIVE') status from fnd_user fnd, icx_sessions icx, fnd_responsibility_tl frt where fnd.user_id = icx.user_id and icx.responsibility_id = frt.responsibility_id and icx.disabled_flag <> 'Y' and trunc(icx.last_connect) = trunc(sysdate) order by icx.last_connect;
c. Users with a responsibility
PROMPT Find users who have a responsibility
select usr.user_id, usr.user_name, res.RESPONSIBILITY_ID, res.RESPONSIBILITY_NAME from apps.FND_USER usr, apps.FND_RESPONSIBILITY_TL res, apps.FND_USER_RESP_GROUPS grp where upper(res.RESPONSIBILITY_NAME) like upper('%' || NVL('&EnterRespName', 'INV')|| '%') and upper(res.RESPONSIBILITY_NAME) NOT like '%AX%' and upper(res.RESPONSIBILITY_NAME) NOT like '%OPM%' and grp.responsibility_id = res.responsibility_id and grp.user_id = usr.user_id;
d. Values of a profile option
select
b.user_profile_option_name "Long Name" , a.profile_option_name "Short Name" , decode(to_char(c.level_id),'10001','Site' ,'10002','Application' ,'10003','Responsibility' ,'10004','User' ,'Unknown') "Level" , decode(to_char(c.level_id),'10001','Site' ,'10002',nvl(h.application_short_name,to_char(c.level_value)) ,'10003',nvl(g.responsibility_name,to_char(c.level_value)) ,'10004',nvl(e.user_name,to_char(c.level_value)) ,'Unknown') "Level Value" , c.PROFILE_OPTION_VALUE "Profile Value" , c.profile_option_id "Profile ID" , to_char(c.LAST_UPDATE_DATE,'DD-MON-YYYY HH24:MI') "Updated Date" , nvl(d.user_name,to_char(c.last_updated_by)) "Updated By" from apps.fnd_profile_options a , apps.FND_PROFILE_OPTIONS_VL b , apps.FND_PROFILE_OPTION_VALUES c , apps.FND_USER d , apps.FND_USER e , apps.FND_RESPONSIBILITY_VL g , apps.FND_APPLICATION h where --a.application_id = nvl(401, a.application_id) --and a.profile_option_name = nvl('INV', a.profile_option_name) b.user_profile_option_name like '&ProfileName' -- 'AFLOG_ENABLED' and a.profile_option_name = b.profile_option_name and a.profile_option_id = c.profile_option_id and a.application_id = c.application_id and c.last_updated_by = d.user_id (+) and c.level_value = e.user_id (+) and c.level_value = g.responsibility_id (+) and c.level_value = h.application_id (+) order by b.user_profile_option_name, c.level_id, decode(to_char(c.level_id),'10001','Site' ,'10002',nvl(h.application_short_name,to_char(c.level_value)) ,'10003',nvl(g.responsibility_name,to_char(c.level_value)) ,'10004',nvl(e.user_name,to_char(c.level_value)) ,'Unknown');
2.4 Set Context / Initialize
Sometimes you want to run queries that reference profile options. To do this, you should first initialize the context of the current session to the user, responsibility and application being used. You can also set the context of the current inventory organization for queries that reference the organization context.
PROMPT Initialize context of profiles, etc.
PROMPT Note you can query the user id, responsibility id, PROMPT and application id from the FND tables. execute fnd_global.APPS_INITIALIZE(&UserID, &ResponsibilityID, &ApplicationID);
PROMPT Set organization
PROMPT Note you can query the organization idea from mtl_parameters. execute fnd_client_info.set_org_context('&OrganizationID'); 3. Manufacturing3.1 Manufacturing GeneralPROMPT MANUFACTURING PROMPT Find standard codes and their meanings select lookup_type, lookup_code, substr(meaning, 1, 60) "Meaning" from mfg_lookups where upper(lookup_type) like upper('%'||NVL('&YourType', 'N/A')||'%') or lookup_type IN('SERIAL_NUM_STATUS', 'MTL_PRIMARY_COST', 'MTL_CC_ENTRY_STATUSES', 'MTL_TXN_REQUEST_STATUS', 'MOVE_ORDER_TYPE') order by lookup_type, lookup_code;
3.2. Setup3.2.1. Inventorya. Transaction types
PROMPT MANUFACTURING: INVENTORY
PROMPT Transaction Type SELECT transaction_type_id, transaction_action_id, TRANSACTION_SOURCE_TYPE_ID, TRANSACTION_TYPE_NAME FROM MTL_TRANSACTION_TYPES WHERE to_char(transaction_type_id) like ('%&YourTransactionTypeID%') ORDER BY transaction_type_id; b. Transaction sources:
PROMPT Transaction Source
select transaction_source_type_id, transaction_source_type_name from mtl_txn_source_types where transaction_source_type_id like NVL('&TransSourceID', '%'); 3.3. Transactions3.3.0 Inventory + Order Managementa. View orders and lines of a given order number:
SELECT oh.order_number, oh.header_id, oh.ordered_date, oh.partial_shipments_allowed, oh.open_flag, oh.booked_flag, oh.cancelled_flag, oh.drop_ship_flag, ol.line_number, ol.line_id, ol.org_id, ol.order_quantity_uom, ol.shipping_quantity_uom, ol.cancelled_quantity, ol.shipped_quantity, ol.ordered_quantity, ol.fulfilled_quantity, ol.shipping_quantity, ol.ship_from_org_id, ol.ship_to_org_id, ol.inventory_item_id
FROM OE_ORDER_HEADERS_ALL OH, OE_ORDER_LINES_ALL OL WHERE ol.header_id = oh.header_id AND oh.order_number like '%&EnterOrderNumber%'; b. Sales orders and deliveries for a stuck interface transaction:
select
substr(mti.transaction_interface_id,1,7) "Txn Id", wdd.inv_interfaced_flag, wdd.source_code, wdd.released_status, wdd.delivery_detail_id, wda.delivery_id, substr(mti.inventory_item_id,1,12) "Item Id", substr(mti.organization_id,1,4) "Org Id", substr(mti.subinventory_code,1,12) "Subinv", substr(decode(mti.locator_id,NULL, 'No Loc',mti.locator_id),1,9) "Loc Id", substr(decode(mti.revision,NULL, 'No Rev',mti.revision),1,7) "Rev", substr(mti.transaction_quantity,1,9) "Txn Qty", substr(mti.transaction_date,1,9) "Txn Date", substr(mti.transaction_type_id,1,7) "Type", substr(decode(mti.transaction_source_id,NULL, 'Not Source Id',mti.transaction_source_id),1,15) "Src Id", substr(decode(mti.transfer_subinventory,NULL, 'Not a Transfer', mti.transfer_subinventory),1,15) "XFR Subinv", substr(decode(mti.transfer_locator,NULL, 'Not a Transfer', mti.transfer_locator),1,15) "XFR Loc", substr(decode(mti.trx_source_line_id,NULL,'Not Source Line',mti.trx_source_line_Id),1,15) "Src Line", substr(mti.process_flag,1,7) "PFlag", substr(mti.lock_flag,1,7) "LFlag", substr(mti.transaction_mode,1,5) "Mode", substr(mti.error_code,1,20) "E Code", substr(mti.error_explanation,1,300) "Explanation" from mtl_transactions_interface mti, oe_order_headers_all ooh, oe_order_lines_all ool, wsh_delivery_details wdd, wsh_delivery_assignments wda where ool.line_id = mti.trx_source_line_id and ool.header_id = ooh.header_id and mti.trx_source_delivery_id = wda.delivery_id and wda.delivery_detail_id = wdd.delivery_detail_id order by transaction_source_id, trx_source_line_id; c. View sales orders of a given stuck, pending temporary allocation:
SELECT mmtt.transaction_temp_id, mmtt.transaction_header_id, oh.order_number, ol.line_number, ol.line_id
FROM MTL_MATERIAL_TRANSACTIONS_TEMP MMTT, OE_ORDER_HEADERS_ALL OH, OE_ORDER_LINES_ALL OL WHERE mmtt.trx_source_line_id = ol.line_id AND ol.header_id = oh.header_id AND mmtt.transaction_source_type_id IN (2, 8);
3.3.1. Inventory Transactionsa. Stuck interface transactions (Group By)
PROMPT Stuck Transactions - GroupBy MTI
select transaction_type_id, organization_id, substr(error_code, 1, 30), substr(error_explanation, 1, 50), to_char(transaction_date, 'YYYY-MM'), count(*) from mtl_transactions_interface group by transaction_type_id, organization_id, to_char(transaction_date, 'YYYY-MM'), substr(error_code, 1, 30), substr(error_explanation, 1, 50); b. Stuck pending transactions (Group By)
PROMPT Stuck Transactions - GroupBy MMTT
select transaction_type_id, organization_id, substr(error_code, 1, 30), substr(error_explanation, 1, 50), to_char(transaction_date, 'YYYY-MM'), count(*) from mtl_material_transactions_temp group by transaction_type_id, organization_id, to_char(transaction_date, 'YYYY-MM'), substr(error_code, 1, 30), substr(error_explanation, 1, 50); c. Stuck move order transactions (Group By)
PROMPT Stuck Transactions - GroupBy Move Order
select transaction_type_id, to_char(transaction_date,'YYYY-MON'), decode(transaction_status,2,'Untransacted Move order', transaction_status), error_code, error_explanation, count(*) from mtl_material_transactions_temp where organization_id = &Org_id group by transaction_type_id, to_char(transaction_date,'YYYY-MON'), decode(transaction_status,2,'Untransacted Move order', transaction_status), error_code, error_explanation; d. Uncosted transactions (Group By)
PROMPT Uncosted Transactions - GroupBy MMT
select transaction_type_id, organization_id, costed_flag, to_char(transaction_date, 'YYYY-MM'), error_code, substr(error_explanation, 1, 50), count(*) from mtl_material_transactions where costed_flag IN ('N','E') group by transaction_type_id, organization_id, costed_flag, to_char(transaction_date, 'YYYY-MM'), error_code, substr(error_explanation, 1, 50); e. Dump information about transaction tables
PROMPT Stuck Transactions Dump - MTI
select transaction_interface_id, inventory_item_id, organization_id, subinventory_code, locator_id, revision, transaction_quantity, transaction_date, transaction_type_id, transaction_source_id, transfer_subinventory, transfer_locator, trx_source_line_id, cost_group_id, process_flag, lock_flag, transaction_mode, error_explanation, error_code from mtl_transactions_interface order by transaction_source_id, trx_source_line_id; PROMPT Stuck Transactions Dump - MMTT select transaction_temp_id, inventory_item_id, organization_id, subinventory_code, locator_id, revision, transaction_quantity, transaction_date, transaction_type_id, transaction_source_id, transfer_subinventory, transfer_to_location, trx_source_line_id, cost_group_id, process_flag, lock_flag, transaction_mode, error_explanation, error_code from mtl_material_transactions_temp order by transaction_source_id, trx_source_line_id; PROMPT Stuck Transactions Dump - MMT select transaction_id, inventory_item_id, organization_id, subinventory_code, locator_id, revision, transaction_quantity, transaction_date, transaction_type_id, transaction_source_id, transfer_subinventory, transfer_locator_id, trx_source_line_id, cost_group_id, error_explanation, error_code, from mtl_material_transactions where costed_flag IN ('N','E') order by transaction_source_id, trx_source_line_id; REFERENCESBUG:3211206 - FAILED TO PACK/UNPACK ON PHYSICAL INVENTORY ADJUSTMENT ORA-01403NOTE:296559.1 - FAQ: Common Tracing Techniques in Oracle E-Business Applications 11i and R12 NOTE:568012.1 - FAQ: Inventory Standard Datafixes |