GBase 8s 数据库问题知识库(2020-06-17更新)

1, 删除表记录时,报“692: Key value for constraint ( 主键约束名称 ) is still being referenced.”

解析:
1,报错信息明显的提示,删除的记录被外键引用了,故不能删除;
2,如果需要删除该记录,应当先删除外键所在表的该值所有记录,以下语句可获取外键参考所在的表的名称:

select t.tabname 
from sysconstraints c, systables t, sysreferences r
where c.tabid = t.tabid 
and   c.constrid = r.constrid
and   c.constrtype = 'R'
and   r.ptabid = (select tabid from systables where tabname = '主键表名');

3,使用外键时,我们有时还会用到 级联删除(ON DELETE CASCADE) 功能,使用该功能:删除主表记录时,外键参考表相应的记录均删除。示例:

create table dept (
  dept_id serial, 
  dept_name varchar(60) not null, 
  manager_id int, 
  primary key(dept_id) constraint pk_dept_dept_id
);

create table emp (
  emp_id serial, 
  dept_id int, 
  foreign key (dept_id) references dept(dept_id) on delete cascade constraint fk_emp_dept_id
);

2,基于java的环境中,使用byte字段类型时,服务器上会产生IfxTmpFile_xxxxxxxxxxxxxx的文件。

解析:
该问题产生的原因是受到了JDBC的环境变量参数LOBCACHE的影响(如果未指定,使用缺省默认值4096)。
LOBCACHE参数确定从数据库服务器访存的大对象数据的缓冲区大小。大于 0 的数值时:
在内存中分配来保存数据的最大字节数。如果数据大小超过 LOBCACHE 值,则将数据存储在临时文件中;如果在创建此文件期间发生安全违规,则将数据存储在内存中;为零时:始终将数据存储在文件中。如果发生安全违规,则驱动程序不尝试在内存中存储数据。为负数时:始终将数据存储在内存中。如果得不到所需的内存量,则发生错误。
根据实际需要调整该参数即可。

3,使用nvl2或者decode或者case时,报“800: Corresponding data types must be compatible in CASE expression or DECODE function.”错误。

解析:
800错误表示case或者decode的各个条件返回值需要一致或者是兼容的。
如下,col2为datetime year to second类型,两个条件的返回值:col2 + 1为datetime year to second,而to_date的返回值的类型是datetime year to fraction(5)。系统严格的认为两个并不一致,故而报800错误。

nvl2(col2, col1 + 1, to_date('2020-05-26 00:00:00','yyyy-mm-dd hh24:mi:ss'))

需将某改为一致:

nvl2(col2, 
to_date(to_char(col2 + 1,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss'), 
to_date('2020-05-26 00:00:00','yyyy-mm-dd hh24:mi:ss'))
-- 或者使用强制转换
nvl2(col2, 
col1 + 1, 
to_date('2020-05-26 00:00:00','yyyy-mm-dd hh24:mi:ss')::datetime year to second)
-- 注: '::'表示转换后的类型

4,insert into … select skip … first 报-201语法错误

语句如下:

insert into t1 (col1)
select col1 from t2 order by col1 desc skip 0 first 5;

单独执行select能正常执行,但整个语句会报-201语法错误。
解析:
当前的数据库版本为了支持limit m,n语法,支持将skip m first n后置。但使用时还是尽量使用原始的写法。

insert into t1 (col1)
select skip 0 first 5 col1 from t2 order by col1 desc;

将skip紧接着select 关键字。

猜你喜欢

转载自blog.csdn.net/liaosnet/article/details/106200564
今日推荐