kingbase人大金仓常用sql命令自用)
kingbase人大金仓常用sql命令(自用总结)
开发过程中使用到的
平时用mysql数据库,第一次用人大金仓数据库,有一些地方还是有区别,记录一下。
- –修改字段数据类型
–ALTER TABLE 表名 MODIFY 字段名 数据类型
ALTER TABLE sys_notice MODIFY scope varchar(500)
ALTER TABLE sys_dict_data MODIFY remark varchar(800)
- –查字段备注
select comments from user_col_comments where table_name='sys_notice' and column_name='scope';
- –给表加注释
comment on table sys_notice is '通知公告表';
- –给字段加备注
comment on column sys_notice.scope is '发布范围';
- #表已经创建之后 想要修改主键自增开始数字
#步骤1: 首先创建一个序列 然后把序列给id
–序列号的起始值(START WITH)、最小值(MINVALUE)、最大值(MAXVALUE) 序列值之间的递增幅度(INCREMENT BY),其中NOCYCLE选项表示序列在达到最大值或最小值后不会生成更多值。如果希望序列号可以循环使用,请使用CYCLE选项。CACHE子句预先分配100个序列号保存在内存中。用户每使用一次序列,都需要对序列进行一次查询,当保存在内存中可以大大加快获取序列号,当缓存中的最后一个序列号被使用时,数据库将向缓存读入另一组序列号。
创建序列sql 1
CREATE SEQUENCE sp_menu_menu_ids_seq
INCREMENT BY 1
START WITH 1046
MINVALUE 1046
MAXVALUE 9999
CACHE 100
NOCYCLE;
创建序列sql 2
还可以简单一点:
创建一个序列sp_config_config_ids_seq,从10开始自增,默认为正增长,增长量为1
CREATE SEQUENCE 序列名称 START 10;
步骤2: 然后把序列给id
ALTER TABLE 表名 ALTER COLUMN 字段名 SET DEFAULT NEXTVAL(‘序列名’::REGCLASS);
alter table sp_menu alter column menu_id set default nextval('sp_menu_menu_ids_seq'::REGCLASS)
- **# 获取当前时间 **
select now();
SELECT TO_CHAR(now() ,'yyyy-MM-dd HH:mm:ss');
#当前年月日
SELECT TO_CHAR(now() ,'yyyy-MM-dd')
# 时间戳
select current_timestamp;
# 日期
select current_date;
# 时间
select current_time;
- # 时间计算
select now() - interval '30D';
select now() interval '2 years';
select now() - interval '1 Months';
select now() - interval '120 Minutes';
select timestampdiff('minute','2018-07-01 09:00:00','2018-07-04 12:00:00')
10.# 时间间隔
age
select age(timestamp '2023-01-27');
# 时间截取
extract
select extract(doy from now());
# 注意是 day of year 的简写
select extract(week from now());
select extract(month from now());
# 部分简写以及含义
Y Years
M Months (in the date part)
W Weeks
D Days
H Hours
M Minutes (in the time part)
S Seconds
- #计算时间差
select timestampdiff('minute','2023-04-17 10:00:00',now())
select timestampdiff('day','2023-04-10 10:00:00',now())
select timestampdiff('month','2023-03-10 10:00:00',now())
select timestampdiff('year','2012-03-10 10:00:00',now())
需要计算两个日期之间相差的时间,人大金仓不支持TimeStampDiff 函数,需要我们自己在数据库创建TimeStampDiff 函数。要注意:在金仓中minute 这个要加单引号并且要小写,这个是当参数传进来的。
create or replace function timestampdiff(para1 text,para2 timestamp,para3 timestamp) return bigint
as
declare
diff interval day to second;
diffs bigint;
diffm bigint;
diffh bigint;
diffd bigint;
nyy bigint;
ny bigint;
nm bigint;
begin
diff:=para3-para2;
diffs:=extract(second from diff);
diffm:=extract(minute from diff);
diffh:=extract(hour from diff);
diffd:=extract(day from diff);
ny:=extract(year from age(para3,para2));
nm:=extract(month from age(para3,para2));
nyy:=extract(year from para3)-extract(year from para2);
if para1='second' then
return ((diffd*24 diffh)*60 diffm)*60 diffs;
elseif para1='minute' then
return (diffd*24 diffh)*60 diffm;
elseif para1='hour' then
return diffd*24 diffh;
elseif para1='day' then
return diffd;
elseif para1='month' then
return ny*12 nm;
elseif para1='year' then
return nyy;
else
raise warning 'para1 not support "%"!',para1;
return null;
end if;
end;
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhfjcffk
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
photoshop蒙版画笔没反应怎么办
PHP中文网 06-24