----------------------------------------------------------------
--Find out the EMP table
SELECT * from EMP;
--Select all information for employees in department 30
SELECT * from emp where deptno = 30;
--The number of the employee who listed the position as Martin, name
Select Empno,ename from emp where job = ' MANAGER ';
--Finding employees with bonuses above their salaries
SELECT * FROM EMP where comm>sal;
--Find out the sum of bonuses and wages for each employee
Select Sal+comm,ename from EMP;
--Find out the manager in department 10 and the General Staff in department 20 (clerk)
SELECT * from EMP where (deptno=10 and job= ' MANAGER ') or (deptno=20 and job= ' clerk ');
--Find out that department 10 is neither a manager nor a regular employee, and that the salary is equal to 2000
SELECT * from emp where deptno=10 and job not in (' MANAGER ', ' Clerk ') and sal>=2000;
--Find out the different jobs of employees with bonuses
SELECT DISTINCT job from EMP where Comm are not null and comm>0;
-Find employees with no bonuses or bonuses below 500
SELECT * FROM EMP where comm is null or comm<500;
-Displays the employee's name, according to its service life, the oldest employee in front
Select ename from emp order by HireDate;
Select ename from emp order BY hiredate Desc; --desc from high to low
---------------------------------------------------------------------
--upper All uppercase letters
Select Upper (ename) from EMP;
SELECT * from emp where Ename=upper (' Smith ');
--lower Letter All Lowercase
Select Lower (ename) from EMP;
SELECT * from EMP;
--initcap First Letter Capital
Select Initcap (ename) from EMP;
--concat Merging multiple arrays
Select Concat (ename,job) from EMP;
--substr Intercept String length
--substr (String,start,length)
--string specifying the string to intercept
--start must specify where to start a positive number in the string starting at the specified position from the beginning of the Mantissa Zero starting with the first character
--length Optional, specifies the length of the string to intercept, all characters before the end of the default
Select Ename,
SUBSTR (ename,-3),---starting from the penultimate position, the character after the Intercept
SUBSTR (ename,-3,2), the two-length character after the Intercept, starting at the third-lowest position
substr (Ename,length (' ename ')-3),--set a five-length character ' ename ' (5-3) to intercept from the second position
substr (Ename,length (' ename ') -3,2),--set a five-length character ' ename ' (5-3) to intercept 2 character lengths from the second position
substr (Ename,length (ename)-3), which starts at the third position from the bottom of the subscript zero, and the character after the Intercept
substr (Ename,length (ename) -3,2)-two-length characters from the bottom of the subscript starting from the zero-based three position
from EMP;
--length Get string length
Select Length (ename) from EMP;
--replace replacement character converts a to C
Select Replace (ename, ' A ', ' C ') from EMP;
--instr find the location of a data inside ' character ' case-sensitive
Select InStr (ename, ' S ') from EMP;
--lpad left padding
Select Ename,
Lpad (ename,5, ' * '),---fill the length of the character with ' * ' to 5 lengths from the left
Lpad (ename,5, ' net disk ')--not recognized Chinese
from EMP;
--rpad Right padding
Select Rpad (ename,5, ' * ') from EMP; --fill the length of the character with ' * ' to 5 lengths from the right.
--trim Filter Filter Closure space
Select Trim (' Loyer ') from EMP;
--round rounding
Select Round (sal,-1) from EMP; --round the value of the first position in the countdown
--trunc the number truncation rounding
Select Trunc (SAL) from EMP;
--mod to take the remainder
Select mod (sal,300) from EMP;
---------------------------------------------------------------------------
--Months_between number of months between two dates sysdate represents system time HireDate onboarding time
Select HireDate from EMP;
Select HireDate, Months_between (sysdate,hiredate) from EMP;
--add_moths add a few months to the date you specify
Select Add_months (sysdate,1) from EMP;
--next_day a date value of 1-7 for the specified week inner
Select Next_day (sysdate,7) from EMP;
--last_day last day of the month
Select Last_day (sysdate) from EMP;
--round Date Rounding 24-hour system half of the time will go into the next day
Select Round (sysdate) from EMP;
--trunc date truncation is automatically removed from the hour
Select Trunc (sysdate) from EMP;
---------------------------------------------------------------------------
--to_char
Select To_char (sysdate, ' yyyy ') from EMP;
Select To_char (sysdate, ' Yyyy-mm-dd ') from dual;
Select To_char (Sal, ' l999,999,999 ') from EMP;
Select To_char (sysdate, ' D ') from dual;
---------------------------------------------------------------------------
--Find the employee who was hired on the third day of the month.
Select ename from emp where Hiredate=last_day (HireDate)-3;
--Find out who hired employees 25 years ago.
Select ename from emp where hiredate<=add_months (SYSDATE,-25*12);
--All employee names are preceded by Dear, and the first letter is capitalized
Select ' Dear ' | | Initcap (ename) from EMP;
--Find an employee with a 5-letter name
Select ename from emp where length (ename) = 5;
--Find employees with names that don't have the letter R
Select ename from emp where ename does like '%r% ';
--Displays the first word of all employees ' names
Select substr (ename,1,1) from EMP;
--Show all employees in descending order by name, if same, sort by wage ascending
Select Sal,ename from EMP;
Select ename from emp ORDER BY ename DESC
--Find the employee who was hired in February
SELECT * from emp where TO_CHAR (hiredate, ' fmmm ') = ' 2 ';
Oracle database queries basic data