• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

我们将共同携手迎接你的到来!


新的一年
新的开始
新的目标
新的收获

kevin 愛戀 20140103

博客园          联系   管理     
长数字隔三位用逗号","隔开,保留两位小数,指定长度,不足补空格

长数字隔三位用逗号","隔开

select to_char(1234.45,'9g999g999'),length(to_char(1234.45,'9g999g999')) from dual;

执行结果:     1,234     10

保留两位小数

select to_char(1234.45,'9g999g999d00'),length(to_char(1234.45,'9g999g999d00')) from dual;

执行结果:     1,234.45     13

select to_char(0.40,'9g999g999d00'),length(to_char(0.40,'9g999g999d00')) from dual;

执行结果:     .40     13

select to_char(0.40,'9g999g990d00'),length(to_char(0.40,'9g999g990d00')) from dual;

执行结果:     0.40     13

指定长度,不足补空格

--RPAD 在列的右边粘贴字符
--LPAD 在列的左边粘贴字符

select lpad(to_char(1234,'9g999g999'),7,' '),length(to_char(1234.45,'9g999g999')) from dual;

执行结果:     1,     10

select lpad(to_char(1234,'9g999g999'),9,' '),length(to_char(1234.45,'9g999g999')) from dual;

执行结果:     1, 23    10

select lpad(to_char(1234,'9g999g999'),10,' '),length(to_char(1234.45,'9g999g999')) from dual;

执行结果:     1, 234    10

select lpad(to_char(1234.56,'9g999g999d00'),10,' '),length(to_char(1234.56,'9g999g999d00')) from dual;

执行结果:     1, 234    13

select lpad(to_char(1234.56,'9g999g999d00'),13,' '),length(to_char(1234.56,'9g999g999d00')) from dual;

执行结果:     1, 234.56    13

select lpad(trim(to_char(1234.56,'9g999g999d00')),10,' '),length(trim(to_char(1234.56,'9g999g999d00'))) from dual;

执行结果:     1, 234.56    8

select lpad(trim(to_char(1234.56,'9g999g999g999g999g999g999g999g999g999d00')),10,' '),length(trim(to_char(1234.56,'9g999g999g999g999g999g999g999g999g999d00'))) from dual;

执行结果:     1, 234.56    8

posted on 2011-04-21 15:09  kevin_20131022  阅读(1534)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3