Skip to content

Instantly share code, notes, and snippets.

@igilham
Created January 5, 2011 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igilham/766519 to your computer and use it in GitHub Desktop.
Save igilham/766519 to your computer and use it in GitHub Desktop.
Insert using a sequence in a nested query in Oracle Database
CREATE SEQUENCE cid_seq
START WITH 100
INCREMENT BY 1;
CREATE OR REPLACE FUNCTION get_next_cseq
RETURN NUMBER AS l_return NUMBER;
BEGIN
SELECT cid_seq.NEXTVAL INTO l_return FROM DUAL;
RETURN l_return;
END;
/
INSERT INTO
orphans
(
SELECT
get_next_cseq() AS customer_id,
name
FROM
(
SELECT
...
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment