SUSE Linux Enterprise Server 15 for SAP Application 是SUSE专门为SAP产品推出的企业级操作系统,针对SAP应用进行了大量优化和测试,并内嵌了高可用功能,旨在为用户的SAP HANA HDB序列的使用方法及技巧(SAP HANA HDB SEQUENCE):
语法:CREATE SEQUENCE <sequence_name> [<common_sequence_parameter_list>] [RESET BY <subquery>] <sequence_name> ::= <identifier> <common_sequence_parameter_list> ::= <common_sequence_parameter>, ... <common_sequence_parameter> ::= <sequence_parameter_start_with> | <basic_sequence_parameter> <basic_sequence_parameter> ::= INCREMENT BY n <sequence_parameter_start_with> ::= START WITH nINCREMENT BY:用于定义序列的步长,如果省略,则默认为1,如果出现负值,则代表Oracle序列的值是按照此步长递减的。如果INCREMENT BY为0,会出现错误。START WITH :定义序列的初始值(即产生的个值)。如果没指定初始值,在升序增长的序列中MINVALUE将作为初始值,而在江西增长增长的序列中MAXVALUE将作为初始值。MAXVALUE :定义序列生成器能产生的大值。大值范围:0 ~ 4611686018427387903NO MAXVALUE:当没有指定大值时,升序序列大值为461168601842738790,降序序列大值是- 1。MINVALUE:定义序列生成器能产生的小值。小值范围:0~461168601842738790NO MINVALUE:当没有指定小值时,升序序列小值为:1,降序序列小值是:- 461168601842738790。CYCLE和NOCYCLE 表示当序列生成器的值达到限制值后是否循环。CYCLE代表循环,NOCYCLE代表不循环。如果循环,则当递增序列达到大值时,循环到小值;对于递减序列达到小值时,循环到大值。如果不循环,达到限制值后,继续产生新值就会发生错误。RESET BY:在重新启动数据库,数据库自动执行重置复位,复位后序列的值将重新初始化为指定的值。如果复位不指定,序列值被保存在数据库。在重新启动数据库,下-------------------------------------------------------------------------------CREATE SEQUENCE TEST_SEQ START WITH 10;SELECT TEST_SEQ.NEXTVAL FROM DUMMY;----------------------------------------------------------------------------------SELECT TEST_SEQ.CURRVAL FROM DUMMY;----------------------------------------------------------------------------------CREATE SEQUENCE TEST_SEQ_1 INCREMENT BY 2 MAXVALUE 50000 MINVALUE 10 CYCLE;CREATE SEQUENCE TEST_SEQ_2 INCREMENT BY 0 MAXVALUE 50000 MINVALUE 10 CYCLE;错误信息:SAP DBTech JDBC: [313] (at 41): invalid sequence: INCREMENT must be a non-zero integer。CREATE SEQUENCE TEST_SEQ_3;SELECT TEST_SEQ_3.NEXTVAL FROM DUMMY;----------------------------------------------------------------------------------------------CREATE SEQUENCE TEST_SEQ_4 INCREMENT BY 5 MAXVALUE 100 MINVALUE 10 CYCLE;查询SELECT TEST_SEQ_4.NEXTVAL FROM DUMMY循环19次。初始值又从10开始----------------------------------------------------------------------------------------------CREATE SEQUENCE TEST_SEQ_5 INCREMENT BY 5 MAXVALUE 100 MINVALUE 10 NO CYCLE;查询SELECT TEST_SEQ_5.NEXTVAL FROM DUMMY循环19次。Could not execute 'SELECT TEST_SEQ_5 .NEXTVAL FROM DUMMY' SAP DBTech JDBC: [312]: sequence is exhausted: . SAP DBTech JDBC: [312]: sequence is exhausted:----------------------------------------------------------------------------------------------CREATE SEQUENCE TEST_SEQ_6 INCREMENT BY -5 MAXVALUE 100 MINVALUE 10 CYCLE;------------------------------------------------------------------------------------------------------------CREATE SEQUENCE s RESET BY SELECT IFNULL(MAX(a), 0) + 1 FROM r;SELECT s.NEXTVAL FROM DUMMY;CREATE SEQUENCE TEST_SEQ_8 start with 10 INCREMENT BY 5 MAXVALUE 100 MINVALUE 10 CYCLE RESET BY SELECT IFNULL(MAX(a), 0) + 5 FROM r;DROP SEQUENCE <sequence_name> [<drop_option>]删除模式:两种限制(RESTRICT), 级联(CASCADE)。 <drop_option> ::= CASCADE | RESTRICT限制(RESTRICT): 如果存在任何依赖的对象,则拒绝删除序列。这个是缺省值。来源 https://mp.weixin.qq.com/s/St5VT9EMavRMR0xKuV2ang