begin transaction SELECT nextval('seq_order_id') as orderId SELECT * FROM orders WHERE accountid = ? AND status IN (3, 7) INSERT INTO orders (orderid, ... ) end transaction