freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

第14章oracle中的函數(shù)與表達式(編輯修改稿)

2025-01-26 19:42 本頁面
 

【文章內(nèi)容簡介】 值。 select months_between(to_date(39。2023020839。, 39。yyyymmdd39。), to_date(39。2023030839。, 39。yyyymmdd39。)) result from dual。 current_date()函數(shù) —— 返回當前會話時區(qū)的當前日期 current_date()函數(shù)用于返回當前會話時區(qū)的當前日期。 select sessiontimezone, to_char(current_date, 39。yyyymmdd hh:mi:ss39。) result from dual。 注意與說明: current_date等無參數(shù)函數(shù)作為 Oracle的關(guān)鍵字存在。在使用時,不能為其添加小括號。即 select current_date() from dual是錯誤的 SQL語句。 current_timestamp()函數(shù) —— 返回當前會話時區(qū)的當前時間戳 current_timestamp()函數(shù)用于返回當前會話時的區(qū)時間戳??梢越Y(jié)合 sessiontimezone來查看其用法。 select sessiontimezone, current_timestamp from dual。 extract()函數(shù) —— 返回日期的某個域 日期由若干域組成,例如年、月、日、小時等等。extract()函數(shù)可以返回這些域的具體值。為了使用該函數(shù),除了要指定原日期外,還應(yīng)該指定要返回的域名。 select extract(year from sysdate) result from dual。 需要注意的是, year、 month、 day域只能從日期(如sysdate)中獲得,而 hour、 minute、 second只能從時間型(如 systimestamp)中獲得。 Oracle中的聚合函數(shù) 所謂聚合函數(shù)是指針對多條記錄的函數(shù)。 Oracle最常用的聚合函數(shù)包括, max()、 min()、 avg()、 sum()和count()函數(shù)。本節(jié)將講述這些函數(shù)的用法。 max()函數(shù) —— 求最大值 max()函數(shù)用于獲得記錄集在某列的最大值。例如,為了返回員工最高工資,可以利用 max()函數(shù)。 select max(salary) max_salary from t_salary。 需要注意的是,聚合函數(shù)往往是返回記錄集的統(tǒng)計值,因此,不能與其中的單條記錄同時出現(xiàn)。例如,不能將max(salary)與具體列一起查詢。 select employee_id, max(salary) max_salary from t_salary。 select distinct , from t_employees e, t_salary s where = and = (select max(salary) from t_salary) min()函數(shù) —— 求最小值 min()函數(shù)可以用來獲得記錄集在某列上的最小值,其功能與 max()函數(shù)相反。 select distinct , from t_employees e, t_salary s where = and = (select min(salary) from t_salary) avg()函數(shù) —— 求平均值 avg()函數(shù)用于獲得記錄集在某列上的平均值。 select , avg(salary) from t_employees e, t_salary s where = group by , sum()函數(shù) —— 求和 sum()函數(shù)用于獲得結(jié)果集上某列值的和。 select , sum(salary) from t_employees e, t_salary s where = group by , count()函數(shù) —— 獲得記錄數(shù) count()函數(shù)的作用對象同樣為記錄集。與其他聚合函數(shù)不同的是, count()函數(shù)可以有三種方式來進行計數(shù):count(*)——計算行數(shù)、 count(column)——計算某列和count(1)——累加 1。 insert into t_employees values (16, null, null,null)。 select count(*) from t_employees。 select count(employee_id) from t_employees。 select count(employee_name) from t_employees。 select count(1) from t_employees。 一般來說,利用 count(1)進行計數(shù)的速度最快,但是特別注意的是,預(yù)期的結(jié)果是針對整行數(shù)據(jù),還是某列的數(shù)據(jù)。 Oracle中的其他函數(shù) 除了數(shù)值函數(shù)、字符串函數(shù)、日期函數(shù)和聚合函數(shù)外, Oracle還提供了其他功能性更強的函數(shù)。本節(jié)將介紹decode()、 nvl()和 cast()函數(shù)。 decode()函數(shù) —— 多值判斷 decode()函數(shù)用于多值判斷。其執(zhí)行過程類似于解碼操作。該函數(shù)最常見的應(yīng)用為,實現(xiàn)類似 if else的功能。例如,可以利用 decode()函數(shù)為員工工資添加標識,工資大于 6000者為高收入,其余的為一般收入。 select , , decode(sign(avg() 6000),1, 39。高收入 39。, 39。一般收入 39。) inming from t_employees e, t_salary s where = group by , nvl()函數(shù) —— 為空值重新賦值 nvl()函數(shù)用于處理某列的值。該函數(shù)有兩個參數(shù),第一個參數(shù)為要處理的列。如果其值為空,則返回第二個參數(shù)的值,否則,將返回列值。 select employee_id, nvl(employee_name, 39。未知 39。) employee_name from t_employees。 nvl()函數(shù)更常見的用途為判斷數(shù)值是否為空。因為sum()等函數(shù)往往會返回 null,例如,表示匯率的列一旦為null,那么最終的貨幣結(jié)算額度也為 null,所以,必須對匯率列進行 nvl()的處理。在統(tǒng)計員工工資時, null同樣是不受歡迎的結(jié)果,那么可以利用 nvl()函數(shù)進行處理。 select , nvl(, 39。未知 39。) employee_name, nvl(sum(), 0) salary from t_employees e, t_salary s where = (+) group by , cast()函數(shù) —— 強制轉(zhuǎn)換數(shù)據(jù)類型 cast()函數(shù)用于強制轉(zhuǎn)換數(shù)據(jù)類型。 Oracle會根據(jù)操作符來自動進行數(shù)據(jù)類型的轉(zhuǎn)換,例如: select 39。12339。 + 200 result from dual。 Oracle會根據(jù)運算符 “+”將 ?123?轉(zhuǎn)換為數(shù)值型 123。 select 39。12339。 || 200 result from dual。 Oracle會根據(jù)運算符 “||”將數(shù)字 200轉(zhuǎn)換為字符串 ?200?。 cast()函數(shù)最常用的場景是轉(zhuǎn)換列的數(shù)據(jù)類型,以創(chuàng)建新表 create table tmp_salary as select cast(salary_id as varchar2(20)) salary_id, cast(employee_id as varchar2(20)) employee_id, cast(month as varchar2(20)) month, cast(salary as varchar2(20)) salary from t_salary desc tmp_salary。 Oracle中的運算表達式 Oracle中的常用運算包括:數(shù)學運算、邏輯運算和按位運算。本節(jié)將通過范例著重講述這三種運算的常用運算符和運算規(guī)則。 數(shù)學運算 數(shù)學運算是最常用的運算方式, Ora
點擊復(fù)制文檔內(nèi)容
公司管理相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1