`

oracle 字符串连接

阅读更多
字符串连接

SQL> select 'abc' || 'def' from dual;
'ABC'|
------
abcdef
SQL>
■ 小写

select lower('ABC012');

lower
--------
abc012
■ 大写

select upper('abc012');

upper
--------
ABC012

■ 左补全

select lpad('abc', 5, '0');

lpad
-------
00abc

select lpad('abc', 5, '012');

lpad
-------
01abc

第3个参数为空时,缺省为space

select lpad('abc', 5);

lpad
-------
   abc

select lpad('abc', 5, ' ');

lpad
-------
   abc

■ 右补全

select rpad('abc', 5, '0');

rpad
-------
abc00

select rpad('abc', 5, '012');

rpad
-------
abc01

■ 左空白删除

select ltrim('          abc');

ltrim
-------
abc
■ 右空白删除

select ltrim('abc          ');

     ltrim
---------------
abc

■ 左右空白删除

select trim('          abc          ');

btrim
-------
abc
■ 字符串替换

SQL> SELECT TRANSLATE('ababab' , 'a' , '1') FROM DUAL;
TRANSL
------
1b1b1b

■ 取子字符串

SQL> select substr('abc012', 3, 2) from dual;
SU
--
c0

■ 字符串长度

SQL> select length('abc012') from dual;
LENGTH('ABC012')
----------------
               6

■ 数字转化成字符串

SQL> select to_char(123456, '999,999,999,999') from dual;
TO_CHAR(123456,'
----------------
         123,456

■ 字符串转化为数字

SQL> select to_number('123' || '456', '999999999999') from dual;
TO_NUMBER('123'||'456','999999999999')
--------------------------------------
                                123456

SQL> select to_number('123,456', '999,999,999,999') from dual;
TO_NUMBER('123,456','999,999,999,999')
--------------------------------------
                                123456
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics