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;

```
It's a documented limitation of sequences that we cannot use them in a WHERE clause. [Check it here](http://docs.oracle.com/database/121/SQLRF/pseudocolumns002.htm#SQLRF00253).

What some may find surprising is that this extends to sub-queries (also documented, as @MarmiteBomber points out):

```
SQL> select * from t23
  2  where t23.id = (select s23.currval from dual)
  3  /
where t23.id = (select s23.currval from dual)
                           *
ERROR at line 2:
ORA-02287: sequence number not allowed here

SQL> 

```

Of course there is always PL/SQL but it's not very convenient.

```
SQL> set serveroutput on
SQL> declare
  2      n pls_integer;
  3      x pls_integer;
  4  begin
  5       n := s23.currval;
  6      select id into x
  7      from t23
  8      where id = n;
  9      dbms_output.put_line('x='||x);
 10  end;
 11  /
x=5

PL/SQL procedure successfully completed.

SQL> 

```