diff --git a/CN/modules/ROOT/nav.adoc b/CN/modules/ROOT/nav.adoc index dfa5534..75ca9af 100644 --- a/CN/modules/ROOT/nav.adoc +++ b/CN/modules/ROOT/nav.adoc @@ -30,6 +30,7 @@ **** xref:master/6.3.7.adoc[嵌套子函数] **** xref:master/6.3.8.adoc[Force View] **** xref:master/6.3.9.adoc[大小写转换] +**** xref:master/6.3.10.adoc[sys_guid 函数] *** xref:master/6.4.adoc[国标GB18030] *** 内置函数 **** xref:master/6.4.1.adoc[sys_context] @@ -55,6 +56,7 @@ *** xref:master/7.17.adoc[17、NLS 参数] *** xref:master/7.18.adoc[18、Force View] *** xref:master/7.19.adoc[19、嵌套子函数] +*** xref:master/7.20.adoc[20、sys_guid 函数] ** IvorySQL贡献指南 *** xref:master/8.1.adoc[社区贡献指南] *** xref:master/8.2.adoc[asciidoc语法快速参考] diff --git a/CN/modules/ROOT/pages/master/6.3.10.adoc b/CN/modules/ROOT/pages/master/6.3.10.adoc new file mode 100644 index 0000000..89d70b7 --- /dev/null +++ b/CN/modules/ROOT/pages/master/6.3.10.adoc @@ -0,0 +1,21 @@ +:sectnums: +:sectnumlevels: 5 + +:imagesdir: ./_images + += sys_guid() 函数 + +== 目的 + +IvorySQL的sys_guid() 是一个强大的随机数产生函数,它产生并返回一个由16个字节组成的数据库级别唯一的标识符(原始值)。 + +== 实现说明 + +IvorySQL的sys_guid()函数通过修改插件uuid-ossp的代码实现。为了充分利用uuid的多种基础库,采用如下逻辑: + +1. 如果系统有uuid-ossp,就使用uuid_make(); +2. 如果系统有uuid-e2fs,就使用 uuid_generate_random(); +3. 否则就调用 arc4random(); + +同时修改代码使得IvorySQL能够自动载入uuid-ossp插件。 + diff --git a/CN/modules/ROOT/pages/master/7.20.adoc b/CN/modules/ROOT/pages/master/7.20.adoc new file mode 100644 index 0000000..70e6380 --- /dev/null +++ b/CN/modules/ROOT/pages/master/7.20.adoc @@ -0,0 +1,36 @@ +:sectnums: +:sectnumlevels: 5 + +:imagesdir: ./_images + += sys_guid() 函数 + +== 目的 + +IvorySQL的sys_guid() 是一个强大的随机数产生函数,它产生并返回一个由16个字节组成的数据库级别唯一的标识符(原始值)。 + +== 使用示例 + +``` +highgo=# select sys_guid() from dual; + sys_guid +------------------------------------ + \x3ed9426c8a093442a38bea09a74f44a1 +(1 row) +``` + +== sys_guid函数在建表时可以作为主键 + +``` +create table student +( +student_id raw(16) default sys_guid() primary key, +student_name varchar2(100) not null +); +``` + +== 新增数据时自动填充主键 + +``` +insert into student(student_name) values ('Steven'); +``` diff --git a/EN/modules/ROOT/nav.adoc b/EN/modules/ROOT/nav.adoc index 7250cf2..92ebbd0 100644 --- a/EN/modules/ROOT/nav.adoc +++ b/EN/modules/ROOT/nav.adoc @@ -29,6 +29,7 @@ *** xref:master/6.3.7.adoc[Nested Subfunctions] *** xref:master/6.3.8.adoc[Force View] *** xref:master/6.3.9.adoc[Case Conversion] +*** xref:master/6.3.10.adoc[sys_guid Function] ** xref:master/6.4.adoc[GB18030 Character Set] ** Built-in Functions *** xref:master/6.4.1.adoc[sys_context] @@ -54,6 +55,7 @@ ** xref:master/7.17.adoc[17、NLS Parameters] ** xref:master/7.18.adoc[18、Force View] ** xref:master/7.19.adoc[19、Nested Subfunctions] +** xref:master/7.20.adoc[20、sys_guid Function] * xref:master/8.adoc[Community contribution] * xref:master/9.adoc[Tool Reference] * xref:master/10.adoc[FAQ] diff --git a/EN/modules/ROOT/pages/master/6.3.10.adoc b/EN/modules/ROOT/pages/master/6.3.10.adoc new file mode 100644 index 0000000..ff68a7b --- /dev/null +++ b/EN/modules/ROOT/pages/master/6.3.10.adoc @@ -0,0 +1,21 @@ +:sectnums: +:sectnumlevels: 5 + +:imagesdir: ./_images + += sys_guid() function + +== Purpose + +IvorySQL's sys_guid() is a powerful random number generation function that generates and returns a 16-byte database-level unique identifier (raw value). + +== Implementation Description + +The sys_guid() function of IvorySQL is implemented by modifying the code of the uuid-ossp plugin. To make full use of various underlying libraries of uuid, the following logic is adopted: + +1. If the uuid-ossp exists in the system, uuid_make() will be used; +2. If the uuid-e2fs exists in the system, uuid_generate_random() will be used; +3. Otherwise use arc4random(); + +Meanwhile modify the code so that IvorySQL can load uuid-ossp extension automatically. + diff --git a/EN/modules/ROOT/pages/master/7.20.adoc b/EN/modules/ROOT/pages/master/7.20.adoc new file mode 100644 index 0000000..37c67fb --- /dev/null +++ b/EN/modules/ROOT/pages/master/7.20.adoc @@ -0,0 +1,36 @@ +:sectnums: +:sectnumlevels: 5 + +:imagesdir: ./_images + += sys_guid() function + +== Purpose + +IvorySQL's sys_guid() is a powerful random number generation function that generates and returns a 16-byte database-level unique identifier (raw value). + +== Usage example + +``` +highgo=# select sys_guid() from dual; + sys_guid +------------------------------------ + \x3ed9426c8a093442a38bea09a74f44a1 +(1 row) +``` + +== The sys_guid function can generate default values for primary keys when creating a table + +``` +create table student +( +student_id raw(16) default sys_guid() primary key, +student_name varchar2(100) not null +); +``` + +== The primary key is automatically populated when new data is added + +``` +insert into student(student_name) values ('Steven'); +```