Get the App
SLTechnology News&Howtos  ›  Database  › 

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

Shulou Source: shulou.com Published: 2022-06-01 03:51:39 11月12日 Update

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!

Tags: Sequence that is medium creation digit beginning instance maximum minimum function right regular meeting year month day method time part face order help support Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB OPPO Reno Microsoft Shulou Information Linux