Tuesday, May 5, 2009

Pivot query in oracle

Scenario 1:
CREATE TABLE t1 (
id NUMBER PRIMARY KEY,
sum1 NUMBER,
sum2 NUMBER,
sum3 NUMBER
);
INSERT INTO t1 VALUES (1,20,40,50);
INSERT INTO t1 VALUES (2,30,20,25);
INSERT INTO t1 VALUES (3,15,60,55);
COMMIT;
ID SUM1 SUM2 SUM3
---------- ---------- ---------- ----------
1 20 40 50
2 30 20 25
3 15 60 55
SELECT id, num, DECODE(num,'1',sum1,'2',sum2,'3',sum3) data
from t1,
(SELECT '1' num FROM dual UNION ALL
SELECT '2' num FROM dual UNION ALL
SELECT '3' num FROM dual )

ID NUM data
1 1
1 2
1 3
2 1
2 2
2 3



Scenario 2:
scott@DEV816> select job, deptno, count(*) 2 from emp 3 group by job, deptno 4 /JOB DEPTNO COUNT(*)--------- ---------- ----------ANALYST 20 2CLERK 10 1CLERK 20 2CLERK 30 1MANAGER 10 1MANAGER 20 1MANAGER 30 1PRESIDENT 10 1SALESMAN 30 49 rows selected.And you would like to make DEPTNO be a column. We have 4 deptno's in EMP, 10,20,30,40. We can make columns dept_10, dept_20, dept_30, dept_40 that have the values that are currently in the count column. It would look like this:scott@DEV816> scott@DEV816> select job, 2 max( decode( deptno, 10, cnt, null ) ) dept_10, 3 max( decode( deptno, 20, cnt, null ) ) dept_20, 4 max( decode( deptno, 30, cnt, null ) ) dept_30, 5 max( decode( deptno, 40, cnt, null ) ) dept_40 6 from ( select job, deptno, count(*) cnt 7 from emp 8 group by job, deptno ) 9 group by job 10 /JOB DEPT_10 DEPT_20 DEPT_30 DEPT_40--------- ---------- ---------- ---------- ----------ANALYST 2CLERK 1 2 1MANAGER 1 1 1PRESIDENT 1SALESMAN 4

Monday, May 4, 2009

Informatica Architecture --Integration Service vs Power center Server

The differences between 7.x and 8.x is on architecture as well as The architecture of PowerCenter 8.x primarily differs from that of PowerCenter 7.x in the administration of the product. PowerCenter has now adopted a Service Oriented Architecture (SOA).The SOA architecture has replaced several servers that were used within the PowerCenter 7.x installer. A Tomcat web server is used to run an Informatica 'domain' comprising of several repositories or integration 'services'. An integration service is responsible for data movement.
SOA allows a single console tool to be used to administer the PowerCenter installer. This tool is web based and can be accessed from anywhere in your network. SOA supports several integration or repository services to run concurrently. This allows high availability to be implemented (if a server hosting an integration service fails these tasks can be 'failed over' onto another node in the domain).
Additionally PowerCenter 8.x supports the use of Java in mappings, the ability to 'push down' processing into the database and other similar improvements. There is nosignificant change in the client interface.
Additional Information: Several terms have acquired a new meaning with the change in product architecture.
PowerCenter 7.x PowerCenter 8.x R epository server and repository R epository service PowerCenter Server I ntegration service Some other enchancements like push down processing, more flexible java transformations, SQL transformations, string parsing functions are newly added to 8.x. Only change we can see in it is a single place where we do all administration stuff. Repository server is renamed as repository service and informatica pc server renamed as integration service. Not much change in client interface as we still have Repository Manager,Designer,Workflow Manager and Workflow Monitor.
Also on 8.5 and 8.6, security, user and group administration has been moved to the administration console.
When comparing to the architecture 7.1 n 8.1,DOMAIN,NODE,INTEGRATION SERVICES added to the 8.1 architectutre.DOMAIN is a web based admin console.NODE is like INF server or power centre server.INTEGRATION SERVICES is like repository server.DOMAIN,NODE,INTEGRATION SERVICES are at one place that is DOMAIN DATABASE.In 8.1 we don't have admin console n repository agent.and also you can install multiple NODES in a single machine.and you can intiate multiple processes simultaneously.In INF 8.1 has more security you can not create repository with out previliges.you no need to start the services in control panel every time.and also some of the transformations added in 8.1.They are SQL,JAVA transformations.It supports unstructured data like emails,word,pdfs.concept of flatfile updation is introduced.



Effective in PowerCenter 8.0, you might notice an increase in memory and CPU resource usage on machines running PowerCenter Services. The following factors can increase memory and CPU resource usage:
Updates to Integration Service and Repository Service processes. The pmserver and pmdtm process for the Integration Service and the pmrepagent process for the Repository Service include updated functionality that requires more memory and CPU resource usage.
High availability. You configure a domain for high availability, service restart, failover, and recovery operations.
Java Runtime Environment (JRE). The PowerCenter service-oriented architecture uses JRE to run the PowerCenter domains and nodes. Domains and nodes require more memory and CPU resources than when you run a PowerCenter Server or Repository Server in PowerCenter 7.x.
Log Manager. The Log Manager requires additional memory and CPU resources when it collects and processes a large number of log events.

Oracle 10g warehouse features

The list includes these Oracle 10g warehouse features:
Materialized Views — The Oracles materialized views (MV) feature uses Oracle replication to allow you to pre-summarize and pre-join tables.
Automated Workload Repository — The AWR is a critical component for data warehouse predictive tools such as the dbms_advisor package.
Multiple Blocksizes — All data warehouse indexes that are accessed via range scans and Oracle objects that must be accessed via full-table, or full-index, scans should be in a 32k blocksize.
STAR query optimization — The Oracle 10g STAR query features make it easy to make complex DSS queries run at super-fast speeds.
Multi-level partitioning of tables and indexes — Oracle now has multi-level intelligent partitioning methods that allow Oracle to store data in a precise scheme.
Asynchronous Change Data Capture — Change data capture allows incremental extraction, so only changed data to be extracted easily.
Oracle Streams — Streams-based feed mechanisms can capture the necessary data changes from the operational database and send it to the destination data warehouse.
Read-only Tablespaces — If you have a time-series warehouse in which information eventually becomes static, using tablespace partitions and marking the older tablespaces as read-only can greatly improve performance.
Automatic Storage Management (ASM) — The revolutionary new method for managing the disk I/O subsystem removes the tedious and time-consuming chore of I/O load balancing and disk management.
Advanced Data Buffer Management — Using Oracle 10g’s multiple block sizes and KEEP pool, you can preassign warehouse objects to separate data buffers and ensure that your working set of frequently-referenced data is always cached.

Wednesday, March 25, 2009

CDC QUERY IN ORACLE

desc table



update test_update u
set (u.changec) =
(
with t as
(select change,x.c1 as c1,x.c2 as c2,x.c3 as c3,x.c4 as c4,x.c5 as c5,x.c6 as c6 from test_update x,
(
(select
'c4 change' as change ,a.c1,a.c2,a.c3,a.c4,a.c5,a.c6
from test_update a,test_update b
where
a.c1=b.c1 and
a.c2=b.c2 and
a.c3=b.c3 and
( a.c4 != b.c4 )
and a.sourceI='I')
union
(select
'c5 change' as change,a.c1,a.c2,a.c3,a.c4,a.c5,a.c6
from test_update a,test_update b
where
a.c1=b.c1 and
a.c2=b.c2 and
a.c3=b.c3 and
(a.c5 != b.c5 )
and a.sourceI='I'))y
where
X.C1=y.c1 and
x.c2=y.c2 and
x.c3=y.c3
and x.sourceI='I')
select change from t
where t.c1=u.c1 and
t.c2=u.c2 and
t.c3=u.c3 and
t.c4=u.c4 and
t.c5=u.c5 and
t.c6=u.c6
-- t.sourceI='I'
)

Wednesday, February 25, 2009

String Aggregation in oracle

----------------------------------------------------------------
http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
---------------------------------------------------------------------
Home Articles Scripts Forums Blog Certification Misc About Printer Friendly Oracle 8i Oracle 9i Oracle 10g Oracle 11g Miscellaneous Oracle RAC Oracle Apps Linux
Home » Articles » 10g » Here
String Aggregation TechniquesOn occasion it is necessary to aggregate data from a number of rows into a single row, giving a list of data associated with a specific value. Using the SCOTT.EMP table as an example, we might want to retrieve a list of employees for each department. Below is a list of the base data and the type of output we would like to return from an aggregate query.
Base Data:
DEPTNO ENAME---------- ---------- 20 SMITH 30 ALLEN 30 WARD 20 JONES 30 MARTIN 30 BLAKE 10 CLARK 20 SCOTT 10 KING 30 TURNER 20 ADAMS 30 JAMES 20 FORD 10 MILLER
Desired Output:
DEPTNO EMPLOYEES---------- -------------------------------------------------- 10 CLARK,KING,MILLER 20 SMITH,FORD,ADAMS,SCOTT,JONES 30 ALLEN,BLAKE,MARTIN,TURNER,JAMES,WARDThis article is based on a thread from asktom.oracle.com and contains several methods to achieve the desired results.
Specific Function Generic Function using Ref Cursor User-Defined Aggregate Function ROW_NUMBER() and SYS_CONNECT_BY_PATH functions in Oracle 9i COLLECT function in Oracle 10g Specific FunctionOne approach is to write a specific function to solve the problems. The get_employees function listed below returns a list of employees for the specified department.
CREATE OR REPLACE FUNCTION get_employees (p_deptno in emp.deptno%TYPE) RETURN VARCHAR2IS l_text VARCHAR2(32767) := NULL;BEGIN FOR cur_rec IN (SELECT ename FROM emp WHERE deptno = p_deptno) LOOP l_text := l_text ',' cur_rec.ename; END LOOP; RETURN LTRIM(l_text, ',');END;/SHOW ERRORSThe function can then be incorporated into a query as follows.
COLUMN employees FORMAT A50
SELECT deptno, get_employees(deptno) AS employeesFROM empGROUP by deptno;
DEPTNO EMPLOYEES---------- -------------------------------------------------- 10 CLARK,KING,MILLER 20 SMITH,JONES,SCOTT,ADAMS,FORD 30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES
3 rows selected.To reduce the number of calls to the function, and thereby improve performance, we might want to filter the rows in advance.
COLUMN employees FORMAT A50
SELECT e.deptno, get_employees(e.deptno) AS employeesFROM (SELECT DISTINCT deptno FROM emp) e;
DEPTNO EMPLOYEES---------- -------------------------------------------------- 10 CLARK,KING,MILLER 20 SMITH,JONES,SCOTT,ADAMS,FORD 30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES 3 rows selected.Generic Function using Ref CursorAn alternative approach is to write a function to concatenate values passed using a ref cursor. This is essentially the same as the previous example, except that the cursor is passed in making it generic, as shown below.
CREATE OR REPLACE FUNCTION concatenate_list (p_cursor IN SYS_REFCURSOR) RETURN VARCHAR2IS l_return VARCHAR2(32767); l_temp VARCHAR2(32767);BEGIN LOOP FETCH p_cursor INTO l_temp; EXIT WHEN p_cursor%NOTFOUND; l_return := l_return ',' l_temp; END LOOP; RETURN LTRIM(l_return, ',');END;/SHOW ERRORSThe CURSOR function is used to allow a query to be passed to the function as a ref cursor, as shown below.
COLUMN employees FORMAT A50
SELECT e1.deptno, concatenate_list(CURSOR(SELECT e2.ename FROM emp e2 WHERE e2.deptno = e1.deptno)) employeesFROM emp e1GROUP BY e1.deptno;
DEPTNO EMPLOYEES---------- -------------------------------------------------- 10 CLARK,KING,MILLER 20 SMITH,JONES,SCOTT,ADAMS,FORD 30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES
3 rows selected.Once again, the total number of function calls can be reduced by filtering the distinct values, rather than calling the function for each row.
COLUMN employees FORMAT A50
SELECT deptno, concatenate_list(CURSOR(SELECT e2.ename FROM emp e2 WHERE e2.deptno = e1.deptno)) employeesFROM (SELECT DISTINCT deptno FROM emp) e1;
DEPTNO EMPLOYEES---------- -------------------------------------------------- 10 CLARK,KING,MILLER 20 SMITH,JONES,SCOTT,ADAMS,FORD 30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES
3 rows selected.User-Defined Aggregate FunctionPossibly the best generic solution is to create a user-defined aggregate function, using the ODCIAggregate interface, to solve the problem, as shown below.
CREATE OR REPLACE TYPE t_string_agg AS OBJECT( g_string VARCHAR2(32767),
STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg) RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg, value IN VARCHAR2 ) RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg, returnValue OUT VARCHAR2, flags IN NUMBER) RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg, ctx2 IN t_string_agg) RETURN NUMBER);/SHOW ERRORS
CREATE OR REPLACE TYPE BODY t_string_agg IS STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg) RETURN NUMBER IS BEGIN sctx := t_string_agg(NULL); RETURN ODCIConst.Success; END;
MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg, value IN VARCHAR2 ) RETURN NUMBER IS BEGIN SELF.g_string := self.g_string ',' value; RETURN ODCIConst.Success; END;
MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg, returnValue OUT VARCHAR2, flags IN NUMBER) RETURN NUMBER IS BEGIN returnValue := RTRIM(LTRIM(SELF.g_string, ','), ','); RETURN ODCIConst.Success; END;
MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg, ctx2 IN t_string_agg) RETURN NUMBER IS BEGIN SELF.g_string := SELF.g_string ',' ctx2.g_string; RETURN ODCIConst.Success; END;END;/SHOW ERRORS
CREATE OR REPLACE FUNCTION string_agg (p_input VARCHAR2)RETURN VARCHAR2PARALLEL_ENABLE AGGREGATE USING t_string_agg;/SHOW ERRORSThe aggregate function is implemented using a type and type body, and is used within a query.
COLUMN employees FORMAT A50
SELECT deptno, string_agg(ename) AS employeesFROM empGROUP BY deptno;
DEPTNO EMPLOYEES---------- -------------------------------------------------- 10 CLARK,KING,MILLER 20 SMITH,FORD,ADAMS,SCOTT,JONES 30 ALLEN,BLAKE,MARTIN,TURNER,JAMES,WARD
3 rows selected.ROW_NUMBER() and SYS_CONNECT_BY_PATH functions in Oracle 9iAn example on williamrobertson.net uses the ROW_NUMBER() and SYS_CONNECT_BY_PATH functions to achieve the same result without the use of PL/SQL or additional type definitions. SELECT deptno, LTRIM(MAX(SYS_CONNECT_BY_PATH(ename,',')) KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employeesFROM (SELECT deptno, ename, ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) AS curr, ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) -1 AS prev FROM emp)GROUP BY deptnoCONNECT BY prev = PRIOR curr AND deptno = PRIOR deptnoSTART WITH curr = 1;
DEPTNO EMPLOYEES---------- -------------------------------------------------- 10 CLARK,KING,MILLER 20 ADAMS,FORD,JONES,SCOTT,SMITH 30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
3 rows selected.COLLECT function in Oracle 10gAn example on oracle-developer.net uses the COLLECT function in Oracle 10g to get the same result. This method requires a table type and a function to convert the contents of the table type to a string. I've altered his method slightly to bring it in line with this article.
CREATE OR REPLACE TYPE t_varchar2_tab AS TABLE OF VARCHAR2(4000);/
CREATE OR REPLACE FUNCTION tab_to_string (p_varchar2_tab IN t_varchar2_tab, p_delimiter IN VARCHAR2 DEFAULT ',') RETURN VARCHAR2 IS l_string VARCHAR2(32767);BEGIN FOR i IN p_varchar2_tab.FIRST .. p_varchar2_tab.LAST LOOP IF i != p_varchar2_tab.FIRST THEN l_string := l_string p_delimiter; END IF; l_string := l_string p_varchar2_tab(i); END LOOP; RETURN l_string;END tab_to_string;/The query below shows the COLLECT function in action. COLUMN employees FORMAT A50
SELECT deptno, tab_to_string(CAST(COLLECT(ename) AS t_varchar2_tab)) AS employeesFROM empGROUP BY deptno; DEPTNO EMPLOYEES---------- -------------------------------------------------- 10 CLARK,KING,MILLER 20 SMITH,JONES,SCOTT,ADAMS,FORD 30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES 3 rows selected.For more information see:
User-Defined Aggregate Functions asktom.oracle.com williamrobertson.net oracle-developer.net - the collect function in 10g Hope this helps. Regards Tim...
Back to the Top.
20 comments, read/add them...

Home Articles Scripts Forums Blog Certification Misc About
Copyright & Disclaimer

Saturday, February 7, 2009

Handling xml sources in informatica

Hi,


To handle the xml source with different segements and to get the columns for one parent segment to child segment ,then we have to use a joiner,but remember do not use a seperate source qualifer .It will generate a sepearte primary key ,so you will not able to join the two segments.

Clob datatype in informatica

Hi,

To handle the clob data in oracle 10g the source qualifer should be also clob datatype for the particular column ,where for 11g version of oracle the datatype in the source qualifier to be change into nclob.

Wednesday, January 7, 2009

Email task and its parameters declarations ??

Email task and its parameters declarations ??

If you want to make it reusable then you have to create a email task else you can directly call from the post session commands.

Email User Name--$PMFailureEmailUser
Email Subject --FAILURE: ''Foldername'' - Session Name: %S failed
Email Text---
Folder Name: %N
Integration Service Name: %v \nWorkflow Name: %W \nSession Name: %S \n %b %i %c \nMapping Name: %M
%l
%r
Target Table Details:%T
Log file: %g

Tuesday, January 6, 2009

What is the difference between XSd and DTD and Validating a XML against XSD

What is the difference between XSd and DTD ?

Both of them achieve similar goals to define the structure of xml documents.XSd does in the language of xml itself,DTD uses its own language.Xsd is more expressive and dtd is less expressive.XSD allows for extensible schmeas,has namespace support, has content directives,offers tighter integration with the testing tools etc.DTD has none of these features.XSD is newer and DTD is older.DTD is also used to define other types of documents(types other than XML).


Validating a XML against XSD ?

To check the validity of xml,it has to first be well formed.The XML specification has some rules on well-formedness of xml.Once a documents is found to be well formed ,it can be validated against a schema that defined it,the schema can be defined using many schema definitions.The most popular ones are XSD,DTD and RELAX-NG.To validate a program is used.Some IDEs,MS VisualStudio.YOu can also find programs on the net that perform validation of xml files.

Monday, January 5, 2009

Creating a database link (DB link )

Syntax:
Creating a database link

create database link DB_Link connect to "Username" identified by "Password"using '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=HOsT string)(Port =
Port number))(CONNECT_DATA=(SID = service ID)))';

creating a synonym :
create or replace synonym synonym1for schmea. synonym1 @DB_Link;

Creating a table:
create table table1 as (select * from table1@db_link)

Sunday, January 4, 2009

Oracle Application Express (Apex)

Oracle Application Express (Apex)

It is a HTML Database where the database can be accessed anywhere following the url and credetials apart from this ,the basic repoting and query handling can also be done in apex .
The main basic three components present in apex are
1)Application Builder
1.1)Create Application
1.2)View Application
1.3)Demonstration
1.4)Application Adminstration
1.4.1)In This we can Manage services Activities and apex users as well.
1.5)Import
2)Sql Workshop
2.1)Object Browser
2.1.1)Create objects
2.1.2)Browse objects
2.2 )Sql Commands
2.2.1)Enter Commands
2.3)Sql Scripts
2.3.1)Create
2.3.2)Upload
2.3.3)View
2.3.4)Export
2.3.5)Import
2.4)Query Builder
2.4.1)Create
2.4.2) view
3)Utilities
3.1)DataLoad/Unload
3.1.1)Load
3.1.2)Unload
3.1.3)Repository
3.2)Generate DDL
3.3)Object Reports
3.3.1)Table Reports
3.3.2)Expection Reports
3.3.3)Security Reports
3.3.4)All objects Reports
3.3.5) PL/SQl Reports
3.4)Recycle Bin
3.5)Database Monitor
3.5.1)Sessions
3.5.2)System Statistics
3.5.3)Top SQL
3.5.4)Long Operations
3.6)Apex Views
3.7)Schema Comparisons
3.8)About Database

Friday, January 2, 2009

Steps to start a pmcmd command to run a workflow from informatica server

Steps to start a pmcmd command to run a workflow from informatica server
1. At the command prompt, switch to the directory where the pmcmd executable is located.
By default, the PowerCenter installer installs pmcmd in the \server\bin directory.2. Enter pmcmd followed by the command name and its required options and arguments:
pmcmd command_name [-option1] argument_1 [-option2] argument_2...
if your not pretty sure where the excutable is present or not just type and pmcmd command in your server and check for the message if throws an "command not found"
then check for this file in your home directory(.cshrc_infa) file this file contains
#ident "@(#)local.cshrc 1.2 00/05/01 SMI"umask 022set path=(/bin /usr/bin /usr/ucb /etc .)if ( $?prompt ) then set history=32endif
setenv ODBCHOME /(server name)/app/informatica/pc_server/ODBC5.2setenv ODBCINI $ODBCHOME/odbc.inisetenv INFA_HOME /mounts/infdev/app/informatica/pc_serversetenv DOMAINS_INFA /(servername)/app/informatica/pc_serversetenv ORACLE_HOME /mounts/ora_home/app/oracle/product/10.2.0.3setenv ORACLE_SID infdev
setenv TNS_ADMIN /(mainserver name)/app/oracle/network
setenv PATH ${PATH}:/Mounts/ora_home/app/oracle/product/10.2.0.3/bin:$ODBCHOME/bin:$INFA_HOME/server/binsetenv LD_LIBRARY_PATH $ORACLE_HOME/lib:$ODBCHOME/lib:$INFA_HOME/server/bin

then type csh command and then source your file .csh source .cshrc_infa
and then run pmcmd command
synatx is as follows
pmcmd scheduleworkflow <-serveraddr-s> [host:]portno <<-user-u> username<-uservar-uv> user_env_var> <<-password-p> password<-passwordvar-pv> password_env_var> [<-folder-f> folder] workflow
--------------------------------- pmcmd startworkflow -sv Integartion service name -d domain -u username -p password -f 'folder' workflow name


If you are alreadyin pmcmd prompt then follow the below mentioned steps

The following commands were helpful for pmcmd:
pmcmd>connect -sv Service -d domain -u username -p password
pmcmd>startworkflow -f 'folder' workflow
pmcmd>getworkflowdetails -f 'folder' -rin workflow
pmcmd>gettaskdetails -f 'folder' workflow
pmcmd>stoptask -f 'folder' workflow
pmcmd>getsessionstatistics -f 'folder' workflow
pmcmd>scheduleworkflow -f 'folder' workflow
pmcmd>unscheduleworkflow -f 'folder' workflow
pmcmd>disconnect -sv Service -d domain -u username -p password