Thursday 4 July 2013

Useful Query in Oracle APPS/HRMS

Finding Patch Set Level
SELECT * FROM (
SELECT '(Patch: ' || bug_number || ') applied ' || LAST_UPDATE_DATE PFbugDate
FROM ad_bugs
WHERE BUG_NUMBER IN (
'2115771',
'2268451',
'2502761',
'2632500',
'2803988',
'2968701', -- F
'3116666', -- G
'3233333', -- H
'3127777', -- I = 11.5.10 base
'3333633', -- J
'3500000', -- K
'3800000', -- L
'5055050') -- Rup1
ORDER BY LAST_UPDATE_DATE desc
) WHERE ROWNUM = 1;
---  **************************** -----

Find the key flex field structure
SELECT id_flex_structure_code structure_code,
DECODE (dynamic_inserts_allowed_flag,
'Y', 'OK: Dynamic',
'ERROR: No Dynamic'
) dynamic,
DECODE (freeze_flex_definition_flag,
'Y', 'OK: Freezed',
'ERROR: No Freezed'
) freeze,
segment_num seg_number, segment_name seg_name,
DECODE (required_flag,
'Y', 'OK: Required',
'ERROR: No required'
) required,
DECODE (fvs.flex_value_set_name,
NULL, 'NULL',
fvs.flex_value_set_name
) value_set,
DECODE (fvs.validation_type,
'N', 'OK: No validation',
'ERROR: ' || fvs.validation_type
) VALIDATION,
DECODE (fvs.uppercase_only_flag,
'N', 'OK: No',
'ERROR: Uppercase Only'
) uppercase_only,
DECODE (alphanumeric_allowed_flag,
'Y', 'OK: Allowed',
'ERROR: Not Allowed'
) alphanumeric,
DECODE (numeric_mode_enabled_flag,
'N', 'OK:Not justified',
'ERROR: Justified'
) right_justify,
DECODE (format_type,
'C', 'OK: Char',
'ERROR: ' || format_type
) format_type
FROM fnd_id_flex_structures_vl ffst,
fnd_id_flex_segments_vl ffsg,
fnd_flex_value_sets fvs
WHERE ffst.application_id = 800
AND ffst.id_flex_code = 'GRD'
AND ffst.enabled_flag = 'Y'
AND ffst.application_id = ffsg.application_id
AND ffst.id_flex_code = ffsg.id_flex_code
AND ffst.id_flex_num = ffsg.id_flex_num
AND ffsg.enabled_flag = 'Y'
AND fvs.flex_value_set_id(+) = ffsg.flex_value_set_id;

---  **************************** -----
Find the Descriptive flex field structure
SELECT apps.application_name "App",
d_flex.title "Title",
d_flex.application_table_name "Table",
d_flex.context_user_override_flag "DFF Disp",
d_flex.freeze_flex_definition_flag "Frozen",
d_flex.default_context_value "Default Ctx",
d_flex.context_required_flag "DFF Required",
ctx_val_s.flex_value_set_name "Ctx ValueSet",
ctx.descriptive_flex_context_name "Ctx",
ctx.enabled_flag "Ctx Enabled",
col.form_left_prompt "Prompt",
col.end_user_column_name "Column",
val_s.flex_value_set_name "Value Set",
col.enabled_flag " Col Enabled",
col.required_flag "Required",
col.application_column_name "App Column",
col.display_flag " Col Display",
col.default_value "Default Val",
col.security_enabled_flag "Security",
col.display_size,
col.maximum_description_len,
col.concatenation_description_len,
col.application_id,
d_flex.concatenated_segs_view_name,
col.descriptive_flexfield_name,
col.form_above_prompt,
col.descriptive_flex_context_code,
col.range_code,
col.flex_value_set_id,
col.default_type,
col.srw_param
FROM fnd_descr_flex_col_usage_vl col,
fnd_descr_flex_contexts_vl ctx,
fnd_descriptive_flexs_vl d_flex,
fnd_flex_value_sets val_s,
fnd_flex_value_sets ctx_val_s,
fnd_application_tl apps
WHERE d_flex.application_id IN (809,
808)
--AND Upper(d_flex.title) LIKE Upper('%Addtional Ben Pl F Details%')
AND d_flex.descriptive_flexfield_name = ctx.descriptive_flexfield_name
AND ctx.descriptive_flexfield_name = col.descriptive_flexfield_name (+)
AND col.descriptive_flex_context_code (+) = ctx.descriptive_flex_context_code
AND val_s.flex_value_set_id (+) = col.flex_value_set_id
AND ctx_val_s.flex_value_set_id (+) = d_flex.context_override_value_set_id
AND apps.application_id = d_flex.application_id
AND d_flex.application_table_name <> 'FND_SRS_MASTER'
ORDER BY apps.application_name,
d_flex.title,
ctx.descriptive_flex_context_name,
col.column_seq_num;
---  **************************** -----
Compile a Menu
declare
l_r number;
l_e varchar2(1000);
begin
fnd_function.compile(l_e,l_r,'N');
end;
---  **************************** -----

Retrieve Supervisory Hierarchy (CONNECT BY PRIOR)
SELECT lpad(' ',level*3)
||
(SELECT full_name
FROM per_all_people_f ppl
WHERE person_id = paf.person_id
AND rownum =1
) full_name,
(SELECT full_name
FROM per_all_people_f ppl
WHERE person_id = paf.supervisor_id
AND rownum =1
) sup ,
assignment_number,
position_id
FROM per_all_assignments_f paf
WHERE business_group_id = 81
AND assignment_type = 'E'
AND assignment_status_type_id = 1
AND sysdate BETWEEN effective_start_date AND effective_end_date START
WITH assignment_number = '2748' CONNECT BY prior person_id = supervisor_id;
---  **************************** -----

Initialize Apps (FND_GLOBAL.APPS_INTIALIZE)
declare
l_user_id number;
l_resp_id number;
l_resp_app_id number;
cursor get_user is
select user_id
from fnd_user
where user_name = ‘GSEHGAL’;
cursor get_resp is
select responsibility_id, application_id
from fnd_responsibility_vl
where responsibility_key = 'HIRING_MANAGER';
begin
open get_user;
fetch get_user into l_user_id;
close get_user;
open get_resp;
fetch get_resp into l_resp_id, l_resp_app_id;
close get_resp;
fnd_global.apps_initialize(l_user_id, l_resp_id,l_resp_app_id);

Scripts to find a string in a FAST FORMULA

1. Compile the following pkg in development instance.

create or replace package arj_pkg as

function long_to_varchar2 (p_tab IN VARCHAR2

,p_long_col IN VARCHAR2

,p_row_id in rowid)

return CLOB;

end arj_pkg;

/

create or replace package body arj_pkg as

function long_to_varchar2 (p_tab IN VARCHAR2

,p_long_col IN VARCHAR2

,p_row_id in rowid)

return CLOB is

-- v_size = number of characters to retrieve

v_cur integer;

v_rc integer;

v_size integer := 32000;

v_buffer varchar2(32000);

v_buf_len integer;

begin

v_cur := dbms_sql.open_cursor;

dbms_sql.parse(v_cur,'SELECT '||p_long_col||' FROM '||p_tab||' WHERE ROWID = :row_id',dbms_sql.native);

dbms_sql.bind_variable(v_cur, ':row_id', p_row_id);

dbms_sql.define_column_long(v_cur,1);

v_rc := dbms_sql.execute_and_fetch(v_cur);

dbms_sql.column_value_long(v_cur,1,v_size,0,v_buffer,v_buf_len);

dbms_sql.close_cursor(v_cur);

return substr(v_buffer,1,v_buf_len);

end long_to_varchar2;

end arj_pkg;

/
2.Run the following script

declare

--

v_search_string VARCHAR2(2000) := 'SAMPLE_STRING';

v_fmla_name FF_FORMULAS_F.formula_name%TYPE;

v_fmla_text CLOB;

--

cursor get_fmla (c_fmla_name IN varchar2)

is

SELECT

fff.rowid

,fff.formula_name

, TO_CHAR(fff.effective_start_date,'DD/MM/YYYY') effective_date

FROM ff_formulas_f fff

WHERE fff.formula_name LIKE c_fmla_name;

--

begin

FOR rec IN get_fmla ('%') LOOP

BEGIN

v_fmla_text := ccsl_pkg.long_to_varchar2('FF_FORMULAS_F','FORMULA_TEXT',rec.rowid);

IF UPPER(v_fmla_text) LIKE '%'||UPPER(v_search_string)||'%' THEN

DBMS_OUTPUT.PUT_LINE ('Formula '||rec.formula_name||

', eff date '|| rec.effective_date||

' contains the string '||v_search_string);

END IF;

-- EXCEPTION

END;

END LOOP;

--

--exception

end;