15 May, 2015

Claender Query

SELECT   LPAD (MONTH, 20 - (20 - LENGTH (MONTH)) / 2) MONTH, "Su", "Mo", "Tu",
         "We", "Th", "Fr", "Sa"
    FROM (SELECT   TO_CHAR (dt, 'fmMonthfm YYYY') MONTH,
                   CASE
                      WHEN TO_CHAR (dt, 'fmMonthfm YYYY') LIKE 'Dec%'
                      AND TO_CHAR (dt + 1, 'iw') = '01'
                         THEN '53'
                      WHEN TO_CHAR (dt, 'fmMonthfm YYYY') LIKE 'Jan%'
                      AND TO_CHAR (dt + 1, 'iw') = '53'
                         THEN '.5'
                      ELSE TO_CHAR (dt + 1, 'iw')
                   END week,
                   MAX (DECODE (TO_CHAR (dt, 'd'),
                                '1', LPAD (TO_CHAR (dt, 'fmdd'), 2)
                               )
                       ) "Su",
                   MAX (DECODE (TO_CHAR (dt, 'd'),
                                '2', LPAD (TO_CHAR (dt, 'fmdd'), 2)
                               )
                       ) "Mo",
                   MAX (DECODE (TO_CHAR (dt, 'd'),
                                '3', LPAD (TO_CHAR (dt, 'fmdd'), 2)
                               )
                       ) "Tu",
                   MAX (DECODE (TO_CHAR (dt, 'd'),
                                '4', LPAD (TO_CHAR (dt, 'fmdd'), 2)
                               )
                       ) "We",
                   MAX (DECODE (TO_CHAR (dt, 'd'),
                                '5', LPAD (TO_CHAR (dt, 'fmdd'), 2)
                               )
                       ) "Th",
                   MAX (DECODE (TO_CHAR (dt, 'd'),
                                '6', LPAD (TO_CHAR (dt, 'fmdd'), 2)
                               )
                       ) "Fr",
                   MAX (DECODE (TO_CHAR (dt, 'd'),
                                '7', LPAD (TO_CHAR (dt, 'fmdd'), 2)
                               )
                       ) "Sa"
              FROM (SELECT TRUNC (SYSDATE, 'y') - 1 + ROWNUM dt
                      FROM all_objects
                     WHERE ROWNUM <=
                                ADD_MONTHS (TRUNC (SYSDATE, 'y'), 12)
                              - TRUNC (SYSDATE, 'y'))
          GROUP BY TO_CHAR (dt, 'fmMonthfm YYYY'), TO_CHAR (dt + 1, 'iw')
          ORDER BY TO_CHAR (dt + 1, 'iw'))
ORDER BY TO_DATE (MONTH, 'Month YYYY'), TO_NUMBER (week)

Discoverer with EBS in R12 (DISCOVERER REPORT REGISTRATION PROCESS)

* Navigate > System Administrator > Application > Function

* Go to the Description TAB

    * Enter Function Name =test_DWB
    * Enter User Function Name =TESTDISCO Function DWB
    * Enter Description = This Function Created to test discoverer 11g for R12.

We appended a suffix of “_DWB” at the end of the function name to indicate this is a Discoverer Workbook function. You may choose any other name for your function but it is a good idea to keep the function name same as the developer key for easy identification and tracking.

    * Now Go to the Properties TAB
    * Select Type = SSWA jsp function
    * Maintenance Mode Support = None
    * Context Dependence = Responsibility

* Now Go to Form TAB
   
* Enter Parameters =>  mode=DISCO

* Now Go to Web HTML TAB
   
* Enter HTML Call = OracleOasis.jsp and then Click on the Save Button

Now that we have created our Form Function we will create a new menu
“TESTDISCO” to hold this function.



Navigate > System Administrator > Application > Menus

Create a new menu “TESTDISCO”

Then attach the function to this menu “TESTDISCO Function DWB”
Prompt : “Test Discoverer Reports”

Save.


Now Attach this Menu to Responsibility.


Navigate > System Administrator > Security>Responsibility> Define

Responsibility Name:  Test Discoverer Reports

Application : Applications BIS  (for Example I used this).
(here you can use related application like (Payables, Purchasing, Assets, Human resource, etc).

Responsibility  Key :TESTDISCO

Menu : TESTDISCO  (attach here previously created).

SAVE.

Now you can add this Responsibility to the user.


Navigate > System Administrator > Security>User> Define



Before connecting to Oracle Discoverer as an Oracle Applications user, we must configure the Connect dialog to default to Oracle Applications users. Select Tools > Options to display the “Options dialog: Connection tab”.
To create an End User Layer in an Oracle database, the database user that the EUL is being created in must have the following database privileges:

      • CREATE SESSION
      • CREATE TABLE
      • CREATE VIEW
      • CREATE SEQUENCE
      • CREATE PROCEDURE

AP Trail Balances SQL Query for 11i

SELECT alb.invoice_id invoice_id,inv.INVOICE_NUM,inv.DESCRIPTION INV_DESCRIPTION,
alb.vendor_id vendor_id,pv.SEGMENT1 Vendor#,pv.VENDOR_NAME,
alb.code_combination_id code_combination_id, 
SUM(ae_invoice_amount) invoice_amount,
SUM (alb.accounted_cr) - SUM (alb.accounted_dr) remaining_amount, 
alb.set_of_books_id set_of_books_id, 
alb.org_id org_id,
GCC.SEGMENT1,GCC.SEGMENT2,GCC.SEGMENT3,
INV.INVOICE_TYPE_LOOKUP_CODE,INV.INVOICE_DATE,INV.ATTRIBUTE5 Status,apt.NAME Terms
FROM ap_liability_balance alb,
PO_VENDORS PV,AP_INVOICES_ALL INV,
GL_CODE_COMBINATIONS GCC,
 AP_TERMS apt
WHERE PV.VENDOR_ID=alb.VENDOR_ID
and INV.INVOICE_ID=alb.INVOICE_ID
and alb.CODE_COMBINATION_ID=gcc.CODE_COMBINATION_ID
and apt.TERM_ID=INV.TERMS_ID
AND alb.ORG_ID =:org_id  
and trunc(accounting_date) <=:Date1
GROUP BY alb.invoice_id, alb.code_combination_id, alb.vendor_id, alb.set_of_books_id, alb.org_id ,
pv.SEGMENT1,pv.VENDOR_NAME,inv.INVOICE_NUM,inv.DESCRIPTION,GCC.SEGMENT1,GCC.SEGMENT2,GCC.SEGMENT3,
INV.INVOICE_TYPE_LOOKUP_CODE,INV.INVOICE_DATE,INV.ATTRIBUTE5,apt.NAME
HAVING SUM (accounted_cr) <> SUM (accounted_dr)

User Function (oracle APPS)

create function mazeeddecrypt(key in varchar2, value in varchar2)
return varchar2 as
language java name 'oracle.apps.fnd.security.WebSessionManagerProc.decrypt(java.lang.String,java.lang.String) return java.lang.String';


SELECT fnd_user.user_name, fnd_user.LAST_UPDATE_DATE,
  fnd_user.description,mazeeddecrypt('APPS' , fnd_user.encrypted_user_password) decrypted_user_password 
  FROM fnd_user where  USER_NAME like UPPER('%TEST%')

Discoverer Desktop/Administrator tools Installation Steps (Secure Env)

1) Install BI Tool (discoverer) using below link:http://www.oracle.com/technology/software/products/ids/htdocs/101202winsoft.html
 or
install dektop and administrator from the setup cd.

Identify the Oracle Home for Discoverer
For example: You could find dis51usr.exe under the directory D:\oracle\BIToolsHome_1\bin. Then the Oracle Home is D:\oracle\BIToolsHome_1


2) Create SECURE folder in this path D:\oracle\BIToolsHome_1\discoverer\secure 
and copy the file "example.dbc" to this dir. 
(Discoverer requires Windows Environment variables to dynamically retrieve the location of the .dbc file on the PC.)


3.copy this (SET FND_SECURE=D:\oracle\BIToolsHome_1\discoverer\secure) path and add to "AUTOEXEC.BAT" file in "C Drive".




4. place TNSNAMES.ora file to this path (D:\oracle\BIToolsHome_1\network\ADMIN) for Discoverer tools.

XYZ is not a valid responsibility for current user. Please contact your System Administrator

If We See issue like below.



We need to follow below steps:


Step 1: Logon with System Administrator responsibility


Step 2:  Navigate to Profile > System, click on User and enter the user name


Step 3:  Search for profile 'Applications Start Page'. Delete the value set at user level and save

Step 4:  Try it now.

12 May, 2015

Database Growth History and Forecast

To get information about individual tablespaces growth history and forecast, please see my article and scripts by clicking here.


Starting Oracle 10G, Oracle records tablespaces usage (allocated, used etc.) in AWR which can be retrieved by querying the data dictionary view dba_hist_tbspc_space_usage. Using information in dba_hist_tbspc_space_usage, following script can be used to view the history of database usage and predict the expected growth for the future. Growth forecast is based on daily growth in the past.

Things to note:
1) This script is based on AWR. If your AWR retention period is 7 days, this script can only tell the growth history of last 7 days and predict based on last 7 days growth. I would recommend to have AWR retention to at least 30 days - this will also be more helpful in case of performance tuning situation as you will have a longer window of the past to look into for performance comparisons.
2) This script does not including TEMP and UNDO tablespaces while analyzing and forecasting
3) You may edit this scrip according to your requirement to forecast for a period  which suites your requirements. By default it will predict expected growth for next 30, 60 and 90 days.
4) Log in as user SYS on SQLPLUS and copy and paste the following code.

##############################################
set serverout on
set verify off
set lines 200
set pages 2000
DECLARE
v_ts_id number;
v_ts_block_size number;
v_begin_snap_id number;
v_end_snap_id number;
v_begin_snap_date date;
v_end_snap_date date;
v_numdays number;
v_ts_begin_size number;
v_ts_end_size number;
v_ts_growth number;
v_ts_begin_allocated_space number;
v_ts_end_allocated_space number;
v_db_begin_size number := 0;
v_db_end_size number := 0;
v_db_begin_allocated_space number := 0;
v_db_end_allocated_space number := 0;
v_db_growth number := 0;
cursor v_cur is select tablespace_name from dba_tablespaces where contents='PERMANENT';

BEGIN

FOR v_rec in v_cur
LOOP

BEGIN
v_ts_begin_allocated_space := 0;
v_ts_end_allocated_space := 0;
v_ts_begin_size := 0;
v_ts_end_size := 0;

SELECT ts# into v_ts_id FROM v$tablespace where name = v_rec.tablespace_name;
SELECT block_size into v_ts_block_size FROM dba_tablespaces where tablespace_name = v_rec.tablespace_name;
SELECT min(snap_id), max(snap_id), min(trunc(to_date(rtime,'MM/DD/YYYY HH24:MI:SS'))), max(trunc(to_date(rtime,'MM/DD/YYYY HH24:MI:SS')))
into v_begin_snap_id,v_end_snap_id, v_begin_snap_date, v_end_snap_date from dba_hist_tbspc_space_usage where tablespace_id=v_ts_id;
v_numdays := v_end_snap_date - v_begin_snap_date;

SELECT round(max(tablespace_size)*v_ts_block_size/1024/1024,2) into v_ts_begin_allocated_space from dba_hist_tbspc_space_usage where tablespace_id=v_ts_id and snap_id = v_begin_snap_id;
SELECT round(max(tablespace_size)*v_ts_block_size/1024/1024,2) into v_ts_end_allocated_space from dba_hist_tbspc_space_usage where tablespace_id=v_ts_id and snap_id = v_end_snap_id;
SELECT round(max(tablespace_usedsize)*v_ts_block_size/1024/1024,2) into v_ts_begin_size from dba_hist_tbspc_space_usage where tablespace_id=v_ts_id and snap_id = v_begin_snap_id;
SELECT round(max(tablespace_usedsize)*v_ts_block_size/1024/1024,2) into v_ts_end_size from dba_hist_tbspc_space_usage where tablespace_id=v_ts_id and snap_id = v_end_snap_id;

v_db_begin_allocated_space := v_db_begin_allocated_space + v_ts_begin_allocated_space;
v_db_end_allocated_space := v_db_end_allocated_space + v_ts_end_allocated_space;
v_db_begin_size := v_db_begin_size + v_ts_begin_size;
v_db_end_size := v_db_end_size + v_ts_end_size;
v_db_growth := v_db_end_size - v_db_begin_size;

END;
END LOOP;

DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('Summary');
DBMS_OUTPUT.PUT_LINE('========');
DBMS_OUTPUT.PUT_LINE('1) Allocated Space: '||v_db_end_allocated_space||' MB'||' ('||round(v_db_end_allocated_space/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('2) Used Space: '||v_db_end_size||' MB'||' ('||round(v_db_end_size/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('3) Used Space Percentage: '||round(v_db_end_size/v_db_end_allocated_space*100,2)||' %');
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('History');
DBMS_OUTPUT.PUT_LINE('========');
DBMS_OUTPUT.PUT_LINE('1) Allocated Space on '||v_begin_snap_date||': '||v_db_begin_allocated_space||' MB'||' ('||round(v_db_begin_allocated_space/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('2) Current Allocated Space on '||v_end_snap_date||': '||v_db_end_allocated_space||' MB'||' ('||round(v_db_end_allocated_space/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('3) Used Space on '||v_begin_snap_date||': '||v_db_begin_size||' MB'||' ('||round(v_db_begin_size/1024,2)||' GB)' );
DBMS_OUTPUT.PUT_LINE('4) Current Used Space on '||v_end_snap_date||': '||v_db_end_size||' MB'||' ('||round(v_db_end_size/1024,2)||' GB)' );
DBMS_OUTPUT.PUT_LINE('5) Total growth during last '||v_numdays||' days between '||v_begin_snap_date||' and '||v_end_snap_date||': '||v_db_growth||' MB'||' ('||round(v_db_growth/1024,2)||' GB)');
IF (v_db_growth <= 0 OR v_numdays <= 0) THEN
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('No data growth was found for the Database');
ELSE
DBMS_OUTPUT.PUT_LINE('6) Per day growth during last '||v_numdays||' days: '||round(v_db_growth/v_numdays,2)||' MB'||' ('||round((v_db_growth/v_numdays)/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('Expected Growth');
DBMS_OUTPUT.PUT_LINE('===============');
DBMS_OUTPUT.PUT_LINE('1) Expected growth for next 30 days: '|| round((v_db_growth/v_numdays)*30,2)||' MB'||' ('||round(((v_db_growth/v_numdays)*30)/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('2) Expected growth for next 60 days: '|| round((v_db_growth/v_numdays)*60,2)||' MB'||' ('||round(((v_db_growth/v_numdays)*60)/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('3) Expected growth for next 90 days: '|| round((v_db_growth/v_numdays)*90,2)||' MB'||' ('||round(((v_db_growth/v_numdays)*90)/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('If no data is displayed, it means that AWR does not have data about at least one tablespace of this database');
DBMS_OUTPUT.PUT_LINE('Execute DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT, or wait for next AWR snapshot capture before executing this script');
DBMS_OUTPUT.PUT_LINE('/\/\/\/\/\/\/\/\/\/\/ END \/\/\/\/\/\/\/\/\/\/\');

END IF;

EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('====================================================================================================================');
DBMS_OUTPUT.PUT_LINE('One or more Tablespaces usage information not found in AWR');
DBMS_OUTPUT.PUT_LINE('Execute DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT, or wait for next AWR snapshot capture before executing this script');
DBMS_OUTPUT.PUT_LINE('====================================================================================================================');

END;
/
##############################################

Please give your feedback if you find any difficulty in executing this script or if this script does not work for you.

Sample Output

Summary
========
1) Allocated Space: 42492 MB (41.5 GB)
2) Used Space: 30806.5 MB (30.08 GB)
3) Used Space Percentage: 72.5 %


History
========
1) Allocated Space on 07-DEC-14: 38776 MB (37.87 GB)
2) Current Allocated Space on 11-JAN-15: 42492 MB (41.5 GB)
3) Used Space on 07-DEC-14: 26445.89 MB (25.83 GB)
4) Current Used Space on 11-JAN-15: 30806.5 MB (30.08 GB)
5) Total growth during last 35 days between 07-DEC-14 and 11-JAN-15: 4360.61 MB (4.26 GB)
6) Per day growth during last 35 days: 124.59 MB (.12 GB)


Expected Growth
===============
1) Expected growth for next 30 days: 3737.67 MB (3.65 GB)
2) Expected growth for next 60 days: 7475.33 MB (7.3 GB)
3) Expected growth for next 90 days: 11213 MB (10.95 GB)

If no data is displayed, it means that AWR does not have data about at least one tablespace of this database
Execute DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT, or wait for next AWR snapshot capture before executing this script

/\/\/\/\/\/\/\/\/\/\/ END \/\/\/\/\/\/\/\/\/\/\

Finding OPP Manager log for a concurrent request

=> Use below query to find the OPP manager log for a concurrent request.  SELECT fcpp.concurrent_request_id req_id, fcp.node_name, fcp.lo...