Load distinct rows with sequence
Hi All
I have requirement at my client where we need to load distinct rows from the source TABLEA into TABLEB and add sequence in target TABLEB.
As we know in Oracle we cant use sequence with distinct keyword, one of the solution is to use the sequence in target so ODI will capture
distinct rows from source and use the sequence only in target table but if the source and target are on same schema then ODI doesn't create
C$ table but it load data directly into target table and we get the error of invalid use of sequence.It wors fine if source and target table on different
schema. I like to know if there is any way force ODI to create C$ table with distinct rows and load the sequence in target table only even source and
target are on same schema. Otherwise I have create two interface to capture the distinct rows firct and then update the same table with sequence
in second step. I really wanna avoid creating 2 interface for this simple job.Let me know if you have better solution.
Thanks
Kashif
user634784 wrote:
But is there any way to get the same outcome without using the subquery.In reality... No.
You can hide the fact that you have to generate a row_number for the records by using a view... ;)
SQL> ed
Wrote file afiedt.buf
1 create table t as select 1 as Empid, to_date('01-jan-2008','DD-MON-YYYY') as startdate, null as enddate, 'O1' as organisation from dual union all
2 select 2, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O1' from dual union all
3 select 3, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O1' from dual union all
4 select 4, to_date('5-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O2' from dual union all
5 select 5, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O2' from dual union all
6 select 6, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O2' from dual union all
7 select 7, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O3' from dual union all
8* select 8, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O3' from dual
9 /
Table created.
SQL> ed
Wrote file afiedt.buf
1 create view vw_x as
2* select empid, startdate, enddate, organisation, row_number() over (partition by organisation order by empid) rn from t
SQL> /
View created.
SQL> select * from vw_x where rn = 1;
EMPID STARTDATE ENDDATE OR RN
1 01-JAN-08 O1 1
4 05-JAN-08 31-JUL-08 O2 1
7 02-JAN-08 31-JUL-08 O3 1
SQL>
Similar Messages
-
Update group of rows with sequence
Hi guys,
I have no idea how to do an update of a table with a sequence value... but i don't want to increment the sequence for each row.
create sequence seq_num;
create table upd_group(
id number,
group_code varchar2(5),
seq_num number
insert into upd_group values(1,'a',null);
insert into upd_group values(2,'c',null);
insert into upd_group values(3,'a',null);
insert into upd_group values(4,'b',null);
insert into upd_group values(5,'a',null);
insert into upd_group values(6,'b',null);
commit;
select * from upd_group;
--doesn't work
update upd_group set seq_num = seq_num.nextval
where group_code in (select distinct group_code from upd_group)the expected result would be
all rows with group_code = 'a' would have N
all rows with group_code = 'b' would have N+1
all rows with group_code = 'c' would have N+2
and so on....
any idea how to do this?Thanks for posting sample data!
If this is a one time shot, then analytics and MERGE might come to the rescue:
SQL> select * from upd_group order by group_code;
ID GROUP SEQ_NUM
1 a
3 a
5 a
4 b
6 b
2 c
6 rows selected.
SQL> --
SQL> --doesn't work
SQL> --update upd_group set seq_num = seq_num.nextval
SQL> --where group_code in (select distinct group_code from upd_group);
SQL> --
SQL> merge into upd_group a
2 using ( select id
3 , dense_rank() over (order by group_code) new_seq_num
4 from upd_group
5 ) b
6 on (a.id = b.id)
7 when matched then update set a.seq_num = b.new_seq_num;
6 rows merged.
SQL> --
SQL> select * from upd_group order by group_code;
ID GROUP SEQ_NUM
1 a 1
3 a 1
5 a 1
4 b 2
6 b 2
2 c 3
6 rows selected.How a sequence could be able to take care of this in a query....that's interesting.
Depending on your database version you might opt for a virtual column....(11g stuff) -
Did bc4j create row with sequence change from integer to long
When creating a new row through bc4j with database sequence for primary key, I followed the online examples and even checked the samples distributed with jdev production 9.0.2. They all show that the sequence is returned as Integer. I finally changed it to Long and got it to work. Has there been a change, or have I got something else fouled up?
This is the code that worked...
protected void create(AttributeList attributeList)
super.create(attributeList);
// get the next template ID from database sequence
SequenceImpl s = new SequenceImpl("XXPRC_TEMPLATE_ID_S", getDBTransaction() );
java.lang.Long next = (java.lang.Long) s.getData();
setTemplateId( new Number(next) );
}When creating a new row through bc4j with database sequence for primary key, I followed the online examples and even checked the samples distributed with jdev production 9.0.2. They all show that the sequence is returned as Integer. I finally changed it to Long and got it to work. Has there been a change, or have I got something else fouled up?
This is the code that worked...
protected void create(AttributeList attributeList)
super.create(attributeList);
// get the next template ID from database sequence
SequenceImpl s = new SequenceImpl("XXPRC_TEMPLATE_ID_S", getDBTransaction() );
java.lang.Long next = (java.lang.Long) s.getData();
setTemplateId( new Number(next) );
} Yes some javadoc was corrected to reflect this change in 9.0.2. Could you post the "context" for the javadoc where you're seeing this example so we can verify if that's corrected too.
To get the correct Sequence value, you need to call getSequenceNumber() method and not getData which should have been (and is in 902) marked internal. -
Problem loading multiple rows with ADI
Hello guys. I setup a custom integrator to use with WebADI. Even after unprotecting the sheet, only the rows that are within the border (only 10 records) are uploaded. I have updated the profile option "BNE Upload Batch Size". Before doing this it would give an error saying "Server could not complete the upload". Now it doesn't give an error but it doesn't load the other values in the sheet. Is there a way of increasing the black border where the data fits so it can load more data? Many thanks
Hi,
there are two options:
1/ When you specify and define your layout you can also define how many rows you like to get in your excel sheet.
2/ If you unprotect your sheet, you can always add rows in between the existing row area. I put always new rows between the existing row 9 and 10. This always works.
Hope this helps
br, Volker -
Need distinct rows with using distinct clause
I have following requirement
Empid startdate end organisation
1 1-jan-2008 O1
2 2-jan-2008 31-jul-08 O1
3 2-jan-2008 31-jul-08 O1
4 2-jan-2008 31-jul-08 O2
5 2-jan-2008 31-jul-08 O2
6 2-jan-2008 31-jul-08 O2
7 2-jan-2008 31-jul-08 O3
8 2-jan-2008 31-jul-08 O3
My requirement is to get a sql query that report me something like this
Empid startdate end organisation
1 1-jan-2008 O1
4 2-jan-2008 31-jul-08 O2
7 2-jan-2008 31-jul-08 O3
That is any empid, startdate, end for a given organization (ie organization should be distinct)
regards
vikas
Edited by: user634784 on Jan 19, 2009 4:05 AMuser634784 wrote:
But is there any way to get the same outcome without using the subquery.In reality... No.
You can hide the fact that you have to generate a row_number for the records by using a view... ;)
SQL> ed
Wrote file afiedt.buf
1 create table t as select 1 as Empid, to_date('01-jan-2008','DD-MON-YYYY') as startdate, null as enddate, 'O1' as organisation from dual union all
2 select 2, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O1' from dual union all
3 select 3, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O1' from dual union all
4 select 4, to_date('5-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O2' from dual union all
5 select 5, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O2' from dual union all
6 select 6, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O2' from dual union all
7 select 7, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O3' from dual union all
8* select 8, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O3' from dual
9 /
Table created.
SQL> ed
Wrote file afiedt.buf
1 create view vw_x as
2* select empid, startdate, enddate, organisation, row_number() over (partition by organisation order by empid) rn from t
SQL> /
View created.
SQL> select * from vw_x where rn = 1;
EMPID STARTDATE ENDDATE OR RN
1 01-JAN-08 O1 1
4 05-JAN-08 31-JUL-08 O2 1
7 02-JAN-08 31-JUL-08 O3 1
SQL> -
Update rows with a sequence which fall under same group.
Hi Friends,
I have sample table with following data :
ID DIV NEW_ID
1 A
2 A
3 B
4 B I want to update the column NEW_ID with a sequence value for the rows with same DIV value.
My result should look like below :
ID DIV NEW_ID
1 A 1001
2 A 1001
3 B 1002
4 B 1002How can I accomplish with a single update ?
Thanks
Raj.This isn't pretty, but it should work ....
ME_XE?create table table1 (col1 number, col2 varchar2(1), col3 number);
Table created.
Elapsed: 00:00:00.04
ME_XE?insert into table1 values (1, 'A', NULL);
1 row created.
Elapsed: 00:00:00.06
ME_XE?insert into table1 values (2, 'A', NULL);
1 row created.
Elapsed: 00:00:00.01
ME_XE?insert into table1 values (3, 'B', NULL);
1 row created.
Elapsed: 00:00:00.00
ME_XE?insert into table1 values (4, 'B', NULL);
1 row created.
Elapsed: 00:00:00.00
ME_XE?
ME_XE?
ME_XE?create sequence s start with 1001 increment by 1;
Sequence created.
Elapsed: 00:00:00.00
ME_XE?create or replace function get_s_nextval
2 return number
3 as
4 o_val number;
5 begin
6 select s.nextval into o_val from dual;
7 return o_val;
8 end;
9 /
Function created.
Elapsed: 00:00:00.54
ME_XE?
ME_XE?
ME_XE?merge into table1 t using
2 (
3 with data
4 as
5 (
6 select --+ MATERIALIZE
7 col2, get_s_nextval as next_value
8 from
9 (
10 select distinct col2
11 from table1
12 where col3 is null
13 )
14 )
15 select * from data
16 ) s
17 on (s.col2 = t.col2)
18 when matched then update set t.col3 = s.next_value;
4 rows merged.
Elapsed: 00:00:00.20
ME_XE?
ME_XE?
ME_XE?select * from table1;
COL1 COL COL3
1 A 1001
2 A 1001
3 B 1002
4 B 1002
4 rows selected.
Elapsed: 00:00:00.03
ME_XE? -
Getting Chained Rows with SQL-Loader
Hi, I'm getting chained rows when loading data into an empty table. I always thought this could only happen when updating rows in a table. I'm loading into a datawarehouse, so I set the pctfree and pctused to use as much of the data blocks as possible. Here's the specs:
pctfree 5, pctused 90 (blocksize 8k).
The average rowsize is 1481 bytes.
There will never be updates or deletes on this table. The table is always created new or truncated. How come does Oracle chain about 30 percent of the rows with the above values? I had to go down to pctfree 50 in order to get chained rows = 0.
tia,
Danny Smith- check if your table has check constraints (like column not null)
if you trust the data in the file you have to load you can disable this constrainst and after the loader enable this constrainst.
- Check if you can modify the table and place it in nologging mode (generate less redo but ONLY is SOME Conditions)
Hope it helps
Rui Madaleno -
Query to get row with max values for distinct
I have a table test with ID, ADID, MTMST columns.
ID ----ADID---- MTMST
1 ----100---- 24-MAR-12 08.17.09.000000 PM
1 ----101---- 24-MAR-12 08.18.15.000000 PM
1 ----102---- 24-MAR-12 08.18.56.000000 PM
2 ----103---- 24-MAR-12 08.19.21.000000 PM
2 ----104---- 24-MAR-12 08.19.36.000000 PM
2 ----105---- 24-MAR-12 08.19.46.000000 PM
3 ----99---- 22-MAR-12 09.48.22.000000 PM
I need the rows with max ADID for each ID.
I used the following query but it provided max ADID of the table but not the distinct ID
select * from test where ADID in (select max(ADID) from test where id in (select distinct(id) from test where mtmst > sysdate -1))
Result:*
ID ----ADID---- MTMST
2 ----105---- 24-MAR-12 08.19.46.000000 PM
Expected result:*
ID ----ADID---- MTMST
1 ----102---- 24-MAR-12 08.18.56.000000 PM
2 ----105---- 24-MAR-12 08.19.46.000000 PM
Thanks,
Dheepan
Edited by: Dheepan on Mar 24, 2012 9:53 AMselect id, adid, mtmst from test where (id, adid) in (select id, max(adid) from test group by id) and MTMST>sysdate-1
is the answer. -
I have a Power Query that i have used for few weeks, successfully, but occasionally requires being run a few times to return records. Just lately it seems to require run more than a few times to make it work.
When it doesn't return records , it seems to connects and start retrieving data, but returns only randomly like 100 - 200 rows with 1 error. The error doesn't have any message. So its hard to troubleshoot from that perspective.
Query appends two other large and merges in a few others. The data sources are either csv files, Sharepoint Lists and tables in workbook.
I haven't identified anything in terms of environment or query changes that might cause this.
When it finally does retrieve all records, it might be after i have done the following things, but i can't say for certain exactly what did the trick:
* to run query multiple times
*maybe simply changing anything in query resolves issue
* making upstream queries (that are merged or appended into this query) to Not Load to worksheet or model, eg just have connection
I'd think this type of error and situation while not common is encountered by others.
Does this ring a bell for anyone, and if so, can you please shed some light on the reasons and resolutions for this?
Thanks!If you click on "1 error" it should show the editor with a query that will select the rows with errors. This unfortunately might not show all errors for various reasons, but you should try it.
If that doesn't work, here's an example of how to retrieve error details.
Suppose the following query:
= Table.FromRecords({[A="B", B="C" + 1]})
Notice how we're using the + operator with a string and number. This will result in an error.
I can create a custom column that uses the 'try' operator over the B column. This returns a record with details which I then expand to retrieve the message.
let
Source = Table.FromRecords({[A="B", B="C" + 1]}),
#"Added Custom" = Table.AddColumn(Source, "Custom", each try [B]),
#"Expand Custom" = Table.ExpandRecordColumn(#"Added Custom", "Custom", {"HasError", "Error"}, {"Custom.HasError", "Custom.Error"}),
#"Expand Custom.Error" = Table.ExpandRecordColumn(#"Expand Custom", "Custom.Error", {"Message"}, {"Custom.Error.Message"})
in
#"Expand Custom.Error"
Let me know how this works for you.
Tristan -
Load rows with date fileds include time
Hi, I need to load rows with SQLLoader. The data has am field with date and time but using mask don4t load the time, only date. How do I load date and time?
Thanks...The following should work to load both the date and time (as long as it is not rejected for some reason)date_cancel date "YYYY/MM/DD HH24:MI:SS"To display the date and time after it has been loaded, you will have to use on of the following:ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH:MI:SS AM';
or
SELECT to_char(<column_name,'DD-MON-YYYY HH:MI:SS AM') from <table_name>; -
Load fact table with null dimension keys
Dear All,
We have OWB 10g R2 and ROLAP star schema. In our source system some rows don’t have all attributes populated with values (null value), and this empty attributes are dimension (business) keys in star schema. Is it possible to load fact table with such rows (some dimension keys are null) in the OWB mappings? We use cube operator in mappings.
Thanks And Regards
MiranThe dimension should have a row indicating UNKNOWN, this will have a business key outside of the normal range e.g. -999999.
In the mapping the missing business keys can then be NVL'd to -999999.
Cheers
Si -
How can i get all these values in single row with comma separated?
I have a table "abxx" with column "absg" Number(3)
which is having following rows
absg
1
3
56
232
43
436
23
677
545
367
xxxxxx No of rows
How can i get all these values in single row with comma separated?
Like
output_absg
1,3,56,232,43,436,23,677,545,367,..,..,...............
Can you send the query Plz!These all will do the same
create or replace type string_agg_type as object
2 (
3 total varchar2(4000),
4
5 static function
6 ODCIAggregateInitialize(sctx IN OUT string_agg_type )
7 return number,
8
9 member function
10 ODCIAggregateIterate(self IN OUT string_agg_type ,
11 value IN varchar2 )
12 return number,
13
14 member function
15 ODCIAggregateTerminate(self IN string_agg_type,
16 returnValue OUT varchar2,
17 flags IN number)
18 return number,
19
20 member function
21 ODCIAggregateMerge(self IN OUT string_agg_type,
22 ctx2 IN string_agg_type)
23 return number
24 );
25 /
create or replace type body string_agg_type
2 is
3
4 static function ODCIAggregateInitialize(sctx IN OUT string_agg_type)
5 return number
6 is
7 begin
8 sctx := string_agg_type( null );
9 return ODCIConst.Success;
10 end;
11
12 member function ODCIAggregateIterate(self IN OUT string_agg_type,
13 value IN varchar2 )
14 return number
15 is
16 begin
17 self.total := self.total || ',' || value;
18 return ODCIConst.Success;
19 end;
20
21 member function ODCIAggregateTerminate(self IN string_agg_type,
22 returnValue OUT varchar2,
23 flags IN number)
24 return number
25 is
26 begin
27 returnValue := ltrim(self.total,',');
28 return ODCIConst.Success;
29 end;
30
31 member function ODCIAggregateMerge(self IN OUT string_agg_type,
32 ctx2 IN string_agg_type)
33 return number
34 is
35 begin
36 self.total := self.total || ctx2.total;
37 return ODCIConst.Success;
38 end;
39
40
41 end;
42 /
Type body created.
[email protected]>
[email protected]> CREATE or replace
2 FUNCTION stragg(input varchar2 )
3 RETURN varchar2
4 PARALLEL_ENABLE AGGREGATE USING string_agg_type;
5 /
CREATE OR REPLACE FUNCTION get_employees (p_deptno in emp.deptno%TYPE)
RETURN VARCHAR2
IS
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 ERRORS
The function can then be incorporated into a query as follows.
COLUMN employees FORMAT A50
SELECT deptno,
get_employees(deptno) AS employees
FROM emp
GROUP by deptno;
###########################################3
SELECT SUBSTR(STR,2) FROM
(SELECT SYS_CONNECT_BY_PATH(n,',')
STR ,LENGTH(SYS_CONNECT_BY_PATH(n,',')) LN
FROM
SELECT N,rownum rn from t )
CONNECT BY rn = PRIOR RN+1
ORDER BY LN desc )
WHERE ROWNUM=1
declare
str varchar2(32767);
begin
for i in (select sal from emp) loop
str:= str || i.sal ||',' ;
end loop;
dbms_output.put_line(str);
end;
COLUMN employees FORMAT A50
SELECT e.deptno,
get_employees(e.deptno) AS employees
FROM (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
CREATE OR REPLACE FUNCTION concatenate_list (p_cursor IN SYS_REFCURSOR)
RETURN VARCHAR2
IS
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;
COLUMN employees FORMAT A50
SELECT e1.deptno,
concatenate_list(CURSOR(SELECT e2.ename FROM emp e2 WHERE e2.deptno = e1.deptno)) employees
FROM emp e1
GROUP BY e1.deptno;
DEPTNO EMPLOYEES
10 CLARK,KING,MILLER
20 SMITH,JONES,SCOTT,ADAMS,FORD
30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES
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 VARCHAR2
PARALLEL_ENABLE AGGREGATE USING t_string_agg;
/ -
Report Row With Detail (IFRAME) - How to reload Main Page within iFrame
Hi,
Based on Carl's example - Report Row With Detail (IFRAME), i.e:
http://htmldb.oracle.com/pls/otn/f?p=11933:17
Within my scenario, I have a button within the iframe section of my report that calls a pl/sql process that performs some database processing.
What I basically need is a means of performing a page refresh of the main page, when this button within the iframe is pressed. In Carl's example, that would be page 17.
As mentioned, I call a PL/SQL process within the iframe, but unsure how to then refresh the main page - parent page.
Any help would be appreciated.
Thanks.
Tony.Tony,
you could insert the following script to the region footer of a region located on your "iframe"-page.
<script>
parent.location.reload();
</script>
But this is dangerous because everytime the parent is being reloaded, the iframe is loaded, too. Risk of loop...
A possible solution is to conditionally display a html region (with the script) on your iframe-page basing on a request. You could post the request as a result after your plsql processing in a branch.
Regards,
Jens -
Report row with detail (AJAX)
Hi,
In Carl's report row with detail (AJAX) demo, is there any way to show all detail row by default when the page is loaded?
http://apex.oracle.com/pls/otn/f?p=11933:13
Thanks.
AndyHi Andy,
In Carl's example, the "details" content seems to be from a table that has a one-to-one relationship with the main table. If this is the case, you would probably find it easier to use a "Named Column (row template)" type of report template and lay out the report as you need it rather than use Ajax
Otherwise, I'm sure it would be possible to loop through a report and make a series of Ajax calls to retrieve the details should there be multiple records required.
Andy -
How to delete the duplicate data in between two distinct rows in SQL?
Hi,
I need to identify the duplicate data with two distinct rows. See my data structure below.
NAME NAME_1 VALUE START_DATE END_DATE FLAG INDEX
SUR SE 275 13/12/2005 31/12/2010 B 1
SUR SE 375 A 1
SUR SE 475 A 1
SUR SE 275 13/12/2005 31/12/2010 B 2
SUR SE 375 A 2
SUR SE 475 A 2
SUR SE 175 13/12/2006 31/12/2010 B 3
SUR SE 375 A 3
SUR SE 475 A 3
This is my sample data. Here data are duplicate with different index columns. INDEX 1 and 2 contains same group of combination. So i need to identify any one of duplicate combination(i.e INDEX 1 or 2). Can anyone come up with exact solution?
ThanksTry this:
with test_table as
(select 'SUR' NAME, 'SE' NAME_1, 275 VALUE, '13/12/2005' START_DATE, '31/12/2010' END_DATE, 'B' FLAG, 1 IND from dual union all
select 'SUR', 'SE', 375, null, null, 'A', 1 from dual union all
select 'SUR', 'SE', 475, null, null, 'A', 1 from dual union all
select 'SUR', 'SE', 275, '13/12/2005' ,'31/12/2010' ,'B', 2 from dual union all
select 'SUR', 'SE', 375, null, null, 'A', 2 from dual union all
select 'SUR', 'SE', 475, null, null, 'A', 2 from dual union all
select 'SUR', 'SE', 175, '13/12/2006', '31/12/2010', 'B', 3 from dual union all
select 'SUR', 'SE', 375, null, null, 'A', 3 from dual union all
select 'SUR', 'SE', 475, null, null, 'A', 3 from dual )
select t.*,
CASE WHEN START_DATE IS NULL THEN
first_value(row_number) OVER (PARTITION BY NAME, NAME_1, IND ORDER BY START_DATE)
ELSE
row_number
END row_number
from (
SELECT t.*,
CASE WHEN START_DATE IS NOT NULL THEN
row_number() over(PARTITION BY NAME, NAME_1,VALUE, START_DATE, END_DATE, FLAG
ORDER BY IND)
END row_number
FROM test_table t) t
order by IND, start_dateNote that this is only checking for diferences in the rows where start_date is not null. Do you want to also check if the records where start_date is null it there are differences? If so you can do this:
with test_table as
(select 'SUR' NAME, 'SE' NAME_1, 275 VALUE, '13/12/2005' START_DATE, '31/12/2010' END_DATE, 'B' FLAG, 1 IND from dual union all
select 'SUR', 'SE', 375, null, null, 'A', 1 from dual union all
select 'SUR', 'SE', 475, null, null, 'A', 1 from dual union all
select 'SUR', 'SE', 275, '13/12/2005' ,'31/12/2010' ,'B', 2 from dual union all
select 'SUR', 'SE', 375, null, null, 'A', 2 from dual union all
select 'SUR', 'SE', 475, null, null, 'A', 2 from dual union all
select 'SUR', 'SE', 175, '13/12/2006', '31/12/2010', 'B', 3 from dual union all
select 'SUR', 'SE', 375, null, null, 'A', 3 from dual union all
select 'SUR', 'SE', 475, null, null, 'A', 3 from dual )
SELECT t.*,
MIN(row_number) OVER(PARTITION BY NAME, NAME_1, IND) MIN
FROM (SELECT t.*,
row_number() over(PARTITION BY NAME, NAME_1, VALUE,
START_DATE, END_DATE, FLAG
ORDER BY IND) row_number
FROM test_table t) t
ORDER BY IND,
start_date;Edited by: Manuel Vidigal on 13/Abr/2009 12:05
Maybe you are looking for
-
Can't get wireless to work on my Lenovo Y500
i can get on the internet using wifi-menu wlp3s0, picking my ssid and pw. i also followed the directions for wpa_supplicant. ip link wlan0 up : gives me error device not found wlan0. If i go to the gui in xfce to network connections if i hit add new
-
Utl_smtp and problem with french language characters
Hello, I am using utl_smtp to send email. Here is part of the proc: First try: mail_conn := utl_smtp.open_connection(mailhost, 25); utl_smtp.helo(mail_conn, mailhost); utl_smtp.mail(mail_conn, sender); utl_smtp.rcpt(mail_conn, recipient); utl_smtp.op
-
Is it possible to include an Icon in a Jar file that will be displayed for the jar file instead of a default Icon give to it by Windows 2000? If so, how is it done? Thanks
-
Trying to run ConnBeanDemo.jsp and get this error: java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=150999297)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4)))) What does this mean ?
-
Oracle 9.2 Installation Guide; User question
Hi, i want to install Oracle 9.2 on SuSE Linux 9.3 professional. Beacuase of that i read Ivan Kartik's Installation Guide. But i don't understand the first step. I create an oracle user, but how can i log in as the oracle user? Because whenever i try