瀚高数据库 select-sql常用函数

瀚高数据库 select-sql常用函数


1、字符串拼接||
语法
string || string
示例
'post' || 'gresql' -- 返回postgresql


2、字符串的长度length()
语法
length(string)
示例
length('odoo') -- 返回4

3、模式匹配like
语法
string like pattern
示例
’abc’ like ’abc’ -- 返回true
’abc’ like ’a%’ -- 返回true

4、把时间戳转换成字符串to_char()
语法
to_char(timestamp, text)
示例
to_char(create_date, 'yyyy-mm-dd')
to_char(create_date, ’hh12:mi:ss’)

5、把字符串转换成日期to_date()
语法
to_date(text, text)
示例
to_date(’05 jan 2015’,’dd mon yyyy’)

6、把字符串转换成时间戳to_timestamp()
语法
to_timestamp(text, text)
示例
to_timestamp(’05 jan 2015’, ’dd mon yyyy’)

7、 条件表达式case
语法1
case when condition then result [when ...then ...] [else result] end
示例1
case when gender='male' then '程序猿' else '程序媛' end
语法2(简化形式)
case expression when value then result [when ...then ...] [else result] end
示例2
case gender when 'male' then '程序猿' else '程序媛' end

8、返回第一个非null的参数coalesce()
所有参数均为null时则返回null
语法
coalesce(value [, ...[, ...]])
示例
coalesce(actual_qty,0) as actual_qty

9、nullif() 如果value1与value2相等则返回null, 否则返回value1
语法
nullif(value1, value2)
示例
nullif(value, ’(none)’)

10、将参数的第一个字符转换为ascii码ascii()
语法
ascii(string)
示例
ascii(’x’) -- 返回120


11、将ascii码转换为字符chr()
语法
chr(int)
示例
chr(65) -- 返回a

posted @ 2024-03-25 13:57  山䂥进城  阅读(691)  评论(0)    收藏  举报