From 2674a0cda2ba3c8703a31d84b1b7fe96be373351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Fri, 25 Apr 2025 18:01:05 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E8=B0=83=E6=95=B4sql=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/sql/oracle/oracle_ry_cloud.sql | 23 +++++++++++------------ script/sql/postgres/postgres_ry_cloud.sql | 17 ++++++++--------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/script/sql/oracle/oracle_ry_cloud.sql b/script/sql/oracle/oracle_ry_cloud.sql index d47ceaf4..f1f233a9 100644 --- a/script/sql/oracle/oracle_ry_cloud.sql +++ b/script/sql/oracle/oracle_ry_cloud.sql @@ -1405,18 +1405,6 @@ insert into test_tree values (11, '000000', 7, 108, 3, '子节点77', 0, 103, sy insert into test_tree values (12, '000000', 10, 108, 3, '子节点88', 0, 103, sysdate, 1, null, null, 0); insert into test_tree values (13, '000000', 10, 108, 3, '子节点99', 0, 103, sysdate, 1, null, null, 0); - --- ---------------------------- --- 钩子 ,用于session连接之后 自动设置默认的date类型格式化 简化时间查询 --- 如需设置其它配置 可在此钩子内任意增加处理语句 --- 例如: SELECT * FROM sys_user WHERE create_time BETWEEN '2022-03-01 00:00:00' AND '2022-04-01 00:00:00' --- ---------------------------- -create or replace trigger login_trg -after logon on database -begin -execute immediate 'alter session set nls_date_format=''YYYY-MM-DD HH24:MI:SS'''; -end; - -- for AT mode you must to init this sql for you business database. the seata server not need it. CREATE TABLE undo_log ( @@ -1443,3 +1431,14 @@ COMMENT ON COLUMN undo_log.log_modified is 'modify datetime'; -- Generate ID using sequence and trigger CREATE SEQUENCE UNDO_LOG_SEQ START WITH 1 INCREMENT BY 1; + +-- ---------------------------- +-- 钩子 ,用于session连接之后 自动设置默认的date类型格式化 简化时间查询 +-- 如需设置其它配置 可在此钩子内任意增加处理语句 +-- 例如: SELECT * FROM sys_user WHERE create_time BETWEEN '2022-03-01 00:00:00' AND '2022-04-01 00:00:00' +-- ---------------------------- +create or replace trigger login_trg +after logon on database +begin +execute immediate 'alter session set nls_date_format=''YYYY-MM-DD HH24:MI:SS'''; +end; diff --git a/script/sql/postgres/postgres_ry_cloud.sql b/script/sql/postgres/postgres_ry_cloud.sql index 04e2ba40..3999b0e1 100644 --- a/script/sql/postgres/postgres_ry_cloud.sql +++ b/script/sql/postgres/postgres_ry_cloud.sql @@ -1398,15 +1398,6 @@ insert into test_tree values (11, '000000', 7, 108, 3, '子节点77', 0, 103, no insert into test_tree values (12, '000000', 10, 108, 3, '子节点88', 0, 103, now(), 1, NULL, NULL, 0); insert into test_tree values (13, '000000', 10, 108, 3, '子节点99', 0, 103, now(), 1, NULL, NULL, 0); - --- 字符串自动转时间 避免框架时间查询报错问题 -create or replace function cast_varchar_to_timestamp(varchar) returns timestamptz as $$ -select to_timestamp($1, 'yyyy-mm-dd hh24:mi:ss'); -$$ language sql strict ; - -create cast (varchar as timestamptz) with function cast_varchar_to_timestamp as IMPLICIT; - - -- for AT mode you must to init this sql for you business database. the seata server not need it. CREATE TABLE IF NOT EXISTS public.undo_log ( @@ -1433,3 +1424,11 @@ COMMENT ON COLUMN public.undo_log.log_created IS 'create datetime'; COMMENT ON COLUMN public.undo_log.log_modified IS 'modify datetime'; CREATE SEQUENCE IF NOT EXISTS undo_log_id_seq INCREMENT BY 1 MINVALUE 1 ; + + +-- 字符串自动转时间 避免框架时间查询报错问题 +create or replace function cast_varchar_to_timestamp(varchar) returns timestamptz as $$ +select to_timestamp($1, 'yyyy-mm-dd hh24:mi:ss'); +$$ language sql strict ; + +create cast (varchar as timestamptz) with function cast_varchar_to_timestamp as IMPLICIT;