码迷,mamicode.com
首页 > 数据库 > 详细

oracle 常用字符串函数

时间:2017-10-04 14:20:55      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:四舍五入   内容   字母   ini   一个   oracle   trim   bsp   select   

 select  initcap(‘guodongdong‘) from dual;                                  /返回字符串并将字符串的第一个字母变为大写;
  select initcap(ename) from scott.emp;                                      /针对scott.emp表中的ename开头全部大写。
  select lower(ename) from scott.emp;                                       /针对scott.emp表中的ename名字中全部小写。
  select * from scott.emp where lower(ename)=‘scott‘;                         /以防scott中有大小写。
  select upper(ename) from scott.emp;                                       /针对scott.emp表中的ename名字全部大写
  select length(ename) from scott.emp;                                       /查询scott.emp表中的ename名字所占的单词个数。
  select ename,substr(ename,length(ename)-2) from scott.emp            /查询Scott.emp表中的ename名字最后的三个英文名称。
    或者 select ename,substr(ename,-3) from scott.emp;
  select concat(‘guo‘,‘dongdong‘) from dual;                                 /CONCAT只能连接两个字符串,没有|| 强大。
  select concat(ename,sal) from scott.emp;                                   /针对scott.emp表中的名字个工资做一个连接。
  select substr(‘guodongdong‘,1,5) from dual;                               /查询guodongdong,從左邊1-5的单词列出。
  select subsrt(‘guodongdong‘,-1,5) from dual;                                /從右邊開始。
    select subsrt(‘guodongdong‘,-1) from dual;                                /截取末尾;
  select lpad(‘guodongdong‘,15,‘*‘) from dual;                               /显示guodongdong,15表示15为,不够15为则在前方补*。
  select rpad(‘guodongdong‘,15,‘*‘) from dual;                               /显示guodongdong,15表示15为,不够15为则在后方补*。
  select lpad(ename,length(ename)+30,‘*‘ )from scott.emp;
  select lpad (ename,length(ename)+30,‘*‘) from scott.emp;
  select rpad (lpad (ename,length(ename)+30,‘*‘),length(lpad(ename,length(ename) +30,‘*‘)) +30,‘*‘) from scott.emp;
  select replace(‘guodongdong‘,‘d‘,‘j‘) from dual;                           /修改guodongdong,d单词全部替换为j,则是guojongjong
  select trim(‘k‘ from  ‘gkgguodonkkgdonggg‘) from dual;                     /只要gkgguodonkkgdonggg去除指定字符的前后空格。
    ltrim
    rtrim
    三个主要函数:ROUND,trunc,mod
     1: SELECT
            round(78915.67823823),    78916,小数点之后的内容直接进行四舍五入
            round(78915.67823823,2),  78915.68,保留两位小数
            round(78915.67823823,-2), 78900,把不足5的数据取消了
            round(78985.67823823,-2), 79000,如果超过了5则进行进位
            round(-15.65)           ; -16
          from dual;
     2:截取小数,所有的小数都不进位
        SELECT
            trunc(78915.67823823),    78916,小数点之后的内容直接进行四舍五入
            trunc(78915.67823823,2),  78915.68,保留两位小数
            trunc(78915.67823823,-2), 78900,把不足5的数据取消了
            trunc(78985.67823823,-2), 79000,如果超过了5则进行进位
            trunc(-15.65)           ; -16
          from dual;
      3:求模(求余数)
          select mod(10,3) from dual; 得1

oracle 常用字符串函数

标签:四舍五入   内容   字母   ini   一个   oracle   trim   bsp   select   

原文地址:http://www.cnblogs.com/Juvenile/p/7625318.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!