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;

```
Maybe you can select the highest ID.

```
select max(ID) from rules

```

This will also get you around the problem that not all numbers generated by the sequence are actually used in a record.

On the other hand, if, in your session, the sequence was used. Why not

```
select rules_seq.currval from dual

```

And finally, if this all takes place in PLSQL you can either return the generated the ID into a variable:

```
declare
   l_id rules.id%type;
begin
  insert into rules (id) 
   values (rules_seq.nextval) 
  returning id into l_id;
end;

```

or assign the sequence value to the variable before the insert.

```
declare
       l_id rules.id%type;
    begin
      l_id := rules_seq.nextval;
      insert into rules (id) 
       values (l_id);
    end;

```