GBase 8s触发存储过程示例

GBase 8s的触发器不支持raise exception,条件判断等存储过程中可以使用的功能,若有需求,可以使用触发存储过程的功能。
以下以insert触发器为示例,创建触发存储过程:
1,创建相应的表

create table tab1
  (
    id integer,
    name varchar(40),
    primary key (id)
  ) ;

create table tab2
  (
    id integer,
    name varchar(40),
    uptime datetime year to second
        default current year to second
  ) ;



阅读全文»

GBase 8s使用内部用户

GBase 8s支持内部用户,但默认情况下并不是开启的,需要手工开启。
以下以GBase 8s v8.8_2.0.1a2_2版本为例示范如何使用内部用户(mapping user)

1,配置allowed.surrogates
在/etc/gbasedbt(如没有,使用root用户创建)下创建allowed.surrogates配置文件,内容如下:

USERS:daemon



阅读全文»

在java中调用GBase 8s的函数示例

测试在java程序中调用GBase 8s的函数调用。

1, OUT及RETURN返回值

1)、首先创建需要调用的函数或者存储过程

-- out value 是 out变量值
-- return value 是函数返回值
create function myfunc2(f1 int,out f2 varchar(128)) returns varchar(128);
  let f2 = "out value: myfunc2";
  return "return value: myfunc2  and  f1: " || f1;
end function;

2)、java程序调用函数myfunc2示例

阅读全文»

GBase 8s使用unix_timestamp()函数

从mysql迁移到GBase 8s数据库时,原有unix_timestamp()函数在GBase 8s中不可用,因此需要自己创建相应的函数,可以使用C或者JAVA创建自定义例程,也可以使用存储过程或者函数。以下以存储过程/函数方式创建。
注:以下语法根据GBase 8s v8.7 2.0.1a2_2版本进行过更新。


阅读全文»

GBase 8s 存储过程跟踪示例

TRACE语句用于调试存储过程, 它可以跟踪以下存储过程实体的值:
变量(Variables)
过程参数(Procedure arguments)
返回值(Return values)
SQL 错误代码(SQL error codes)
ISAM 错误代码(ISAM error codes)
TRACE 语句把跟踪结果写到一个文件中, 该文件由SQL语句SET DEBUG FILE指定







阅读全文»

GBase 8s回收public权限

默认的情况下,数据库中public(具有库级connect权限的用户自动获取public权限)具有insert,delete,update,select,index权限。若只允许public用户只有select权限,则需要回收权限。

阅读全文»

GBase 8s 自定义split_part函数

GBase 8s 默认无split_part函数,但可以通过substring_index()函数来达到split_part的功能,具体如下:
该函数的功能:以第二个参数separator_in分隔第一个参数str_in,返回第三个参数field_in指定字段。


阅读全文»

GBase 8s数据库存储过程使用出参示例

GBase 8s数据库的存储过程支持入参,出参 out ,入出参 inout。
以下以示例说明存储过程的入参,出参,以及使用存储过程调用出参的过程及方法。

1, 创建存储过程 入参、出参。

drop procedure if exists p3;
create procedure p3(v1 int, out v2 varchar(20))
  let v1 = 101;
  let v2 = "P3 out parm value";
end procedure;


阅读全文»