Here I've found how to define a variable in Oracle SQL Developer.
But can we define the range of values somehow?
I need smth like this:
define my_range = '55 57 59 61 67 122';
delete from ITEMS where ITEM_ID in (&&my_range);
Here I've found how to define a variable in Oracle SQL Developer.
But can we define the range of values somehow?
I need smth like this:
define my_range = '55 57 59 61 67 122';
delete from ITEMS where ITEM_ID in (&&my_range);
Actually if you put commas in your list it will work since you are using a substitution parameter (not a bind variable):
define my_range = '55, 57, 59, 61, 67, 122';
delete from ITEMS where ITEM_ID in (&&my_range);
Use a collection:
CREATE TYPE INT_TABLE AS TABLE OF INT;
/
Then you can do:
DEFINE my_range = '55,57,59,61,67,122';
DELETE FROM items
WHERE ITEM_ID MEMBER OF INT_TABLE( &&my_range );
Example:
CREATE TABLE ITEMS ( ITEM_ID ) AS
SELECT LEVEL FROM DUAL CONNECT BY LEVEL <= 150;
DEFINE my_range = '55,57,59,61,67,122';
DELETE FROM items WHERE ITEM_ID MEMBER OF INT_TABLE( &&my_range );
Output:
Table ITEMS created.
old:DELETE FROM items WHERE ITEM_ID MEMBER OF INT_TABLE( &&my_range );
new:DELETE FROM items WHERE ITEM_ID MEMBER OF INT_TABLE( 55,57,59,61,67,122 );
6 rows deleted.
You can use LIKE and just change the way you contain your variable.. Something like this:
define my_range = ',55,57,59,61,67,122,';
delete from ITEMS
where $$my_range like ('%,' || ITEM_ID || ',%');