|
|
|
|
|
|
Re: Start value of sequence 00001 [message #336843 is a reply to message #336828] |
Tue, 29 July 2008 03:32   |
naikjigar
Messages: 51 Registered: July 2008 Location: India
|
Member |

|
|
How am i going to use TO_CHAR
if my seq.nextval gives me 10 than my total length will be 21 digits. n so on. 22.. 23
i can not even measure the length of the seq's returned value, and append conditional 0
SELECT '2' || TO_CHAR(SYSDATE,'YYYYMMDDHHMISS') || '0000' || TO_CHAR(SEQ_OUTBOUND.NEXTVAL) AS PrimaryKey FROM DUAL
PRIMARYKEY
------------------------
22008072901523100009 //Length is 20 fine.
SQL> /
PRIMARYKEY
------------------------
220080729015233000010 //Length is 21 bad.
SQL>
[Updated on: Tue, 29 July 2008 03:33] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Start value of sequence 00001 [message #336883 is a reply to message #336878] |
Tue, 29 July 2008 05:10   |
ThomasG
Messages: 3212 Registered: April 2005 Location: Heilbronn, Germany
|
Senior Member |
|
|
Quote: | Please tell us the disadvantage of using LPAD in this case.
|
One disadvantage is that you have:
- Executed one implicit conversion from number to char
- Executed one LPAD function.
When you just do an
to_char(SEQ_OUTBOUND.NEXTVAL,'fm00000')
you only have executed one explicit conversion from number to char.
So you have only half the number of function calls running on the DB.
Another disadvantage is that you might get wrap-around duplicate values some day. Consider the difference in results:
SELECT LPad(4444,2,'0') FROM dual;
SELECT to_char(4444,'fm00') FROM dual;
[Updated on: Tue, 29 July 2008 05:14] Report message to a moderator
|
|
|
|
|
Re: Start value of sequence 00001 [message #337065 is a reply to message #336828] |
Tue, 29 July 2008 16:37  |
Bill B
Messages: 1971 Registered: December 2004
|
Senior Member |
|
|
MAKE YOUR SEQUENCE USING THE FOLLOWING COMMAND
CREATE SEQUENCE SEQ_OUTBOUND
INCREMENT BY 1
START WITH 1
MAXVALUE 99999
MINVALUE 1
NOCACHE
CYCLE;
And insert your primary key during the insert, not by making the key first.
insert into my_table(key,col1,col2)
values('2'||TO_CHAR(SYSDATE,'YYYYMMDDHHMISS')||to_char(SEQ_OUTBOUND.NEXTVAL,'fm0000'),junk1,junk2);
|
|
|