You are on page 1of 4

How does one eliminate duplicates rows from a table?

Choose one of the following queries to identify or remove duplicate rows from a table leaving only unique
records in the table:

Method 1:

Delete all rowids that is BIGGER than the SMALLEST rowid value (for a given key):

SQL> DELETE FROM table_name A


2 WHERE ROWID > ( SELECT min(rowid)
3 FROM table_name B
4 WHERE A.key_values = B.key_values );

Method 2:

This method is usually faster. However, remember to recreate all indexes, constraints, triggers, etc. on
the table when done.

SQL> create table table_name2 as select distinct * from table_name1;


SQL> drop table table_name1;
SQL> rename table_name2 to table_name1;

Method 3:

SQL> DELETE FROM my_table t1


2 WHERE EXISTS ( SELECT 'x' FROM my_table t2
3 WHERE t2.key_value1 = t1.key_value1
4 AND t2.key_value2 = t1.key_value2
4 AND t2.rowid > t1.rowid );

Note: One can eliminate N^2 unnecessary operations by creating an index on the joined fields in the inner
loop (no need to loop through the entire table on each pass by a record). This will speed-up the deletion
process.

Note 2: If you are comparing NULL columns, use the NVL function. Remember that NULL is not equal to
NULL. This should not be a problem as all key columns should be NOT NULL by definition.

Method 4:

This method collects the first row (order by rowid) for each key values and delete the rows that are not in
this set:
SQL> DELETE FROM my_table t1
1 WHERE rowid NOT IN ( SELECT min(rowid)
2 FROM my_table t2
3 GROUP BY key_value1, key_value2 );

Note: IF key_value1 is null or key_value2 is null, this still works correctly.

1)Dyanamically creating flat files in


Informatica
Asked by purushotham N | posted Jun 29 | Replies (10)
Hi I just have requirement where in, I need to generate the target files dyanamically with the department
names.

For example , If I have 3 departments with the names Comupers, Accounts and Finance, then We need
to generate the target files as Computers.txt, Accounts.txt and Finance.txt respecivey using Informatica
tool.

Can any please provide the solution for this.

ANSWER:

Source is FILE :---

empno deptno
100 10
100 20
100 30
200 10
200 20
200 20
200 10
300 10
300 10
300 10

step 1
drag and drop the columns form the source qualifier to sorter
set the sort key on DEPTNO (Ascending)

step 2

Drag and drop the ports to expression

create ports like

PORTNAME TYPE EXPRESSION


PREVDEPTNO V VAL
EMPNO I/O
DEPTNO I/O
VAL V DEPTNO
CHECK_FILE V decode(DEPTNO,PREVDEPTNO,1,0)
OUTPUT_FILE O/P CHECK_FILE

STEP3
DROP empno,DEPTNO, OUTPUT_FILE TO TRANSACTION CONTROL TRANSFORMER WRITE
DECODE (OUTPUT_FILE,1,TC_CONTINUE_TRANSACTION,0,TC_COMMIT_ Before).

step 4
connect to file target with the file name as deptno in target filename port.

2)Ex.
1st file
AAAAAAAAAAAAAAAAAAAAAAAAAA
2nd file
BBBBBBBBBBBBBBBBBBBBBBBBBB
Out put is third file
AAAAAAAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBB BBBBBBBBBBB
Now for achieving this i am using session properties with file sequential merge but i am not getting it in
the third file. Even my third file is not created also after the successful Run of session. Please help me in
this and pls mention the procedure that in which file i have to give merge. and do i use command in
informatica session level properties.
I would like to tell all of you i can not Shell Script or even any command task. as the client does't want to
be done in unix.

ANSWER:

Why don,t you take both the files as source and merge them using union trans,and then load it to another
flat file(Third file).just create another pipeline in same mapping to do that.

join of two Flat files through Informatica


Asked by bhabesh palhar | posted Dec 7, 2009 | Replies (5)
Dear All,
Please suggest how to join 2 flat Files through Informatica if both have no common columns.
Flat file 1- The 2 columns are Employee name & Employee Number
Flt File2-The 2 columns are Department name & Department Number
Regards,
Bhabesh
You can also join the flat files by using a generic join condition 1=1.
i.e., After the Flatfile1 source Qualifier, create an expression
transformation, create an output port , JOIN_CONDITION1 with value as 1
(numeric)
Do the same(JOIN_CONDITION2 ) in another expression transformation
after the FlatFile2 source Qualifier.
Now in the Joiner, the two pipelines can be joined on this condition using
the JOIN_CONDITION1 and 2 ports.
Regards,
Vamsi