I have a table MY_TABLE with a primary key MY_PK. Then, I have a list of ordered primary keys, for example (17,13,35,2,9).
Now I want to retrieve all rows with these primary keys, and keep the order of the rows in the same way as the given list of keys.
What I was initally doing was:
SELECT * FROM MY_TABLE WHERE MY_PK IN (:my_list)
But then the order of the returned rows is random and does not correspond to the order of the given keys anymore. Is there a way to achieve that? The only thing I thought of is making many SELECT statements and concatenate them with UNION, but my list of primary keys can be very long and contain hundreds or even thousands of keys. The alternative I thought of was to reorder the rows afterwards in the application, but I would prefer a solution where this is not necessary.