There are several problems with your initial approach.
While the selected answer correctly provides a way to determine the current value of the sequence is does not address these problems:
- The value of the sequence might have changed between the call to NEXTVAL and CURRVAL. This will lead to a hard to detect bug and there is a possibility that you will get a value used by a different session. Use the returning clause in the insert statement to retrieve the actual inserted value.
- Your variable names are the same as your column names. This will lead to hard to detect bugs in queries embedded inside PL/SQL blocks. Make sure your variables are named differently - you can prefix them from the type name like v_userid instead of userid.
SELECT statement inside an Oracle PL/SQL block requires an INTO clause. Example:
SELECT userid INTO v_userid FROM bs_orders WHERE ono = orderNumberSEQ;
The sub-query for current_timestamp is redundant. You can use plain CURRENT_TIMESTAMP in place of the sub-query to achieve the same result.
Instead of manually providing the column type. Anchor it to the exact table type using %type notation.
v_userid bs_orders.userid%type;
The following code addresses all 5 issues.
DECLARE
v_userid bs_orders.userid%type; -- anchoring the type
BEGIN
INSERT INTO bs_orders(userid , ono , timepurchased)
VALUES('lilith', orderNum_seq.NEXTVAL, CURRENT_TIMESTAMP)
RETURNING userid INTO v_userid; -- instead of currval and an additional select
-- do whatever you want with v_userid here
END;
/