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

How to reset the oracle sequence from 0 and increment by 1

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the relevant knowledge of "how to reset the sequence from 0 to increase 1". The editor shows you the operation process through an actual case. The method of operation is simple and fast, and it is practical. I hope this article "how to reset the sequence from 0 to increase 1" can help you solve the problem.

After the oracle sequence is created, if you want to reset the sequence starting from 0 and incrementing by 1, you can use the following stored procedure:

Create or replaceprocedure reset_seq (p_seq_name in varchar2) is l_val number;begin execute immediate 'select' | | p_seq_name | |. Nextval from dual' INTO execute immediate 'alter sequence' | | p_seq_name | | 'increment by -' | | l_val | | 'minvalue 0' | Execute immediate 'select' | | p_seq_name | |. Nextval from dual' INTO lumped vale; execute immediate 'alter sequence' | | p_seq_name | | 'increment by 1 minvalue 0 originating end

After the stored procedure is created, the stored procedure is called, and the parameter is the name of the sequence to be reset:

Call reset_seq ('test_seq')

Use the following SQL statement to query the sequence that needs to be reset:

SELECT a.sequence_name sequence name, minimum value of a.min_value sequence, maximum value of to_char (to_number (a.max_value)) sequence, current value of a.last_number sequence, CASE a.last_number WHEN 1 THEN'--no need to reset; 'ELSE'CALL seq_reset (''| | a.sequence_name | |'') 'END reset sequence script,' DROP SEQUENCE'| | a.sequence_name delete sequence script, 'RENAME' | | a.sequence_name | |'TO {newname} 'rename script FROM USER_SEQUENCES a WHERE a.last_number1ORDER BY a.sequence_name ASC;. That's all for "how to reset the sequence from 0 to increment 1". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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

Development

Wechat

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

12
Report