Conversion functions are used from one data type into another, in some cases, allows the data types oracle server and the actual values are not the same, then the oracle server implicitly conversion data types, such as:
create table t1(id number);
insert into t1 values ('10 '); ---> this oracle will automatically' 10 'is converted to 10
create table t2(id varchar2(10));
insert into t2 values (11) so oracle will automatically be converted to 11 '11'
We can say is that although this oracle implicit data type conversion, but it is not suitable for all cases, in order to improve the reliability of the program, we should use the conversion function to convert.
n use to_date function
(To convert the string to a date format specified)
We insert date column, we find that to be in the default format (day - month - year) adding, in fact, the way we want to add their own habits, such as:
insert into emp (empno, hiredate) values (2222, '1988-11-11'); this error.
We can use to_date the date conversion
insert into emp(empno,hiredate) values(2222,to_date(’1988-11-11’,’yyyy-mm-dd’);
Please think about: How to insert a column with a sheet date, according to you - month - insert date format?
n to_char(number/date/char)...
You can use select ename, hiredate, sal from emp where deptno = 10; display information, but, in some cases, the disease can not meet your needs.
? Whether the date can display minutes and seconds
SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'YYYY-MM-DDHH2
------------------------------
2016-10-15 17:11:06
9 : digital display, and disregard the previous 0 0 : digital display, such as insufficient digits, with 0 padded . : Decimal point in the specified location ,: Comma appears in the specified location $ : Plus $ before the number L : local currency plus sign before the number C : International Monetary plus sign before the number G : display set separator at the specified position , D : decimal point position specified symbol ( . ) |
yy: two-digit year 2004 Nian -> 04 yyyy: four-digit year 2004 Nian mm: two-digit month 8 Yue -> 08 dd: day two factors of 30 Ri -> 30 hh24: 24 hour evening . 8 point -> 20:00 hh12: 12 hour . 8 point -> 08:00 mi: ss shown in minutes : seconds day |
? Whether the salary can display a specified currency symbol
SQL> select ename,to_char(sal,'L99G999D99') from emp;
ENAME TO_CHAR(SAL,'L99G999D99')
---------- -------------------------
xiaohong
SMITH ¥1,190.00
ALLEN ¥1,600.00
WARD ¥1,250.00
JONES ¥2,975.00
? According deptno number display different information
SQL> select ename, decode (deptno, 10, department number '10 ', 20, department number '20', 30, department number '30 ') from emp;
ENAME DECODE (DEPTNO, 10, department number '10 ', 20
---------- ---------------------------
xiaohong
SMITH 20 departments
ALLEN No. 30 departments
WARD 30 departments
JONES 20 departments