PostgreSQL 内核自带的Oracle兼容函数

简介:

标签

PostgreSQL , Oracle , 兼容函数 , Oracle compatible functions


背景

PostgreSQL功能上基本可以和Oracle对齐,只是一些语法或者函数名不一样,所以为了做到兼容,有一些兼容包和兼容函数的出现。

PostgreSQL自带了一些Oracle兼容函数,如果你觉得不够意思,可以通过orafce插件继续扩展PostgreSQL与Oracle的兼容性(本文不涉及orafce包)。

http://pgxn.org/dist/orafce/

http://api.pgxn.org/src/orafce/orafce-3.3.0/README.asciidoc

PostgreSQL自带的Oracle兼容函数

在源码src/backend/utils/adt/oracle_compat.c中可以找到它们的定义

/*-------------------------------------------------------------------------  
 * oracle_compat.c  
 *      Oracle compatible functions.  
 *  
 * Copyright (c) 1996-2016, PostgreSQL Global Development Group  
 *  
 *      Author: Edmund Mergl <E.Mergl@bawue.de>  
 *      Multibyte enhancement: Tatsuo Ishii <ishii@postgresql.org>  
 *  
 *  
 * IDENTIFICATION  
 *      src/backend/utils/adt/oracle_compat.c  
 *  
 *-------------------------------------------------------------------------  
 */  
/********************************************************************  
 *  
 * lower  
 *  
 * Syntax:  
 *  
 *       text lower(text string)  
 *  
 * Purpose:  
 *  
 *       Returns string, with all letters forced to lowercase.  
 *  
 ********************************************************************/  
/********************************************************************  
 *  
 * upper  
 *  
 * Syntax:  
 *  
 *       text upper(text string)  
 *  
 * Purpose:  
 *  
 *       Returns string, with all letters forced to uppercase.  
 *  
 ********************************************************************/  
/********************************************************************  
 *  
 * initcap  
 *  
 * Syntax:  
 *  
 *       text initcap(text string)  
 *  
 * Purpose:  
 *  
 *       Returns string, with first letter of each word in uppercase, all  
 *       other letters in lowercase. A word is defined as a sequence of  
 *       alphanumeric characters, delimited by non-alphanumeric  
 *       characters.  
 *  
 ********************************************************************/  
/********************************************************************  
 *  
 * lpad  
 *  
 * Syntax:  
 *  
 *       text lpad(text string1, int4 len, text string2)  
 *  
 * Purpose:  
 *  
 *       Returns string1, left-padded to length len with the sequence of  
 *       characters in string2.  If len is less than the length of string1,  
 *       instead truncate (on the right) to len.  
 *  
 ********************************************************************/  
/********************************************************************  
 *  
 * rpad  
 *  
 * Syntax:  
 *  
 *       text rpad(text string1, int4 len, text string2)  
 *  
 * Purpose:  
 *  
 *       Returns string1, right-padded to length len with the sequence of  
 *       characters in string2.  If len is less than the length of string1,  
 *       instead truncate (on the right) to len.  
 *  
 ********************************************************************/  
/********************************************************************  
 *  
 * btrim  
 *  
 * Syntax:  
 *  
 *       text btrim(text string, text set)  
 *  
 * Purpose:  
 *  
 *       Returns string with characters removed from the front and back  
 *       up to the first character not in set.  
 *  
 ********************************************************************/  
/********************************************************************  
 *  
 * btrim1 --- btrim with set fixed as ' '  
 *  
 ********************************************************************/  
/********************************************************************  
 *  
 * byteatrim  
 *  
 * Syntax:  
 *  
 *       bytea byteatrim(byta string, bytea set)  
 *  
 * Purpose:  
 *  
 *       Returns string with characters removed from the front and back  
 *       up to the first character not in set.  
 *  
 * Cloned from btrim and modified as required.  
 ********************************************************************/  
/********************************************************************  
 *  
 * ltrim  
 *  
 * Syntax:  
 *  
 *       text ltrim(text string, text set)  
 *  
 * Purpose:  
 *  
 *       Returns string with initial characters removed up to the first  
 *       character not in set.  
 *  
 ********************************************************************/  
/********************************************************************  
 *  
 * ltrim1 --- ltrim with set fixed as ' '  
 *  
 ********************************************************************/  
/********************************************************************  
 *  
 * rtrim  
 *  
 * Syntax:  
 *  
 *       text rtrim(text string, text set)  
 *  
 * Purpose:  
 *  
 *       Returns string with final characters removed after the last  
 *       character not in set.  
 *  
 ********************************************************************/  
/********************************************************************  
 *  
 * rtrim1 --- rtrim with set fixed as ' '  
 *  
 ********************************************************************/  
/********************************************************************  
 *  
 * translate  
 *  
 * Syntax:  
 *  
 *       text translate(text string, text from, text to)  
 *  
 * Purpose:  
 *  
 *       Returns string after replacing all occurrences of characters in from  
 *       with the corresponding character in to.  If from is longer than to,  
 *       occurrences of the extra characters in from are deleted.  
 *       Improved by Edwin Ramirez <ramirez@doc.mssm.edu>.  
 *  
 ********************************************************************/  
/********************************************************************  
 *  
 * ascii  
 *  
 * Syntax:  
 *  
 *       int ascii(text string)  
 *  
 * Purpose:  
 *  
 *       Returns the decimal representation of the first character from  
 *       string.  
 *       If the string is empty we return 0.  
 *       If the database encoding is UTF8, we return the Unicode codepoint.  
 *       If the database encoding is any other multi-byte encoding, we  
 *       return the value of the first byte if it is an ASCII character  
 *       (range 1 .. 127), or raise an error.  
 *       For all other encodings we return the value of the first byte,  
 *       (range 1..255).  
 *  
 ********************************************************************/  
/********************************************************************  
 *  
 * chr  
 *  
 * Syntax:  
 *  
 *       text chr(int val)  
 *  
 * Purpose:  
 *  
 *      Returns the character having the binary equivalent to val.  
 *  
 * For UTF8 we treat the argumwent as a Unicode code point.  
 * For other multi-byte encodings we raise an error for arguments  
 * outside the strict ASCII range (1..127).  
 *  
 * It's important that we don't ever return a value that is not valid  
 * in the database encoding, so that this doesn't become a way for  
 * invalid data to enter the database.  
 *  
 ********************************************************************/  
/********************************************************************  
 *  
 * repeat  
 *  
 * Syntax:  
 *  
 *       text repeat(text string, int val)  
 *  
 * Purpose:  
 *  
 *      Repeat string by val.  
 *  
 ********************************************************************/  

参考

src/backend/utils/adt/oracle_compat.c

http://pgxn.org/dist/orafce/

http://api.pgxn.org/src/orafce/orafce-3.3.0/README.asciidoc

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍如何基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
7月前
|
Oracle 关系型数据库 数据库
【赵渝强老师】在PostgreSQL中访问Oracle
本文介绍了如何在PostgreSQL中使用oracle_fdw扩展访问Oracle数据库数据。首先需从Oracle官网下载三个Instance Client安装包并解压,设置Oracle环境变量。接着从GitHub下载oracle_fdw扩展,配置pg_config环境变量后编译安装。之后启动PostgreSQL服务器,在数据库中创建oracle_fdw扩展及外部数据库服务,建立用户映射。最后通过创建外部表实现对Oracle数据的访问。文末附有具体操作步骤与示例代码。
280 6
【赵渝强老师】在PostgreSQL中访问Oracle
|
9月前
|
SQL 存储 Oracle
【YashanDB知识库】Oracle pipelined函数在YashanDB中的改写
【YashanDB知识库】Oracle pipelined函数在YashanDB中的改写
|
SQL Oracle 算法
|
关系型数据库 Serverless 定位技术
PostgreSQL GIS函数判断两条线有交点的函数是什么?
PostgreSQL GIS函数判断两条线有交点的函数是什么?
907 60
|
SQL 自然语言处理 关系型数据库
在 PostgreSQL 中使用 `REPLACE` 函数
【8月更文挑战第8天】
2133 9
在 PostgreSQL 中使用 `REPLACE` 函数
|
Oracle NoSQL 关系型数据库
主流数据库对比:MySQL、PostgreSQL、Oracle和Redis的优缺点分析
主流数据库对比:MySQL、PostgreSQL、Oracle和Redis的优缺点分析
2625 3
|
SQL 关系型数据库 C语言
PostgreSQL SQL扩展 ---- C语言函数(三)
可以用C(或者与C兼容,比如C++)语言编写用户自定义函数(User-defined functions)。这些函数被编译到动态可加载目标文件(也称为共享库)中并被守护进程加载到服务中。“C语言函数”与“内部函数”的区别就在于动态加载这个特性,二者的实际编码约定本质上是相同的(因此,标准的内部函数库为用户自定义C语言函数提供了丰富的示例代码)
|
关系型数据库 PostgreSQL
PostgreSQL的null值函数
【8月更文挑战第20天】PostgreSQL的null值函数
507 3
|
SQL Oracle 关系型数据库
|
SQL Oracle 关系型数据库
Oracle|内置函数之INSTR
【7月更文挑战第5天】

相关产品

  • 云原生数据库 PolarDB
  • 云数据库 RDS PostgreSQL 版
  • 推荐镜像

    更多