Using profile option ‘Initialization SQL Statement -Custom’
- Profile option check – Initialization SQL Statement – Oracle
- How do you check the profile option values using sql – Oracle Applications?
- Setting the Applications Context FND_GLOBAL.APPS_INITIALIZE in oracle applications.
- What are the profile setup values for ipayment gateway (oracle applications)?
- Oracle Applications: Another SQL script to find the profile option values.
How to set ‘Initialization SQL Statement – Custom’ (FND_INIT_SQL) profile option?
This is used to get trace files for the concurrent Programs you run through oracle applications. User mainly by technical persons who are trying to solve an issue where manipulating some database session level parameter can help to gather more information.
Using the profile option ‘Initialization SQL Statement – Custom’, you can add site-specific initialization code, such as optimizer settings. This profile value must be a valid SQL statement, or a PL/SQL block for more than one statement, that is to be executed once at the startup of every database session.
The code is executed by FND_GLOBAL.INITIALIZE and APPS_INITIALIZE immediately after initializing global variables, profiles, and the contents of client_info on session startup.
The order of execution is:
FND_GLOBAL values initialized Profiles initialized
CLIENT_INFO contents initialized
FND_APPS_INIT_SQL initialization code called (if a value is defined)
FND_INIT_SQL initialization code called (if a value is defined)
This means that in most cases (eg. tracing a form) the profile option setting will be effective after signing-on again. You can set this profile option at different levels like user/responsibility/ /application or site.
You can specify any valid SQL statement or a PL/SQL block for this profile value, but the best way is using the fnd_sess_ctl procedure of fnd_ctl package.
The value of this profile option can be set using fnd_sess_ctl as follows:
BEGIN
FND_CTL.FND_SESS_CTL(
,
,
,
,
,
);
END;
The different parameters are (all within single quotes) :
-> This sets the Optimizer_mode for online users. The valid values are RULE/CHOOSE/FIRST_ROWS/ALL_ROWS.
It is recommended for CBO you set it to FIRST_ROWS.
-> This sets the Optimizer_mode for conc. jobs. The valid values are RULE/CHOOSE/FIRST_ROWS/ALL_ROWS .
It is recommeneded for CBO you set it to ALL_ROWS.
-> This sets the trace option to true or false. Valid values are TRUE/FALSE. If set to true then you will be able to generate the trace files for the session.
-> This sets the times_statistics for tracing to true or false. Valid values are TRUE/FALSE.
-> Reserved for logging. Logs session information in FND_TRACE_LOG. Recommended value is ”, other possible value is LOG.
-> This can be set for different events. An example could be to set an event point in order to get the values of the bind values in the trace file. In that case the example setting is as follows.
‘ALTER SESSION SET EVENTS = ””””” 10046 TRACE NAME CONTEXT FOREVER, LEVEL 4 ”””’ .
Please make sure you have all the quotes correct.
Examples:
———
1) To enable SQL trace for the session, you should set the profile option as follows:
BEGIN FND_CTL.FND_SESS_CTL(”,”,’TRUE’,'TRUE’,”,”); END;
Result of the above setting will be the execution of the following two alter session commands at database session startup:
ALTER SESSION SET SQL_TRACE = ‘TRUE’
ALTER SESSION SET TIMED_STATISTICS = ‘TRUE’
2) To put an event statement for getting bind variables in the trace file set the profile option as follows
BEGIN FND_CTL.FND_SESS_CTL(”,”,”,”,”,’ALTER SESSION SET EVENTS =””””” 10046 TRACE NAME CONTEXT FOREVER, LEVEL 12 ”””’); END;
3) To set the logging on,
set the profile options (Initialization SQL statement – custom) as follows:
BEGIN FND_CTL.FND_SESS_CTL(”,”,”,”,’LOG’,”); END;
begin fnd_ctl.fnd_sess_ctl(”,”,’TRUE’,'TRUE’,”, ‘ALTER SESSION SET EVENTS=”””””10046 TRACE NAME CONTEXT FOREVER, LEVEL 12”””””TRACEFILE_IDENTIFIER=”””””JIL”””’);end;
For this option the log table is FND_TRACE_LOG, This table should be purged periodically.
If this LOG mode is set then then following information will be inserted in FND_TRACE_LOG table (every time when fnd_global.initialize procedure is called):
user_name,
sysdate,
conc_request_id,
oltp_opt_mode, (optimizer mode for online transactions)
conc_opt_mode, (optimizer mode for concurrent programs)
conc_program_name,
user_conc_program_name,
resp_name,
application_short_name
Here I am setting the custom sql for sysadmin for test purposes.



WARNINGS
——–
1) Do not ever set profile option ‘Initialization SQL Statement – Oracle’ instead of ‘Initialization SQL Statement – Custom’.
‘Initialization SQL Statement – Oracle’ (FND_APPS_INIT_SQL) profile option is used by Oracle Applications to add application-specific initialization code.
This profile option is set at the application level only, and will only be executed for responsibilities owned by that application. This profile option and its value settings are delivered as seed data, and must not be modified.
2) Setting of profile option ‘Initialization SQL Statement – Custom’ can effect on the operation of the whole Applications. As far as possible set this profile option only on USER level. Syntax error can cause that users can not login to the Applications or cannot run any concurrent programs. Please make sure syntax is correct. If you set this profile option on site level and a syntax error is in the profile value then it would cause that nobody can login to the applications.
In this situation the error message is something similar: ORA-20001: Oracle error -20001: ORA-20001: -: While executing SQL in profile FND_INIT_SQL:BEGIN FND_CTL.FND_SESS_CTL(’RUL’,”,”,”,’LOG’,”)has been detected in FND_GLOBAL.INITIALIZE.
If you cannot login to Applications with any apps user then you can correct this in SQL*Plus by selecting and updating the profile_option_value:
FROM fnd_profile_options opt, fnd_profile_option_values val
WHERE opt.profile_option_name = ‘FND_INIT_SQL’ AND opt.profile_option_id = val.profile_option_id;
You can correct the syntax error or can set profile_option_value to NULL and then define it in the Applications again (preferred way):
AND level_id = AND level_value = ;
How to check the existing values of ‘Initialization SQL Statement -Custom’?
val.level_id,
val.level_value,
val.profile_option_id,
val.profile_option_value
FROM
fnd_profile_options opt,
fnd_profile_option_values val
WHERE
opt.profile_option_name = ‘FND_INIT_SQL’ AND
opt.profile_option_id = val.profile_option_id;
Following script used to set the values using sqlplus instead of sys.adm -> profile value.
The script can be downloaded here
var v_ts varchar2(30);
BEGIN
SELECT value
INTO :v_mdfs
FROM v$parameter
WHERE name = ‘max_dump_file_size’;
SELECT value
INTO :v_ts
FROM v$parameter
WHERE name = ‘timed_statistics’;
END;
/
SET term ON;
PROMPT
PROMPT
PROMPT You are about TO turn SQL Trace ON FOR ALL new sessions, Forms OR
PROMPT Concurrent Program FOR SINGLE Applications User BY USING
PROMPT EVENT 10046 WITH LEVEL 12 (WAITS plus BIND VARIABLES)
PROMPT
PROMPT IN Applications do NOT SET Trace through Help>Diagnostics>Trace.
PROMPT NEITHER should your Concurrent Program have Trace Enabled USING the Form
PROMPT Concurrent Program Define. NOR a Profile turning Trace ON should be
PROMPT used.
PROMPT
PAUSE Press ENTER TO continue…
PROMPT
PROMPT Choose applicable Responsibility, AND just before opening Form, press ENTER
PROMPT IN this SQL*Plus session. FOR Concurrent Requests navigate TO the Form that
PROMPT submits your Concurrent Program, AND just before clicking the SUBMIT button,
PROMPT press ENTER IN this SQL*Plus session.
PROMPT
PROMPT Once you press ENTER IN this SQL*Plus session, applicable Applications
PROMPT Username AND SR (TAR) Number are TO be enteredand
PROMPT Profile ‘Initialization SQL Statement – Custom’ gets its value. ALL new
PROMPT sessions, Forms AND Concurrent Requests, will be affected.
PROMPT
PROMPT TO minimize the number of sessions being traced, turn OFF this
PROMPT EVENT 10046 AS soon AS possible (after reproduction IN Form OR start of
PROMPT Concurrent Request). You just need TO press ENTER again.
PROMPT
PROMPT
PROMPT Applications User FOR which tracing of new sessions IS TO be started
ACCEPT username PROMPT ‘Username : ‘
ACCEPT tar PROMPT ‘SR (TAR) Number : ‘
PROMPT
SET heading off
SET feedback 0
SET echo off
SET verify off
SELECT TO_CHAR(sysdate,‘DD-MON-YY HH24:MI:SS’) "Start" FROM dual;
ALTER SYSTEM SET max_dump_file_size = unlimited;
ALTER SYSTEM SET timed_statistics = true;
DEFINE deftrace=‘begin fnd_ctl.fnd_sess_ctl(’”””‘,’”””‘,’”‘TRUE’”‘,’”‘TRUE’”‘,’”””‘, ‘”‘ALTER SESSION SET EVENTS=’”””””””””””””‘10046 TRACE NAME CONTEXT FOREVER, LEVEL 12′”””””””””””””‘TRACEFILE_IDENTIFIER=’”””””””””””””‘SR&tar’””””””””””‘); end;’
INSERT INTO fnd_profile_option_values
(application_id,profile_option_id,level_id,level_value,
last_update_date,last_updated_by,creation_date,created_by,
last_update_login,profile_option_value,level_value_application_id)
SELECT 0,profile_option_id, 10004, user_id,
sysdate,0,sysdate,0,0,
‘&deftrace’, NULL
FROM fnd_profile_options, fnd_user
WHERE profile_option_name = ‘FND_INIT_SQL’
AND user_name = upper(‘&username’);
COMMIT;
PROMPT
PROMPT Inserted Profile value
PROMPT
PROMPT Start reproduction of your issue…
PROMPT
PROMPT
PAUSE Afterwards press ENTER TO disable tracing FOR new sessions
PROMPT
DELETE fnd_profile_option_values
WHERE application_id=0
AND level_id=10004
AND level_value =
(SELECT user_id
FROM fnd_user
WHERE user_name = upper(‘&&username’))
AND profile_option_id =
(SELECT profile_option_id
FROM fnd_profile_options
WHERE profile_option_name = ‘FND_INIT_SQL’);
COMMIT;
DECLARE
v_sql VARCHAR2(1000);
BEGIN
v_sql:=‘ALTER SYSTEM SET timed_statistics = ‘”:v_ts;
EXECUTE IMMEDIATE v_sql;
v_sql:=‘ALTER SYSTEM SET max_dump_file_size = ‘”:v_mdfs;
EXECUTE IMMEDIATE v_sql;
END;
/
PROMPT New sessions will NOT have EVENT 10046 turned ON. Be aware that ALL
PROMPT sessions that started BETWEEN the time the EVENT 10046 was turned ON
PROMPT AND the time it was turned OFF, will continue TO be traced until
PROMPT they complete.
PROMPT
PROMPT
PROMPT CHECK FOR trace file:
SELECT ‘ ‘”p1.value”‘/ora_*_’”‘SR&tar’”‘.trc’
FROM v$parameter p1
, v$instance i
WHERE p1.name = ‘user_dump_dest’;
PROMPT
PROMPT
PAUSE Press ENTER TO exit
SELECT TO_CHAR(sysdate,‘DD-MON-YY HH24:MI:SS’) "End" FROM dual;
PROMPT
PROMPT
EXIT

Hi,
This is a very informative blog. I want to run some PL/SQL code at the time when user logs in and i was using FND_PRODUCT_INITIALIZATION_PKG.REGISTER package for that with which i can call same PL/SQL code again and again based on init condition which can be based on responsibility change, organization change, application change etc but could not get enough details regarding that. Then i found your blog which talks about running PL/SQL code at the time of user session initialization. I was wondering, can we use same procedure for rest of the init conditions as well which i mentioned earlier or would you be able to give me some details about FND_PRODUCT_INITIALIZATION_PKG.REGISTER package.
Thanks in advance.
Kind regards
Ankit