oracle day3:如何對錶進行增刪改詢操做

1.查詢公司每一個員工的編號,名字,薪水數據庫

select empno,ename,sal from emp;session

2.查詢員工入職的時間oracle

select ename,hiredate from emp;ide

3.設置查詢數據的時間格式函數

alter session set nls_date_format='YYYY-MM-DD';orm

alter:"更改",居句首.排序

session:在計算機中表示一個會話,這裏表示只更改當前會話的時間格式,不影響其餘用戶。退出當前會話是消失。字符串

set: "設置"it

nls_date_format:日期參數io

YYYY-MM-DD:年月日

4.查詢當前數據庫時間

select sysdate from dual;

dual:oracle的一個虛表,用查詢計算,常量表達式

5.查詢出每一個員工到目前的工做年數

select ename,round((sysdate-hiredate)/365,0) from emp;

round(X,Y):表示oracle數據庫的一個四捨五入的函數。

X表示的是要進行四捨五入的數,Y表示哪位小數要進行四捨五入(能夠鏈接爲保留幾個小數點)。若是Y=0,則表示在個位進行四捨五入。

6.按照工做年數排序查詢出每一個員工的姓名及年數

a. select ename,round((sysdate-hiredate)/365,0) from emp order by round((sysdate-hiredate)/365,0);

select ename,round((sysdate-hiredate)/365,0) from emp order by hiredate;

select ename,round((sysdate-hiredate)/365,0) from emp order by 2;

b. select ename,round((sysdate-hiredate)/365,0) from emp order by 2 desc;

order by:SQL語句的關鍵字,表示排序,默認升序

desc:降序

7.臨時多給每一個員工1500的獎金

select ename,sal+1500 from emp order by 2;

8.對查詢出來的薪水進行說明

select ename||'員工本月工資爲:$'|| (sal+1500) as "公司員工本月工資表" from emp order by sal;

||:oracle的鏈接符。,能夠對多個字符串、多個表的列值鏈接。

'':引號裏面是字符,能夠把裏面的字符輸出

相關文章
相關標籤/搜索