Recently, we have been porting SQL to Oracle. Since Oracle does not have the same Identity column as in SQL, we have encountered a lot of trouble, recently I encountered a stored procedure for deleting data based on the values of the auto-incrementing column. I found a method for half a day.
- /* Procedure in Oracle */
- -- Create a table. Because there is no identity in Oracle, remove the aid column and use rownum later.
- Create table TempTable (
- SearchID number (10, 0)
- )
- -- Delete the value of Rownum 5
- Declare cursor tmp_cursorIsSelect rownum aid, searchid from TempTableForUpdate;
- Tmp_record tmp_cursor % rowtype;
- Begin
- Open tmp_cursor;
- Loop
- Fetch tmp_cursor into tmp_record;
- Exit when tmp_cursor % notfound;
- If(Tmp_record.aid = 5) -- If rownum is 5
- Then
- Begin
- Delete TempTable where current of tmp_cursor;
- End;
- EndIf;
- End loop;
- Close tmp_cursor;
- Commit;
- End;