数据库常用函数(持续更新!!!)

参考文章:https://www.cnblogs.com/ringwang/p/3561758.html

基于oracle数据库。

因为是在navicat工具中写的所以函数的两边有""

统一命名:一参param1,二参param2,三参param3

1、CONCAT() >> 字符串的拼接。

【param1为nullparam2不为null时,返回param2;

param1不为nullparam2为null时,返回param1;

param1与param2都为null时,返回null;

param1与param2都不为null时,返回param1与param2的字符串拼接】

    select "CONCAT"('hello' , NULL) a from dual;

2、INITCAP() >> 字符串大小写的转换

【param1首字母大写其余字母小写】

    select "INITCAP"('hello.world') b from dual;

3、LENGTH() >> 返回字符串的长度

    select "LENGTH"('helloworld') c from dual;

4、REPLACE() >> 字符串的替换

【param1为目标字符串,param2为需要替换的字符,param3为需要替换成的字符】
    
    select "REPLACE"('helloworld', 'lo', 'ol') d from dual;

5、TRIM() >> 字符串消除空格

【注意:仅支持消除字符两边的空格】

    select "TRIM"('hello  world') e from dual;

6、UPPER() >> 字符串转化为大写

    select "UPPER"('helloworld') f from dual;

7、CEIL() >> 字符串向上取整
   
    select "CEIL"(3.4) g from dual;

8、FLOOR() >> 字符串向下取整

    select "FLOOR"(3.7) h from dual;

9、MOD() >> 数字取余数

【param1为需要取余的目标值,param2为余数】

    select "MOD"(5, 2) i from dual;

10、ROUND() >> 数值的四舍五入

【param2为2时表示保留小数点后两位】

    select "ROUND"(3.1415, 2) j from dual;

11、TRUNC() >> 数值的截取

【param2为3时表示小数点后截取三位】

    select "TRUNC"(3.1415, 3) k from dual;

12、SYSDATE >> 返回当前系统日期时间

    select SYSDATE l from dual;

13、USER >> 返回当前用户

    select USER m from dual;

14、LOWER() >> 字符串转换为小写

    select "LOWER"('HELLworLD') n from dual;

15、字符串首字母小写其余大写(demo)

    select "LOWER"('h') || "UPPER"('elloworld') o from dual;

猜你喜欢

转载自blog.csdn.net/qq_42129399/article/details/88925215