Question: How can i get current rule id in a same session because 

```
select ID from rules where ID=rules_seq.currval

```

is throwing error :

> 
> ORA-02287: sequence number not allowed here
> 
> 
>

Answer: 
You should **save** the sequence value when it is created using `NEXTVAL`.

For example if the `NEXTVAL` is used in `INSERT` there is a `RETURNING INTO` [clause](https://oracle-base.com/articles/misc/dml-returning-into-clause) for this purpose.

```
 INSERT INTO my_tab VALUES (seq.nextval, ...)
 RETURNING id INTO v_id;

```
if **ID** is **primary key** or other **index** you can use **index descending** to get maximum id

```
select --+ index_desc (r)
ID 
from rules r 
where rownum=1

```