I have a STUDENT
table and need to update the STUDENT_ID
values by prefixing with the letter SS
followed by STUDENT_ID
value. For any duplicate STUDENT_ID
records, I should prefix the duplicate records as SS1
SS2
. Below is an example
Before Update:
| NUM | STUDENT_ID |
| ------------ | ------------ |
| 1 | 9234 |
| 2 | 9234 |
| 3 | 9234 |
| 4 | 3456 |
| 5 | 3456 |
| 6 | 789 |
| 7 | 956 |
After Update:
| NUM | STUDENT_ID |
| ------------ | ------------ |
| 1 | SS9234 |
| 2 | SS19234 |
| 3 | SS29234 |
| 4 | SS3456 |
| 5 | SS13456 |
| 6 | SS789 |
| 7 | SS956 |
Below is the query for updating the STUDENT_ID
for unique records.
update student set student_id = 'SS'||student_id ;
commit;
Need suggestion for updating the STUDENT_ID
for duplicate records. There are around 1 million duplicate records in the table and total volume is around 40 million. Appreciate for any inputs for performance enhancement.
3条答案
按热度按时间z9smfwbn1#
Maybe you could do it without updating!?
I would probably try to :
SELECT with your sample data:
Result:
| NUM | STUDENT_ID |
| ------------ | ------------ |
| 1 | SS9234 |
| 2 | SS19234 |
| 3 | SS29234 |
| 4 | SS3456 |
| 5 | SS13456 |
| 6 | SS789 |
| 7 | SS956 |
xesrikrc2#
You can use a
MERGE
statement correlated on theROWID
pseudo-column and using theROW_NUMBER()
analytic function:Which, for the sample data:
Then after the
MERGE
the table contains:| NUM | STUDENT_ID |
| ------------ | ------------ |
| 1 | SS9234 |
| 2 | SS19234 |
| 3 | SS29234 |
| 4 | SS3456 |
| 5 | SS13456 |
| 6 | SS789 |
| 7 | SS956 |
fiddle
r6l8ljro3#
我确信一定有更好的方法,但下面的查询可以完成这项工作:
结果:
请参阅db<>fiddle上的运行示例。