日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

oracle之单行函数之课后练习

發布時間:2023/12/10 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle之单行函数之课后练习 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
18. 打印出 "2009年10月14日 9:25:40" 格式的當前系統的日期和時間.select to_char(sysdate, 'YYYY"年"MM"月"DD"日" HH:MI:SS')from dual 注意: 使用雙引號向日期中添加字符19. 格式化數字: 1234567.89 為 1,234,567.89select to_char(1234567.89, '999,999,999.99')from dual20. 字符串轉為數字時1). 若字符串中沒有特殊字符, 可以進行隱式轉換:select '1234567.89' + 100from dual2). 若字符串中有特殊字符, 例如 '1,234,567.89', 則無法進行隱式轉換, 需要使用 to_number() 來完成select to_number('1,234,567.89', '999,999,999.99') + 100from dual21. 對于把日期作為查詢條件的查詢, 一般都使用 to_date() 把一個字符串轉為日期, 這樣可以不必關注日期格式select last_name, hire_datefrom employeeswhere hire_date = to_date('1998-5-23', 'yyyy-mm-dd') -- where to_char(hire_date,'yyyy-mm-dd') = '1998-5-23'22. 轉換函數: to_char(), to_number(), to_date()23. 查詢每個月倒數第 2 天入職的員工的信息. select last_name, hire_datefrom employeeswhere hire_date = last_day(hire_date) - 124. 計算公司員工的年薪--錯誤寫法: 因為空值計算的結果還是空值select last_name, salary * 12 * (1 + commission_pct) year_salfrom employees--正確寫法select last_name, salary * 12 * (1 + nvl(commission_pct, 0)) year_salfrom employees25. 查詢部門號為 10, 20, 30 的員工信息, 若部門號為 10, 則打印其工資的 1.1 倍, 20 號部門, 則打印其工資的 1.2 倍, 30 號部門打印其工資的 1.3 倍數--使用 case-when-then-else-endselect last_name, department_id, salary, case department_id when 10 then salary * 1.1when 20 then salary * 1.2when 30 then salary * 1.3end new_salfrom employeeswhere department_id in (10, 20, 30)--使用 decodeselect last_name, department_id, salary, decode(department_id, 10, salary * 1.1,20, salary * 1.2,30, salary * 1.3) new_salfrom employeeswhere department_id in (10, 20, 30) 1. 顯示系統時間(注:日期+時間) a) select to_char(sysdate,'yyyy-mm-dd hh:mi:ss') b) from dual 2. 查詢員工號,姓名,工資,以及工資提高百分之20%后的結果(new salary) a) select employee_id,last_name,salary,salary*1.2 "new salary" b) from employees 3. 將員工的姓名按首字母排序,并寫出姓名的長度(length) a) select last_name,length(last_name) b) from employees c) order by last_name asc 4. 查詢各員工的姓名,并顯示出各員工在公司工作的月份數(worked_month)。 a) select last_name,hire_date,round(months_between(sysdate,hire_date),1) workded_month b) from employees 5. 查詢員工的姓名,以及在公司工作的月份數(worked_month),并按月份數降序排列 a) Select last_name,hire_date,round(months_between(sysdate,hire_date),1) workded_month b) from employees c) order by workded_month desc 6. 做一個查詢,產生下面的結果 <last_name> earns <salary> monthly but wants <salary*3> Dream Salary King earns $24000 monthly but wants $72000 select last_name || ' earns '|| to_char(salary,'$999999')||' monthly,but wants '||to_char(3*salary,'$999999') "Dream Salary" from employees 7. 使用decode函數,按照下面的條件: job grade AD_PRES A ST_MAN B IT_PROG C SA_REP D ST_CLERK E 產生下面的結果 Last_name Job_id Grade king AD_PRES A select last_name "Last_name",job_id "Job_id",decode(job_id,'AD_PRES','A','ST_MAN','B', 'IT_PROG','C', 'SA_REP','D', 'ST_CLERK','E') "Grade" from employees 8. 將第7題的查詢用case函數再寫一遍。 a) select last_name "Last_name",job_id "Job_id",case job_id when 'AD_PRES'then 'A' b) when 'ST_MAN' then 'B' c) when 'IT_PROG' then 'C' d) when 'SA_REP' then 'D' e) when 'ST_CLERK' then'E' end "Grade" f) from employees

?

?

總結

以上是生活随笔為你收集整理的oracle之单行函数之课后练习的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。