Question: This is my MySQL query. How can I run this query in Oracle? Right now it's not working. 

```
SELECT * FROM mytable WHERE id IN (1,2,3,4) ORDER BY FIELD(id,3,2,1,4);

```

Answer: 
Here is a stupid solution: (:-D)

```
SELECT * FROM mytable WHERE id IN (1,2,3,4)
ORDER BY CASE id WHEN 3 THEN 1
                 WHEN 2 THEN 2
                 WHEN 1 THEN 3
                 WHEN 4 THEN 4 END;

```

Or use `DECODE` function:

```
SELECT * FROM mytable WHERE id IN (1,2,3,4)
ORDER BY DECODE(id, 3, 1, 2, 2, 1, 3, 4, 4, 0)

```
Oracle does not have a `FIELD` function but you can create your own instead

```
create TYPE T_VAR IS TABLE OF varchar2(4000);
/

create or replace function FIELD(p_val varchar2, p_var t_var) return number is
    begin
      for i in 1..p_var.count
        loop
          if p_val = p_var(i) then
            return i;
          end if;
        end loop;

      return p_var.count + 1;
end FIELD;
/

```

Query

```
SELECT t.*
  FROM mytable t
 WHERE id IN (1, 2, 3, 4)
 order by FIELD(id,T_VAR(3,2,1,4))

```

**NOTE**: You should create one more function `FIELD` with this signature `FIELD (p_val number, p_var t_var)` for explicit data type conversation. Function before is universal but can be cause of some bizarre effects.