Tuesday, March 24, 2015

Using SQL Minus to compare the difference of two tables

THE SQL MINUS OPERATOR IS USED TO RETURN ALL ROWS IN THE FIRST SELECT STATEMENT THAT ARE NOT RETURNED IN THE SECOND SELECT STATEMENT.

Each SELECT statement within the MINUS query must have the same number of fields in the result sets with similar data types.

SYNTAX

The syntax for the SQL MINUS operator is:
SELECT expression1, expression2, ... expression_n
FROM tables
MINUS
SELECT expression1, expression2, ... expression_n
FROM tables;

EXAMPLE - WITH SINGLE EXPRESSION

The following is a SQL MINUS operator example that has one field with the same data type:
SELECT supplier_id
FROM suppliers
MINUS
SELECT supplier_id
FROM orders;
This SQL MINUS example returns all supplier_id values that are in the suppliers table and not in the orders table. What this means is that if a supplier_id value existed in the suppliers table and also existed in the orders table, the supplier_id value would not appear in this result set.

EXAMPLE - USING ORDER BY CLAUSE

The following is a MINUS operator example that uses the ORDER BY clause:
SELECT supplier_id, supplier_name
FROM suppliers
WHERE supplier_id > 2000
MINUS
SELECT company_id, company_name
FROM companies
WHERE company_id > 1000
ORDER BY 2;
In this SQL MINUS operator example, since the column names are different between the two SELECT statements, it is more advantageous to reference the columns in the ORDER BY clause by their position in the result set. In this example, we've sorted the results by supplier_name / company_name in ascending order, as denoted by the "ORDER BY 2".
The supplier_name / company_name fields are in position #2 in the result set.

Monday, March 23, 2015

Remove special characters from string using regexp functions

There is a need to remove special characters and non-printable characters that users have accidentally entered into CSV files. For every varchar2 field, I'd like to keep characters inside the range from chr(32) to chr(126), and remove everything else. 

This is the query to solve the problem, it use regexp functions

select regexp_replace('This is a test $%&^*&*'||chr(10)||'*"ú%bsfd.', '( *[[:punct:]])', '') from dual

I really like how regexp functions can do, for more information, check more from here:  http://psoug.org/reference/regexp.html

Wednesday, March 18, 2015

Submit a Concurrent Request from PL/SQL script

We can submit a concurrent request from backend using fnd_request.submit_request API. Before submitting the API we need to set the environment context using fnd_global.apps_initialize
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/****************************************************************
*PURPOSE: To Submit a Concurrent Request using PL/SQL script    *
*Using fnd_request.submit_request                                                   *
****************************************************************/

DECLARE
l_responsibility_id  NUMBER;
l_application_id     NUMBER;
l_user_id            NUMBER;
l_request_id            NUMBER;
BEGIN
  --Find correct responsibility_id and application_id
  SELECT DISTINCT fr.responsibility_id,
    frx.application_id
     INTO l_responsibility_id,
    l_application_id
     FROM apps.fnd_responsibility frx,
    apps.fnd_responsibility_tl fr
    WHERE fr.responsibility_id = frx.responsibility_id
  AND LOWER (fr.responsibility_name) LIKE LOWER('XXTest Resp');
  --
   SELECT user_id INTO l_user_id FROM fnd_user WHERE user_name = 'SYSADMIN';
  --
  --To set environment context.
  --
  apps.fnd_global.apps_initialize (l_user_id,l_responsibility_id,l_application_id);
  --
  --Submitting Concurrent Request
  --
  l_request_id := fnd_request.submit_request ( 
                            application   => 'XXCUST', 
                            program       => 'XXCONCURRENT', 
                            description   => 'XXTest Conccurent Request', 
                            start_time    => sysdate, 
                            sub_request   => FALSE,
       argument1     => '12/31/2012 00:00:00'
  );
  --
  COMMIT;
  --
  IF l_request_id = 0
  THEN
     dbms_output.put_line ('Concurrent request failed to submit');
    --using fnd log if the pl/sql script is run within concurrent manager
    fnd_file.put_line (fnd_file.log, 'Concurrent request failed to submit');
  ELSE
     dbms_output.put_line('Successfully Submitted the Concurrent Request');
  END IF;
  --
EXCEPTION
WHEN OTHERS THEN
  dbms_output.put_line('Error While Submitting Concurrent Request '||TO_CHAR(SQLCODE)||'-'||sqlerrm);
END;
/

Sample scripts for FNDLOAD

FNDLOAD apps/pwd 0 Y mode configfile datafile entity [ param ...]
<apps/pwd>: The APPS schema and password in the form username/password[@connect_string]. If connect_string is omitted, it is taken in a platform-specific manner from the environment
using the name TWO_TASK.
< 0 Y >: Concurrent program flags.<mode>: UPLOAD or DOWNLOAD. UPLOAD causes the datafile to be uploaded to the database. DOWNLOAD causes the loader to fetch rows and write them to the datafile.<configfile>: The configuration file to use (usually with a suffix of .lct, but not enforced or supplied by the loader).<datafile>: The data file to write (usually with a suffix of .ldt, but not enforced or supplied by the loader). If the data file already exists, it will be overwritten.<entity>: The entity(ies) to upload or download. When uploading, always upload all entities, so specify a "-" to upload all entities.< [param] >: Zero or more additional parameters are used to provide bind values in the access SQL (both UPLOAD and DOWNLOAD). Each parameter is in the form NAME=VALUE. NAME should not conflict with an attribute name for the entities being loaded.

Note: Objects enclosed in [ ] are optional and may be used for more precise download or upload.

Some Sample Examples:  
FNDLOAD Concurrent Program
Download:
FNDLOAD apps/password O Y DOWNLOAD $FND_TOP/patch/115/import/afcpprog.lct your_output_dir/your_name.ldt PROGRAM [APPLICATION_SHORT_NAME=$app] CONCURRENT_PROGRAM_NAME="SHORT_PROGRAM_NAME"
Upload:
FNDLOAD apps/password O Y UPLOAD $FND_TOP/patch/115/import/afcpprog.lct
your_output_dir/your_name.ldt

FNDLOAD Profile Options
Download
FNDLOAD apps/password O Y DOWNLOAD $FND_TOP/patch/115/import/afscprof.lct your_output_dir/your_name.ldt PROFILE PROFILE_NAME="profile_option_short_name"[APPLICATION_SHORT_NAME=app]
Upload
FNDLOAD apps/password O Y UPLOAD $FND_TOP/patch/115/import/afscprof.lct your_output_dir/your_name.ldt

FNDLOAD Value Set
Download
FNDLOAD apps/password O Y DOWNLOAD $FND_TOP/patch/115/import/afffload.lct your_output_dir/your_name.ldt VALUE_SET FLEX_VALUE_SET_NAME="value_set_name"
Upload
FNDLOAD apps/password O Y UPLOAD $FND_TOP/patch/115/import/afffload.lct your_output_dir/your_name.ldt

FNDLOAD Request Group 
Download
FNDLOAD apps/password 0 Y DOWNLOAD $FND_TOP/patch/115/import/afcpreqg.lct your_output_dir/your_name.ldt REQUEST_GROUP REQUEST_GROUP_CODE="REQUEST_GROUP_CODE" 
Upload
FNDLOAD apps/password 0 Y UPLOAD $FND_TOP/patch/115/import/afcpreqg.lct your_output_dir/your_name.ldt

FNDLOAD Request Set
Download
FNDLOAD apps/password 0 Y DOWNLOAD $FND_TOP/patch/115/import/afcprset.lct your_output_dir/your_name.ldt REQ_SET REQUEST_SET_NAME="REQUEST_SET_NAME"
Upload
FNDLOAD apps/password 0 Y UPLOAD $FND_TOP/patch/115/import/afcprset.lct your_output_dir/your_name.ldt

FNDLOAD Responsibility 
Download

  

FNDLOAD apps/password 0 Y DOWNLOAD $FND_TOP/patch/115/import/afscursp.lct your_output_dir/your_name.ldt FND_RESPONSIBILITY RESP_KEY="RESPONSIBILITY_KEY_VALUE"
Upload
FNDLOAD apps/password 0 Y UPLOAD $FND_TOP/patch/115/import/afscursp.lct your_output_dir/your_name.ldt

FNDLOAD User Record
Download
FNDLOAD apps/password 0 Y DOWNLOAD $FND_TOP/patch/115/import/afscursp.lct your_output_dir/your_name.ldt FND_USER USER_NAME="USERNAME_TO_PROCESS"
Upload
FNDLOAD apps/password 0 Y UPLOAD $FND_TOP/patch/115/import/afscursp.lct your_output_dir/your_name.ldt 

FNDLOAD Message
Download
FNDLOAD apps/password 0 Y DOWNLOAD $FND_TOP/patch/115/import/afmdmsg.lct your_output_dir/your_name.ldt FND_NEW_MESSAGES APPLICATION_SHORT_NAME='app' [MESSAGE_NAME="MESSAGE_NAME"] 
Upload
FNDLOAD apps/password 0 Y DOWNLOAD $FND_TOP/patch/115/import/afmdmsg.lct your_output_dir/your_name.ldt
 
FNDLOAD Menu
Download  
FNDLOAD apps/appspwd  0 Y DOWNLOAD $FND_TOP/patch/115/import/afsload.lct file_name.ldt MENU MENU_NAME="MENU_NAME"
Upload
FNDLOAD apps/appspwd  0 Y DOWNLOAD $FND_TOP/patch/115/import/afsload.lct file_name.ldt

FNDLOAD Printer Style 
Download:
FNDLOAD apps/password O Y DOWNLOAD $FND_TOP/patch/115/import/afcppstl.lct your_output_dir/your_name.ldt STYLE PRINTER_STYLE_NAME="PRINTER_STYLE_NAME" 
Upload:
FNDLOAD apps/password O Y UPLOAD $FND_TOP/patch/115/import/afcppstl.lct

Thursday, March 12, 2015

Note for building OBIEE sample APP Virtual Machine

1. Following SampleAppQuickDeploymentGuide-309-R2.pdf to build the Virtual Box

2.1 For OBIEE Admin Client tool. Log into this machine's web page (port 9704/analytics). Download the tool from there. Doing this will make sure the client tool version is same as server version. 

2.2 Make sure the computer that Client tool installed, the computer should have host file include: 
    192.168.0.105(OBIEE server ip) obieesample.us.oracle.com

2.3 create tnsnames.ora and sqlnet.ora by copying those from OBIEE server's $ORACLE_HOME/network/admin to \oraclebi\orahome\network\admin, you will need to create this folder. Make sure tnsnames.ora host=obieesample.us.oracle.com, not ip address or others. 

2.4 copy the missing dll files to \oraclebi\orahome\bifoundation\server\bin from dll folder

3.  Study 
    start from here: http://www.oracle.com/technetwork/middleware/bi-enterprise-edition/tutorials/obiee11g-453435.html
    and pick this as the first tutorial:"Creating a Repository Using the Oracle BI 11g Administration Tool"


You can find SampleApp-QuickDeploymentGuide-309-R2.pdf 
and SampleAppv309-R2-UserGuide.pdf from Oracle web site

Connect Oracle using ODBC 32 bit in 64 bit Windows 7

For some reason I need to build an ODBC connection to Oracle database, the Oracle database version is 11.2.0.2. This turned out to be quite a big challenge. There are several issues during the installation, as usual, Oracle never make things easy. Anyway, here is how:

1. Download Instant Client basic 32 bit and ODBC 32 bit for 11.2.0.2 from here.
2. Extract both zip files you downloaded, put the files in instantclient_11_2 folder into C:\instantclient_11_2\
3. Add C:\instantclient_11_2 into Windows Path
4. Run C:\instantclient_11_2\odbc_install.exe
    You may see a warning from Program Compatibility Assistant says: This program might not be installed correctly. Just ignore it.
5. Goto ODBC 32bit console, tt is not easy to find Windows ODBC 32 bit console, the fastest way is to run C:\Windows\SysWOW64\odbcad32.exe from Start-&gt;search
6. If you have ODBC 32bit console open, create a new ODBC connection using Oracle in instantclient_11_2. You will fill the TNS Service Name like this: //host_ip_or_url:port/instance_name.
6. At this point you can test the new ODBC connection, but mostly you will see this error:
    ORA-12705: Cannot access NLS data files or invalid environment specified
The solution was to find the registry key named NLS_LANG under:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ORACLE
and rename it to anything else. I put an "x" at the end. This key is left over from a full install of Oracle. The instant client ODBC works properly now.

Friday, February 27, 2015

Oracle Workflow tables

WF_ACTIVITIES table stores the definition of an activity. Activities can
be processes, notifications, functions or folders. A process activity is a
modelled workflow process, which can be included as an activity in
other processes to represent a sub–process. A notification activity sends
a message to a performer. A functions activity performs an automated
function that is written as a PL/SQL stored procedure. A folder activity
is not part of a process, it provides a means of grouping activities.

WF_ITEMS is the runtime table for workflow processes. Each row
defines one work item within the system.

WF_ITEM_ATTRIBUTES table stores definitions of attributes
associated with a process. Each row includes the sequence in which the
attribute is used as well as the format of the attribute data.

WF_NOTIFICATIONS holds the runtime information about a specific
instance of a sent message. A new row is created in the table each time a
message is sent.