达梦数据库小技巧
- 一: 时间类型TIMESTAMP使用
- 1.1 建表
- 1.2 插入
- 1.3按时间戳查询,返回某一列不重复的值
- 二:存储过程创建和调用
- 2.1建表
- 2.2 创建存储过程,循环100插入拼接字符串
- 2.3调用存储过程
一: 时间类型TIMESTAMP使用
1.1 建表
CREATE TABLE "TEST"."TIMESTAMP_T"
(
"ID" INT IDENTITY(1, 1) NOT NULL,
"NUM" INT,
"REV_TIME" TIMESTAMP(6),
CLUSTER PRIMARY KEY("ID")) STORAGE(ON "MAIN", CLUSTERBTR) ;
1.2 插入
insert TEST.TIMESTAMP_T(NUM,REV_TIME) values
(3,FROM_UNIXTIME(1707034197,'YYYY-MM-DD HH24:MI:SS')),
(3,FROM_UNIXTIME(1707034197,'YYYY-MM-DD HH24:MI:SS')),
(4,FROM_UNIXTIME(1720080515,'YYYY-MM-DD HH24:MI:SS'));
COMMIT;
1.3按时间戳查询,返回某一列不重复的值
SELECT DISTINCT NUM
FROM TEST.TIMESTAMP_T
WHERE UNIX_TIMESTAMP(REV_TIME) < 1720080515;
二:存储过程创建和调用
2.1建表
CREATE TABLE "TEST"."PROCEDURE_T"
(
"ID" INT IDENTITY(1, 1) NOT NULL,
"INFO" VARCHAR(255) NOT NULL,
CLUSTER PRIMARY KEY("ID")) STORAGE(ON "MAIN", CLUSTERBTR) ;
2.2 创建存储过程,循环100插入拼接字符串
CREATE OR REPLACE PROCEDURE TEST.CREATE_UUID() AS
a INT:=0;
BEGIN
LOOP
a:=a+1;
IF a>=100 THEN
EXIT;
END IF;
INSERT INTO TEST.PROCEDURE_T (INFO)
VALUES (CONCAT('CAEFEFEFEFEFEFEFEFEFEFEFEFE', LPAD(CAST(a AS VARCHAR2(5)), 5, '0')));
END LOOP;
COMMIT;
END;
2.3调用存储过程
CALL TEST.CREATE_UUID();