3.2.5.6. DM
3.2.5.6.1. 创建索引
语法
CREATE [UNIQUE|BITMAP] INDEX [SCHEMA.] INDEX_NAME
ON TABLE_NAME ( COLUMN1, COLUMN2, ..., COLUMNN )
[{ LOGGING | NOLOGGING}]
[{ GLOBAL | LOCAL}]
[{ USABLE | UNUSABLE}]
[{ ENABLE | DISABLE}]
[{ IMMEDIATE INVALIDATION | UNUSABLE}]
[tablespace tablespaceName] [local]
示例
--创建表
CREATE TABLE unisql_index_test(col1 int,col2 int,col3 int,col4 int,col5 varchar(10));
-- 删除存在的索引
DROP INDEX unisql_index_test_idx;
-- 转换前Oracle SQL:
-- 使用示例
CREATE INDEX unisql_index_test_idx ON unisql_index_test (col1);
CREATE UNIQUE INDEX unisql_index_test_idx ON unisql_index_test(col1);
CREATE BITMAP INDEX unisql_index_test_idx ON unisql_index_test (col1);
CREATE INDEX test.unisql_index_test_idx ON unisql_index_test(col1);
CREATE INDEX unisql_index_test_idx ON unisql_index_test(col1 asc);
CREATE INDEX unisql_index_test_idx ON unisql_index_test(col1 desc);
CREATE INDEX unisql_index_test_idx ON unisql_index_test(col1,col2);
CREATE INDEX unisql_index_test_idx ON unisql_index_test(col1) LOGGING;
CREATE INDEX unisql_index_test_idx ON unisql_index_test(col1) NOLOGGING;
CREATE INDEX unisql_index_test_idx ON unisql_index_test(col1) GLOBAL;
CREATE INDEX unisql_index_test_idx ON unisql_index_test(col1) USABLE;
CREATE INDEX unisql_index_test_idx ON unisql_index_test(col1) UNUSABLE;
-- 转换后达梦 SQL:
CREATE INDEX unisql_index_test_idx ON unisql_index_test (col1);
CREATE UNIQUE INDEX unisql_index_test_idx ON unisql_index_test(col1);
CREATE BITMAP INDEX unisql_index_test_idx ON unisql_index_test (col1);
CREATE INDEX test.unisql_index_test_idx ON unisql_index_test(col1);
CREATE INDEX unisql_index_test_idx ON unisql_index_test(col1);
CREATE INDEX unisql_index_test_idx ON unisql_index_test(col1 desc);
CREATE INDEX unisql_index_test_idx ON unisql_index_test(col1,col2);
CREATE INDEX unisql_index_test_idx ON unisql_index_test(col1);
CREATE INDEX unisql_index_test_idx ON unisql_index_test(col1);
CREATE INDEX unisql_index_test_idx ON unisql_index_test(col1) GLOBAL;
CREATE INDEX unisql_index_test_idx ON unisql_index_test(col1);
CREATE INDEX unisql_index_test_idx ON unisql_index_test(col1) UNUSABLE;
-- 创建表,LOCAL索引需要创建在分区表上
CREATE TABLE unisql_local_test_orders (
order_id int,
order_num int,
customer varchar(50)
)
PARTITION BY RANGE (order_num)
(
PARTITION p1 VALUES LESS THAN (100),
PARTITION p2 VALUES LESS THAN (200),
PARTITION p3 VALUES LESS THAN (MAXVALUE)
);
-- 删除存在的索引
DROP INDEX unisql_local_test_orders_idx;
-- 转换前Oracle SQL:
-- 使用示例
CREATE INDEX unisql_local_test_orders_idx ON unisql_local_test_orders(order_num) LOCAL;
CREATE INDEX unisql_local_test_orders_idx ON unisql_local_test_orders(order_num) tablespace test LOCAL;
-- 转换后达梦 SQL:
CREATE INDEX unisql_local_test_orders_idx ON unisql_local_test_orders (order_num)
CREATE INDEX unisql_local_test_orders_idx ON unisql_local_test_orders (order_num)
3.2.5.6.2. 创建分区表
分区范围支持使用函数、字符串、常数表达,统一SQL会根据表名、分区名在转化库中创建分区表,分区表名为:表名_1_prt_分区名
语法
CREATE TABLE TABLE_NAME …PARTITION BY[HASH|RANGE|LIST] (partition_list)
示例
-- 转换前Oracle SQL:
CREATE TABLE unisql_partition_by_range_test
(
product_id NUMBER(6),
sale_time TIMESTAMP(6),
sale_price NUMBER(10,2)
)
PARTITION BY RANGE (sale_time)
(
PARTITION q1_2023 VALUES LESS THAN (TO_DATE('2023/04/01', 'yyyy/mm/dd')),
PARTITION q2_2023 VALUES LESS THAN (TO_DATE('2023/07/01', 'yyyy/mm/dd')),
PARTITION q3_2023 VALUES LESS THAN (TO_DATE('2023/10/01', 'yyyy/mm/dd')),
PARTITION q4_2023 VALUES LESS THAN (TO_DATE('2024/01/01', 'yyyy/mm/dd'))
);
-- 转换后达梦 SQL:
-- CREATE TABLE unisql_partition_by_range_test(product_id NUMBER(6),sale_time TIMESTAMP(6),sale_price NUMBER(10,2))PARTITION BY RANGE (sale_time)(PARTITION q1_2023 VALUES LESS THAN (TO_DATE('2023/04/01', 'yyyy/mm/dd')),PARTITION q2_2023 VALUES LESS THAN (TO_DATE('2023/07/01', 'yyyy/mm/dd')),PARTITION q3_2023 VALUES LESS THAN (TO_DATE('2023/10/01', 'yyyy/mm/dd')),PARTITION q4_2023 VALUES LESS THAN (TO_DATE('2024/01/01', 'yyyy/mm/dd')));
CREATE TABLE unisql_partition_by_range_test
(
product_id NUMBER(6),
sale_time TIMESTAMP(6),
sale_price NUMBER(10,2)
)
PARTITION BY RANGE (sale_time)
(
PARTITION q1_2023 VALUES LESS THAN (TO_DATE('2023/04/01', 'yyyy/mm/dd')),
PARTITION q2_2023 VALUES LESS THAN (TO_DATE('2023/07/01', 'yyyy/mm/dd')),
PARTITION q3_2023 VALUES LESS THAN (TO_DATE('2023/10/01', 'yyyy/mm/dd')),
PARTITION q4_2023 VALUES LESS THAN (TO_DATE('2024/01/01', 'yyyy/mm/dd'))
);
-- 转换前Oracle SQL:
create table unisql_partition_by_list_test
(
id varchar2(15) not null,
city varchar2(20)
)
partition by list (city)
(
partition p1 values ('beijing'),
partition p2 values ('shanghai'),
partition p3 values ('changsha'),
partition p4 values (default)
);
-- 转换后达梦 SQL:
-- create table unisql_partition_by_list_test(id varchar2(15) not null,city varchar2(20))partition by list (city)(partition p1 values ('beijing'),partition p2 values ('shanghai'),partition p3 values ('changsha'),partition p4 values (default));
create table unisql_partition_by_list_test
(
id varchar2(15) not null,
city varchar2(20)
)
partition by list (city)
(
partition p1 values ('beijing'),
partition p2 values ('shanghai'),
partition p3 values ('changsha'),
partition p4 values (default)
);
-- 转换前Oracle SQL:
CREATE TABLE unisql_partition_by_hash_test (col1 INT, col2 VARCHAR(50), col3 TIMESTAMP )
PARTITION BY HASH (col1) PARTITIONS 4;
-- 转换后达梦 SQL:
CREATE TABLE unisql_partition_by_hash_test (col1 INT, col2 VARCHAR(50), col3 TIMESTAMP ) PARTITION BY HASH (col1) PARTITIONS 4;
3.2.5.6.3. 清空、删除分区表
语法
ALTER TABLE TABLE_NAME [TRUNCATE|DROP] PARTITION PARTITION_NAMES
示例
-- 转换前Oracle SQL:
ALTER TABLE unisql_partition_by_range_test TRUNCATE PARTITION q1_2023;
ALTER TABLE unisql_partition TRUNCATE PARTITION unisql_partition_p1,unisql_partition_p2;
-- 转换后达梦 SQL:
ALTER TABLE unisql_partition_by_range_test TRUNCATE PARTITION q1_2023;
ALTER TABLE unisql_partition TRUNCATE PARTITION unisql_partition_p1;ALTER TABLE unisql_partition TRUNCATE PARTITION unisql_partition_p2;
-- 转换前Oracle SQL:
ALTER TABLE unisql_partition_by_range_test DROP PARTITION q1_2023;
ALTER TABLE unisql_partition DROP PARTITION unisql_partition_p1,unisql_partition_p2;
-- 转换后达梦 SQL:
ALTER TABLE unisql_partition_by_range_test DROP PARTITION q1_2023;
ALTER TABLE unisql_partition DROP PARTITION unisql_partition_p1;ALTER TABLE unisql_partition DROP PARTITION unisql_partition_p2;
3.2.5.6.4. 修改列的属性
语法
alter_table_stmt:
ALTER TABLE table_name alter_table_action_list;
alter_table_action_list:
alter_table_action [, alter_table_action ...]
alter_table_action:
MODIFY [COLUMN] column_definition
示例
DROP TABLE unisql_modify_column_test;
CREATE TABLE unisql_modify_column_test(a int,d number);
SELECT * FROM unisql_modify_column_test;
-- 转换前Oracle SQL:
ALTER TABLE unisql_modify_column_test MODIFY (d number(10));
ALTER TABLE unisql_modify_column_test MODIFY d number(8,2) DEFAULT '12' NOT NULL;
ALTER TABLE unisql_modify_column_test MODIFY (a varchar(10),d number(10));
ALTER TABLE unisql_modify_column_test MODIFY (a varchar(10) DEFAULT '1',d number(10));
ALTER TABLE unisql_modify_column_test MODIFY (a varchar(10) DEFAULT '1' NOT NULL ,d number(10) DEFAULT 10);
-- 转换后达梦 SQL:
ALTER TABLE unisql_modify_column_test MODIFY d number(10)
ALTER TABLE unisql_modify_column_test MODIFY d number(8,2) DEFAULT '12' NOT NULL
ALTER TABLE unisql_modify_column_test MODIFY(a varchar(10) DEFAULT '1',d number(10)
ALTER TABLE unisql_modify_column_test MODIFY(a varchar(10) DEFAULT '1' NOT NULL,d number(10) DEFAULT 10)
3.2.5.6.5. 修改表名
语法
RENAME TABLE_NAME TO NEW_TABLE_NAME;
ALTER TABLE TABLE_NAME RENAME TO NEW_TABLE_NAME;
示例
CREATE TABLE unisql_rename_table_test(id int,name varchar(10));
-- 转换前Oracle SQL:
RENAME unisql_rename_table_test TO unisql_rename_table_test_new;
ALTER TABLE unisql_rename_table_test_new RENAME TO unisql_rename_table_test;
-- 转换后达梦 SQL:
ALTER TABLE unisql_rename_table_test RENAME TO unisql_rename_table_test_new
ALTER TABLE unisql_rename_table_test_new RENAME TO unisql_rename_table_test
3.2.5.6.6. 创建表
语法
CREATE [GLOBAL TEMPORARY] TABLE table_name
(table_definition_list) [partition_option] [on_commit_option]
CREATE [GLOBAL TEMPORARY] TABLE table_name
(table_definition_list) [partition_option] [AS] select;
table_definition_list:
table_definition [, table_definition ...]
table_definition:
column_definition
| INDEX [index_name] index_desc
| [CONSTRAINT [constraint_name]] [PRIMARY KEY|UNIQUE] (column_definition_list) [USING INDEX index_option_list]
| [CONSTRAINT [constraint_name]] FOREIGN KEY (column_name, column_name ...) references_clause constraint_state
| [CONSTRAINT [constraint_name]] CHECK(expression) constraint_state
column_definition_list:
column_definition [, column_definition ...]
column_definition:
column_name data_type
[VISIBLE|INVISIBLE]
{
[DEFAULT expression]
[NULL | NOT NULL]
[CONSTRAINT [constraint_name] [PRIMARY] KEY] [UNIQUE [KEY]]
[CONSTRAINT [constraint_name] CHECK(expression)]
[CONSTRAINT [constraint_name] references_clause]
|
[GENERATED ALWAYS] AS (expression) [VIRTUAL]
[NULL | NOT NULL] [UNIQUE KEY] [[PRIMARY] KEY] [UNIQUE LOWER_KEY] [COMMENT string]
}
references_clause:
REFERENCES table_name [ (column_name, column_name ...) ] [ON DELETE {CASCADE}]
index_desc:
(column_desc_list) [index_option_list]
column_desc_list:
column_desc [, column_desc ...]
column_desc:
column_name [ASC | DESC][NULL LAST | NULL FIRST]
partition_option:
PARTITION BY HASH(column_name_list)
[subpartition_option] hash_partition_define
| PARTITION BY RANGE (column_name_list)
[subpartition_option] (range_partition_list)
| PARTITION BY LIST (column_name_list)
[subpartition_option] (list_partition_list)
on_commit_option:
ON COMMIT DELETE ROWS
| ON COMMIT PRESERVE ROWS
DEFAULT expression 可支持使用部分函数、关键字函数、字符串、常数、序列、字符串连接符。
示例
-- 转换前Oracle SQL:
CREATE TABLE kvt_ddl_1 (a NUMBER NULL, b NUMBER(5,2) NOT NULL, c NUMBER(4) DEFAULT 1 NOT NULL);
CREATE TABLE kvt_ddl_2 (id NUMBER(18) PRIMARY KEY, a FLOAT NOT NULL, b BINARY_FLOAT);
CREATE TABLE kvt_ddl_3 (id int CONSTRAINT cn_id PRIMARY key, a varchar(20) CONSTRAINT cn_a NOT NULL ,b NUMBER,c varchar(10),CONSTRAINT cn_b UNIQUE(b));
CREATE TABLE kvt_ddl_4 (id int, a varchar(20) CONSTRAINT cn4_a NOT null ,b NUMBER,c varchar(10),CONSTRAINT cn4_id PRIMARY KEY(id), CONSTRAINT cn4_b UNIQUE(b));
CREATE TABLE kvt_ddl_5 (id int, f_id int,CONSTRAINT f_id_fk FOREIGN KEY(f_id) REFERENCES kvt_ddl_3(id) );
CREATE TABLE kvt_ddl_6(id int,a int,b int CHECK(b>10),c varchar(10) CONSTRAINT cn6_c CHECK(c IN ('a','b','d')),CONSTRAINT cn6_a CHECK(a<100));
CREATE GLOBAL TEMPORARY TABLE kvt_ddl_7(id int,a int,b int);
-- 转换后达梦 SQL:
CREATE TABLE kvt_ddl_1 (a number NULL,b number(5,2) NOT NULL,c number(4) DEFAULT 1 NOT NULL);
CREATE TABLE kvt_ddl_2 (id number(18) PRIMARY KEY,a float(126) NOT NULL,b binary_float);
CREATE TABLE kvt_ddl_3 (id int PRIMARY KEY,a varchar(20) NOT NULL,b number,c varchar(10),CONSTRAINT cn_b UNIQUE(b));
CREATE TABLE kvt_ddl_4 (id int,a varchar(20) NOT NULL,b number,c varchar(10),CONSTRAINT cn4_id PRIMARY KEY(id),CONSTRAINT cn4_b UNIQUE(b));
CREATE TABLE kvt_ddl_5 (id int, f_id int,CONSTRAINT f_id_fk FOREIGN KEY(f_id) REFERENCES kvt_ddl_3(id) );
CREATE TABLE kvt_ddl_6(id int,a int,b int CHECK(b>10),c varchar(10) CONSTRAINT cn6_c CHECK(c IN ('a','b','d')),CONSTRAINT cn6_a CHECK(a<100));
CREATE GLOBAL TEMPORARY TABLE kvt_ddl_7(id int,a int,b int);
CREATE SEQUENCE unisql_default_expr_seq
-- 转换前Oracle SQL:
CREATE TABLE unisql_default_expr_table (
col_not_null VARCHAR2 ( 1 ) DEFAULT 1 NOT NULL,
col_current_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
col_current_localstamp DATE DEFAULT LOCALTIMESTAMP,
col_sysdate DATE DEFAULT SYSDATE,
col_systimestamp DATE DEFAULT SYSTIMESTAMP,
col_name VARCHAR2(50) DEFAULT 'John Doe',
col_to_date DATE DEFAULT TO_DATE('2000-01-01', 'YYYY-MM-DD'),
col_nextval NUMBER DEFAULT unisql_default_expr_seq.NEXTVAL,
col_currval NUMBER DEFAULT unisql_default_expr_seq.CURRVAL
)
-- 转换后达梦 SQL:
CREATE TABLE unisql_default_expr_table (
col_not_null varchar2(1) DEFAULT 1 NOT NULL,
col_current_timestamp timestamp DEFAULT CURRENT_TIMESTAMP(),
col_current_localstamp date DEFAULT CURRENT_TIMESTAMP(),
col_sysdate date DEFAULT SYSDATE(),
col_systimestamp date DEFAULT SYSTIMESTAMP(),
col_name varchar2(50) DEFAULT 'John Doe',
col_to_date date DEFAULT TO_DATE('2000-01-01', 'YYYY-MM-DD'),
col_nextval number DEFAULT unisql_default_expr_seq.NEXTVAL,
col_currval number DEFAULT unisql_default_expr_seq.CURRVAL
)
3.2.5.6.7. 创建视图
语法
CREATE [OR REPLACE] [[NO] FORCE] VIEW view_name [(column_name_list)] AS select_stmt;
column_name_list:
column_name [, column_name ...]
- 描述
- 该语句用于创建视图语句,如果指定了 OR REPLACE 子句,该语句能够替换已有的视图
示例
-- 创建表
CREATE TABLE unisql_view_test(a int,b int,c varchar(10));
-- 创建视图示例
-- 转换前Oracle SQL:
CREATE VIEW unisql_view_1 AS SELECT * FROM unisql_view_test;
CREATE VIEW unisql_view_2 AS SELECT a,b FROM unisql_view_test;
CREATE VIEW public.unisql_view_3 AS SELECT a,b FROM unisql_view_test;
CREATE VIEW unisql_view_4 AS SELECT a,b FROM unisql_view_test;
CREATE VIEW unisql_view_5 AS SELECT ' ' a, ' ' b FROM dual;
CREATE VIEW unisql_view_6 AS SELECT 1 a, 2 b FROM dual;
CREATE OR REPLACE VIEW unisql_view_7 AS SELECT 1 a, 2 b FROM dual;
CREATE OR REPLACE VIEW unisql_view_8 AS SELECT 1 a, 2 b, '3' c FROM dual;
CREATE FORCE VIEW unisql_view_9 AS SELECT 1 a, 2 b, '3' c FROM dual;
CREATE NOFORCE VIEW unisql_view_10 AS SELECT 1 a, 2 b, '3' c FROM dual;
CREATE VIEW unisql_view_11(a1,b1) AS SELECT a,b FROM unisql_view_test;
-- 转换后LightDB-Oracle SQL:
CREATE VIEW unisql_view_1 AS SELECT * FROM unisql_view_test
CREATE VIEW unisql_view_2 AS SELECT a,b FROM unisql_view_test
CREATE VIEW public.unisql_view_3 AS SELECT a,b FROM unisql_view_test
CREATE VIEW unisql_view_4 AS SELECT a,b FROM unisql_view_test
CREATE VIEW unisql_view_5 AS SELECT ' ' AS a,' ' AS b FROM dual
CREATE VIEW unisql_view_6 AS SELECT 1 AS a,2 AS b FROM dual
CREATE OR REPLACE VIEW unisql_view_7 AS SELECT 1 AS a,2 AS b FROM dual
CREATE OR REPLACE VIEW unisql_view_8 AS SELECT 1 AS a,2 AS b,'3' AS c FROM dual
CREATE VIEW unisql_view_9 AS SELECT 1 AS a,2 AS b,'3' AS c FROM dual
CREATE VIEW unisql_view_10 AS SELECT 1 AS a,2 AS b,'3' AS c FROM dual
CREATE VIEW unisql_view_11 (a1,b1) AS SELECT a,b FROM unisql_view_test
3.2.5.6.8. 删除视图
语法
DROP VIEW [schema.] view_name [CASCADE CONSTRAINTS];
- 描述
- 该语句用于删除视图语句,该视图必须在您自己的 Schema 中,或者您必须有 DROP ANY VIEW 权限。
示例
-- 创建表
CREATE TABLE unisql_view_employees_test (
employee_id NUMBER PRIMARY KEY,
first_name VARCHAR2(50),
last_name VARCHAR2(50),
salary NUMBER
);
-- 创建视图
CREATE VIEW unisql_view_employee_names_salaries AS
SELECT first_name, salary
FROM unisql_view_employees_test;
-- 删除视图
-- 转换前Oracle SQL:
DROP VIEW unisql_view_employee_names_salaries;
-- 转换后LightDB-Oracle SQL:
DROP VIEW unisql_view_employee_names_salaries
3.2.5.6.9. 创建序列
语法
CREATE SEQUENCE [ schema. ] sequence_name
{ START WITH int_value
|[ INCREMENT BY int_value ]
|[ MINVALUE int_value | NOMINVALUE ]
|[ MAXVALUE int_value | NOMAXVALUE ]
|[ CACHE int_value | NOCACHE ]
|[ ORDER | NOORDER ]
|[ CYCLE | NOCYCLE ]
}
;
- 描述
- 该语句用来创建序列。序列属于数据库对象,用户可以从序列中生成唯一整数。
参数解释
字段 |
描述 |
---|---|
schema. |
指定包含序列的 Schema。如果省略 Schema,则数据库会在用户当前所在的 Schema 中创建序列。 |
sequence_name |
要创建的序列名称。 |
MINVALUE int_value |
指定序列的最小值,int_value 的取值范围是 [-9223372036854775808,9223372036854775807]。 |
NOMINVALUE |
NOMINVALUE 为默认值。 如果指定为 NOMINVALUE,则升序时最小值为 1,降序时最小值为 -9223372036854775808。 |
MAXVALUE int_value |
指定序列的最大值,int_value 的取值范围是 [-9223372036854775808,9223372036854775807]。注意:同时指定 MINVALUE 和 MAXVALUE 时,MINVALUE 必须小于 MAXVALUE。MAXVALUE 和 MINVALUE 之差必须大于等于 INCREMENT BY 中 的 int_value。 |
NOMAXVALUE |
NOMAXVALUE 为默认值。 如果指定为 NOMAXVALUE,则升序时最大值为9223372036854775807,降序时最大值为 -1。 |
START WITH int_value |
指定序列的起始值。int_value 必须小于等于 MAXVALUE,且大于等于 MINVALUE。 如果不指定,则升序时默认取值为最小值,降序时默认取值为最大值。 |
INCREMENT BY int_value |
指定序列的自增步数。int_value 不可以为 0。 如果指定为正数,则序列为升序;如果指定为负数,则序列为降序。 不指定时缺省值为 1。 |
CACHE int_value |
指定在内存中预分配的自增值个数,int_value 默认为 20。CACHE int_value 的值必须大于 1,如果 CACHE INT_VALUE 的值为 1,则等价于 NOCACHE。 |
NOCACHE |
指定序列的值为未预先分配。 如果同时省略 CACHE 和 NOCACHE,则数据库默认缓存 20 个序列号。 |
ORDER |
指定序列的值按顺序生成。 |
NOORDER |
NOORDER 为默认值,即不保证序列的值按顺序生成。 |
CYCLE |
指定序列的值循环生成,即序列在达到其最大值或最小值后继续生成值。在升序达到最大值后,它会生成最小值。在降序序列达到其最小值后,它会生成其最大值。注意: 如果指定了 CYCLE,而且 INCREMENT BY int_value 小于 0 时,必须指定 MINVALUE。如果指定了 CYCLE,CACHE 的数量不能超过一个 CYCLE。 |
NOCYCLE |
NOCYCLE 为默认值,指定序列在达到其最大值或最小值后无法生成更多值。 |
示例
-- 创建序列示例
-- 转换前Oracle SQL:
CREATE SEQUENCE SE_NAME MAXVALUE 100000 CYCLE;
CREATE SEQUENCE SE_NAME_1 NOCYCLE;
CREATE SEQUENCE SE_NAME_2 CACHE 20;
CREATE SEQUENCE SE_NAME_3 START WITH 1 NOCACHE;
CREATE SEQUENCE SE_NAME_4 START WITH 1 ORDER;
CREATE SEQUENCE SE_NAME_5 START WITH 1 NOORDER;
CREATE SEQUENCE SE_NAME_6 START WITH 1 KEEP;
CREATE SEQUENCE SE_NAME_7 NOKEEP START WITH 1;
CREATE SEQUENCE SE_NAME_8 NOMINVALUE MAXVALUE 9223372036854775808;
CREATE SEQUENCE SE_NAME_9 MAXVALUE 9223372036854775806;
CREATE SEQUENCE SE_NAME_10 MINVALUE -9223372036854775808 NOMAXVALUE;
CREATE SEQUENCE SE_NAME_11 MINVALUE -9223372036854775809;
CREATE SEQUENCE SE_NAME_12 MINVALUE -9999999999999999999999999999;
CREATE SEQUENCE SE_NAME_13 INCREMENT BY 9223372036854775808;
CREATE SEQUENCE SE_NAME_14 INCREMENT BY -9223372036854775809;
CREATE SEQUENCE SE_NAME_15 MINVALUE -9999999999999999999999999999;
CREATE SEQUENCE SE_NAME_16 INCREMENT BY 9223372036854775808;
CREATE SEQUENCE SE_NAME_17 INCREMENT BY -9223372036854775809;
CREATE SEQUENCE SE_NAME_18 START WITH 9223372036854775808;
-- 转换后达梦 SQL:
CREATE SEQUENCE SE_NAME MAXVALUE 100000 CYCLE;
CREATE SEQUENCE SE_NAME_1 NOCYCLE;
CREATE SEQUENCE SE_NAME_2 CACHE 20;
CREATE SEQUENCE SE_NAME_3 START WITH 1 NOCACHE;
CREATE SEQUENCE SE_NAME_4 START WITH 1 ORDER;
CREATE SEQUENCE SE_NAME_5 START WITH 1 NOORDER;
CREATE SEQUENCE SE_NAME_6 START WITH 1 KEEP; --不支持
CREATE SEQUENCE SE_NAME_7 NOKEEP START WITH 1; --不支持
CREATE SEQUENCE SE_NAME_8 NOMINVALUE MAXVALUE 9223372036854775808;
CREATE SEQUENCE SE_NAME_9 MAXVALUE 9223372036854775806;
CREATE SEQUENCE SE_NAME_10 MINVALUE -9223372036854775808 NOMAXVALUE;
CREATE SEQUENCE SE_NAME_11 MINVALUE -9223372036854775809;
CREATE SEQUENCE SE_NAME_12 MINVALUE -9999999999999999999999999999;
CREATE SEQUENCE SE_NAME_13 INCREMENT BY 9223372036854775808; --不支持
CREATE SEQUENCE SE_NAME_14 INCREMENT BY -9223372036854775809; --不支持
CREATE SEQUENCE SE_NAME_15 MINVALUE -9999999999999999999999999999;
CREATE SEQUENCE SE_NAME_16 INCREMENT BY 9223372036854775808; --不支持
CREATE SEQUENCE SE_NAME_17 INCREMENT BY -9223372036854775809; --不支持
CREATE SEQUENCE SE_NAME_18 START WITH 9223372036854775808;
3.2.5.6.10. 同义词
- 描述
- 同义词 (Synonym)是 Oracle 租户中表、视图、物化视图、序列、存储过程、函数、包、类型、用户自定义类型,或是其他的同义词的别名。由于其只是一个别名,所以除了在数据字典中的定义不占任何空间。本文主要介绍同义词的分类、基本特性和权限要求。
- 分类
同义词有两种类型,Public 同义词和 Private 同义词。
Public 同义词属于 PUBLIC 组,每个用户都可以访问。Private 同义词属于对象所有者,只有其显式授权后其他用户才可访问。
公有同义词一般由 DBA 创建,普通用户如果希望创建公有同义词,则需要 CREATE PUBLIC SYNONYM 系统权限。
- 基本特性
- 同义词扩展了数据库的使用范围,能够在不同的数据库用户之间实现无缝交互。经常用于简化对象访问和提高对象访问的安全性。
3.2.5.6.10.1. 创建同义词
语法
CREATE [ OR REPLACE ] [ EDITIONABLE | NONEDITIONABLE ]
[ PUBLIC ] SYNONYM
[ schema. ] synonym
[ SHARING = { METADATA | NONE } ]
FOR [ schema. ] object [ @ dblink ] ;
备注
[ EDITIONABLE | NONEDITIONABLE ]和[ SHARING = { METADATA | NONE } ] 在达梦中将被作为语法糖处理,[ @ dblink ]暂不支持!
参数解释
参数 |
说明 |
---|---|
OR REPLACE |
表示如果要创建的同义词名称已存在,则使用新的定义替换同义词。 |
EDITIONABLE/NONEDITIONABLE |
如果在模式中为模式对象类型SYNONYM启用了编辑,请使用这些子句来指定同义词是已编辑对象还是非版本对象。对于私人同义词,默认是EDITABLE。对于公共同义词,默认值为NONEDITIONAL。 |
PUBLIC |
指定 PUBLIC 来创建公共同义词,所有用户都可以使用。用户必须对基础对象具有相应的权限才能使用该同义词。 在解析对象的引用时,仅当对象没有指定 Schema 时,才会使用公共同义词。 如果不指定 PUBLIC,则同义词是私有的,只能由当前 Schema 访问,并且同义词名称在当前 Schema 中必须唯一。 |
[schema. ]synonym |
Schema 指定当前同义词属于哪个用户。如果指定了 PUBLIC,则对同义词不能指定用户。 synonym 表示同义词的名称。 |
[ SHARING = { METADATA/NONE } ] |
此子句仅在应用程序根目录中创建同义词时适用。这种类型的同义词称为应用程序公共对象,它可以与属于应用程序根的应用程序 PDB 共享。要确定同义词的共享方式,请指定以下共享属性之一:METADATA - 元数据链接共享同义词的元数据,但其数据对于每个容器都是唯一的。这种类型的同义词被称为元数据链接的应用程序公共对象。NONE - 不共享同义词。如果省略此子句,则数据库将使用 DEFAULT_SHARING 初始化参数的值来确定同义词的共享属性。如果 DEFAULT_SHARING 初始化参数没有值,则默认值为 METADATA。 |
[schema. ]object |
表示同义词对应对象的名称。 |
[ @ dblink ] |
暂不支持 |
示例
-- 转换前Oracle SQL:
CREATE OR REPLACE EDITIONABLE SYNONYM employee SHARING = METADATA FOR user2.emp;
-- 转换后达梦 SQL:
CREATE OR REPLACE SYNONYM employee FOR user2.emp;
3.2.5.6.10.2. 删除同义词
语法
DROP [PUBLIC] SYNONYM [ schema. ] synonym [FORCE] ;
备注
[FORCE] 在达梦中将被作为语法糖处理!
参数解释
参数 |
说明 |
---|---|
PUBLIC |
指定 PUBLIC 来删除公共同义词。如果不指定 PUBLIC,则删除私有同义词。 |
[schema. ]synonym |
Schema 指定当前同义词属于哪个用户。如果指定了 PUBLIC,则对同义词不能指定用户。 synonym 表示同义词的名称。 |
FORCE |
指定 FORCE 来删除同义词,即使它具有依赖表或用户定义类型。 |
示例
-- 转换前Oracle SQL:
DROP PUBLIC SYNONYM user1.employee FORCE;
-- 转换后达梦 SQL:
DROP PUBLIC SYNONYM user1.employee;