| same sequence number for repeating data [message #577857] |
Thu, 21 February 2013 05:13  |
 |
guddu_12
Messages: 124 Registered: April 2012 Location: UK
|
Senior Member |
|
|
Dear All
I want to insert same sequence number for repeated data else new sequence.
my data is as below
EMP_NAME EMP_INV
Pras CTI
Pras CTI
Shariq Witness
Kate CTI
Shariq Assisted
Shariq Witness
the first 2 record are same Pras CTI and Pras CTI so i want my sequence generate value once as below
1 Pras CTI
1 Pras CTI
2 Shariq Witness
3 Kate CTI
4 Shariq Assisted
2 Shariq Witness
Shariq and witness are repeating so same sequence number but Kate CTI occured once so nextval of sequence
How can i acivee it , any help will be appriciated
CREATE TABLE EMP_INV
(
EMP_NAME VARCHAR2(100 BYTE),
EMP_INV VARCHAR2(100 BYTE)
)
Insert into EMP_INV
(EMP_NAME, EMP_INV)
Values
('Shariq', 'Witness');
Insert into EMP_INV
(EMP_NAME, EMP_INV)
Values
('Shariq', 'Assisted');
Insert into EMP_INV
(EMP_NAME, EMP_INV)
Values
('Kate', 'CTI');
Insert into EMP_INV
(EMP_NAME, EMP_INV)
Values
('Shariq', 'Witness');
Insert into EMP_INV
(EMP_NAME, EMP_INV)
Values
('Pras', 'CTI');
Insert into EMP_INV
(EMP_NAME, EMP_INV)
Values
('Pras', 'CTI');
COMMIT;
|
|
|
|
|
|
|
|
|
|
|
|
| Re: same sequence number for repeating data [message #577865 is a reply to message #577862] |
Thu, 21 February 2013 05:51   |
 |
Littlefoot
Messages: 16993 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
Assuming that sequence in your first message is just an example (because you didn't say how to order these records), here's an example; see whether you can adjust it according to your needs.
SQL> select
2 dense_rank() over (order by emp_name, emp_inv) rb,
3 emp_name,
4 emp_inv
5 from emp_inv
6 order by emp_name, emp_inv;
RB EMP_NAME EMP_INV
---------- ---------- --------------------
1 Kate CTI
2 Pras CTI
2 Pras CTI
3 Shariq Assisted
4 Shariq Witness
4 Shariq Witness
6 rows selected.
SQL>
P.S. Huh, didn't even see Pointers' message; though, he used RANK as opposed to my DENSE_RANK (which, I suppose, returns somewhat "better" result).
[Updated on: Thu, 21 February 2013 05:53] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
| Re: same sequence number for repeating data [message #577876 is a reply to message #577861] |
Thu, 21 February 2013 06:57   |
pointers
Messages: 324 Registered: May 2008
|
Senior Member |
|
|
Quote:Data is inserted by plsql job and rank will not solve the purpose as i want sequence value but rank will repeat for other set of data, i mean for the first record rank is 1 but for different set of record rank will start from once again 1 that is incorrect and this is incremental load
Here we are not using the option of partition, so there is no chance for setting the value to 1
See the output of this.
SELECT emp_name, emp_inv, RANK () OVER (ORDER BY emp_name, emp_inv)
FROM EMP_INV
Regards,
Pointers
|
|
|
|
|
|
|
|
|
|