Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of creating sequence and sequence Zero filling examples in oracle

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Detailed explanation of creating sequence and sequence Zero filling examples in oracle

We often create sequences in DB:

-- Create sequence create sequence COMMON_SEQminvalue 1maxvalue 999999999start with 1increment by 1cache 20cycle

The minimum value of our sequence starts at 1, but we want the number of digits taken out in this order to be the same. according to the number of digits of the maximum number, we need an 8-bit sequence, so we need to add seven zeros in front of 1, which can be done by using the following method

Select to_char (sysdate,'yyyyMMddHH24miss') | | replace (lpad (common_sql.nextval,8,'0'),'','0') from dual

The above function lpad is zero padding on the left, and rpad is zero padding on the right.

There are other parts of the whole sql, that is, we can show the sequence with a specific beginning, for example, we use 14 bits of the year, month, day, hour and second as the beginning of our sequence, which is the complete sql above.

Thank you for reading, hope to help you, thank you for your support to this site!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report