sql - For every Request_number, assign the v_id on each voucher a number starting with 1 and incrementing by 1 -
Hi Everyone, I need some help, please.
I have to do pl / sql with the following:
For each request number, the number starting with number 1 on each voucher and increases by 1. For example, if there are 3 vouchers attached to the request number 786530, the first voucher should be v_id 1, the second voucher should have v_id 2, the third voucher should have v_id 3.
table this looks like
Request_NO Voucher_no V_id 200 22211 null 200 22212 null 200 22213 null 201 22214 null 202 22215 null 202 22216 null 203 22217 null 204 22218 null < / code>
You can use a merge for efficiency:
table voucher (request number - number no, tap, voucher number number primary key, v_id number); Insert in vouchers values (20022211, blank); Insert in vouchers values (20022212, blank); Insert in vouchers values (20022213, blank); Insert in vouchers values (201,22214, blank); Insert in vouchers values (202,22215, blank); Insert in vouchers values (202,22216, blank); Insert in vouchers values (203,22217, blank); Insert in vouchers values (204,22218, blank); Do v_id = new_v_id set when matched to Merge vouchers (voucher_no, division by 1 request by row_number () (request) as new_v_id voucher) (s.woucher_no = s.voucher_no); Choose from voucher *; Rik vouch v_id === ===== ==== 200 22211 1 200 22212 2 200 22213 3 201 22214 1 202 22215 1 202 22216 2 203 22217 1 204 22218 1
Comments
Post a Comment