oracle to_date函数的实现

最近更新时间: 2024-06-12 15:06:00

TDSQL PG可以使用to_timestamp函数代替,如果应用程序中已经大量的使用的oracle to_date函数并且是精细到时:分:秒,那我们可以自定义一个to_date函数存放到一个优先访问的schema中,函数的内容为to_timestamp,这样就可以兼容原来的oracle应用了,如下所示:

postgres=# create schema oracle;
CREATE SCHEMA
postgres=# CREATE OR REPLACE FUNCTION oracle.to_date(a_date text,a_style text ) RETURNS timestamp with time zone AS
postgres-# $$
postgres$# BEGIN
postgres$#     RETURN to_timestamp(a_date,a_style);
postgres$# END;
postgres$# $$  
postgres-# LANGUAGE PLPGSQL;
CREATE FUNCTION
postgres=# set search_path = oracle ,"$user", public,pg_catalog;;
SET
postgres=# select to_date('2028-01-01 13:14:20','yyyy-MM-dd HH24:MI');      
        to_date         
------------------------
 2028-01-01 13:14:00+08
(1 row)