Oracle use function in query

1. Using character functions in queries

1. Demand
Query the employee's birthday in the employee information table, and get the birthday according to the employee's ID number.
2. Examples
  1. SQL>select*from users;
  2. ID NAME CARDID DEPTNO REGDATE AGE
  3. -------------------------------------------------------------------------
  4. 1 abc 123456199205050105-5-1718
  5. SQL>select substr(cardid ,7,8)from users;
  6. SUBSTR(CARDID,7,
  7. ----------------
  8. 19920505
3. Demand
Replace all department number 01 with information technology
4. Examples
  1. SQL>select replace(deptno ,'01','信息技术')from users;
  2. REPLACE(DEPTNO,'01','信息技术')
  3. --------------------------------------------------------------------------------
  4. 信息技术
 
2. Use numeric type functions in queries
1. Demand
Take the remainder of the age field in the employee information table and 10
2. Code
  1. SQL>select mod(age,10)from users;
  2. MOD(AGE,10)
  3. -----------
  4. 8
 
3. Use date functions in queries
1. Demand
The year the employee was hired
Find out the information of employees who joined in May
  1. SQL>select extract(year from regdate)from users;
  2. EXTRACT(YEARFROMREGDATE)
  3. ------------------------
  4. 2017
  5. SQL>select*from users where extract(month from regdate)=5;
  6. ID NAME CARDID DEPTNO REGDATE AGE
  7. -------------------------------------------------------------------------
  8. 1 abc 123456199205050105-5-1718

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326160811&siteId=291194637