Tuesday, August 26, 2014

How to Handle the Date Parameter for Value set (FND_STANDARD_DATETIME) in Oracle R12

1. Define the Concurrent Program With Parameter as Date and attach the FND_STANDARD_DATETIME and in the PLSQL Block pass the Parameter to the Function defined below.

DECLARE
errbuf varchar2(240) := NULL;
retcode number := 0;
p_date varchar2(30) := '&1';

input_date date := FND_CONC_DATE.STRING_TO_DATE('&1');
BEGIN
FND_FILE.PUT_LINE(FND_FILE.OUTPUT, 'Writing to output file' );
FND_FILE.PUT_LINE(FND_FILE.OUTPUT, 'Parameter 1 = ' || nvl(p_date,'NULL'));
FND_FILE.PUT_LINE(FND_FILE.OUTPUT, 'Converted Date is '||input_date);
FND_FILE.PUT_LINE(FND_FILE.LOG, 'Writing to Logfile to test Date Parameters to
SQL*Plus');
FND_FILE.PUT_LINE(FND_FILE.LOG, 'Parameter 1 = ' || nvl(p_date,'NULL'));
FND_FILE.PUT_LINE(FND_FILE.LOG, 'Converted Date is '||input_date);
END;
/


PL/SQL Procedure

CREATE OR REPLACE PROCEDURE simple_pls (
errbuf out varchar2,
retcode out varchar2,
in_date in varchar2
)
is
input_date date;
begin
input_date := FND_CONC_DATE.STRING_TO_DATE(in_date);
fnd_file.put_line (fnd_file.output,'TEST to OUTPUT file');
fnd_file.put_line (fnd_file.output,'Original Date is '||in_date);
fnd_file.put_line (fnd_file.output,'Converted Date is '||input_date);
fnd_file.put_line (fnd_file.log,'Test to LOG File');
fnd_file.put_line (fnd_file.log,'Original Date is '||in_date);
fnd_file.put_line (fnd_file.log,'Converted Date is '||input_date);
end;
/

Saturday, August 23, 2014

Script to Compile Invalid Objects in a Schema


This procedure recompile invalid objects in a given schema or all invalid objects in the database.

Parameter :
 schema     (IN) - Schema in which to recompile invalid objects  If NULL, all invalid objects in the database are recompiled.

BEGIN
UTL_RECOMP.recomp_serial(p_schema_name);
END;

DESCRIPTION:
This procedure is the main driver that recompiles invalid objects
in the database (or in a given schema) in parallel in dependency
order. It uses information in dependency$ to order recompilation
of dependents after parents.

NOTES:
The parallel recompile exploits multiple CPUs to reduce the time taken to recompile invalid objects. However, please note that recompilation writes significant amounts of data to system tables,
so the disk system may be a bottleneck and prevent significant speedups.

   PARAMETERS:
Threads    (IN) - Number of recompile threads to run in parallel If NULL, 0, or negative, RECOMP_PARALLEL computes a default degree of parallelism as the product of Oracle parameters "cpu_count" and "parallel_threads_per_cpu". On a Real Application Clusters installation, the degree of parallelism is the sum of individual settings on each node in the cluster.
Schema     (IN) - Schema in which to recompile invalid objects If NULL, all invalid objects in the database
                         are recompiled.
Flags      (IN) - Option flags supported (as described above).
   

BEGIN
UTL_RECOMP.recomp_parallel(p_schema_name);
END;

Tuesday, August 19, 2014

How to use comma separated string build dynamically and pass to IN clause of select statement


In some cases, we get a comma separated string as output (say from another select statement) that we would need to pass to the IN clause of a select statement.

This article explains how to achieve that using regexp_substr (DB >=10g).

For example, assume a select statement returns the following
'SMITH,ALLEN,WARD,JONES'

Now, we would need to pass this to another select statement as IN clause and get the output.

SQL> select * from emp where ename in ('SMITH,ALLEN,WARD,JONES');

no rows selected

Well, this is not our expected output. We expect the query to return 4 rows.
This can be achieved by splitting the comma separated string to individual strings and pass it to the IN clause.

Oracle provides regexp_substr function, which comes handy for this scenario.
First, we will form a query, that splits this comma separated string and gives the individual strings as rows.

 

SQL> select regexp_substr('SMITH,ALLEN,WARD,JONES','[^,]+', 1, level) from dual
  2  connect by regexp_substr('SMITH,ALLEN,WARD,JONES', '[^,]+', 1, level) is not null;

REGEXP_SUBSTR('SMITH,A
----------------------
SMITH
ALLEN
WARD
JONES

The above query iterates through the comma separated string, searches for the comma (,) and then splits the string by treating the comma as delimiter. It returns the string as a row, whenever it hits a delimiter.

 

We can pass this query to our select statement to get the desired output.

 

SQL> select * from emp where ename in (
  2  select regexp_substr('SMITH,ALLEN,WARD,JONES','[^,]+', 1, level) from dual
  3  connect by regexp_substr('SMITH,ALLEN,WARD,JONES', '[^,]+', 1, level) is not null );

 

EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20

Now, the query returns what we expected.