May 29, 2012

Req: How to attach the empno number before predefined value in a particular column in employee table? Using Sequence .....

Create new table, or other wise copy existing table. Then Create Sequence. While Inserting data into database using bellow insert query. Every time empno before added " PREDIFINEDVALUE00 ".
ex: PREDIFINEDVALUE001
PREDIFINEDVALUE002
PREDIFINEDVALUE003
...
etc.

Queries:

CREATE TABLE EMP_ONE AS SELECT * FROM EMP;

CREATE SEQUENCE EMP_ONE_SEQ
MINVALUE 1
MAXVALUE 999999999999999999999999999
START WITH 1
INCREMENT BY 1
CACHE 20;

SELECT * FROM ALL_SEQUENCES WHERE SEQUENCE_NAME = 'EMP_ONE_SEQ';

SELECT EMP_ONE_SEQ.CURRVAL FROM dual;

INSERT INTO EMP_ONE SELECT 'PREDIFINEDVALUE00'|| EMP_ONE_SEQ.NEXTVAL, ENAME, JOB, MGR,
HIREDATE, SAL, COMM, DEPTNO FROM EMP;

No comments:

Post a Comment

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

My Favorite Site's List

#update below script more than 500 posts