sql> select to_char(salary, '$999,999.00') from employees;
sql> select last_name, to_char(hire_date, 'dd-mon-rr') from employees;
sql> select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') from dual;
sql> select to_char(sysdate, 'yyyy-mm-dd hh:mi:ss am') from dual;
fm 去
0sql> select last_name from employees where hire_date=to_date('2006-05-23', 'yyyy-mm-dd');
sql> select to_number('$123,456.78', '$999,999.00') from dual;
練習:查詢2023年入職員工:
select last_name
from employees
where hire_date between to_date('2006-01-01', 'yyyy-mm-dd')
and to_date('2006-12-31', 'yyyy-mm-dd');
select last_name
from employees
where to_char(hire_date, 'yyyy')='2006';
select last_name
from employees
where extract(year from hire_date)=2006;
--不推薦
select last_name
from employees
where hire_date like '2006%';
查詢歷年9月份入職的員工:
select last_name
from employees
where to_char(hire_date, 'mm')='09';
select last_name
from employees
where extract(month from hire_date)=9;
其他函式:
nvl:
nvl(val1, val2)
if val1 is not null
then
return val1;
else
return val2;
sql> select last_name, salary*12*(1+nvl(commission_pct, 0)) total_salary from employees;
練習:顯示所有員工部門編號,沒有部門的顯示「未分配部門」
case和decode:
it_prog +1000
sa_rep +1500
st_clerk +2000
其他人工資不變
select salary+1000 from employees where job_id='it_prog';
select last_name, job_id, salary,
case job_id
when 'it_prog' then salary+1000
when 'sa_rep' then salary+1500
when 'st_clerk' then salary+2000
else salary
end new_salary
from employees;
select last_name, job_id, salary,
decode( job_id,
'it_prog', salary+1000,
'sa_rep', salary+1500,
'st_clerk', salary+2000,
salary) new_salary
from employees;
練習:按照員工工資,對員工分級顯示:
a 20001-25000
b 15001-20000
c 10001-15000
d 5001-10000
e 0-5000
Impala 轉換函式和其他函式
基於impala 3.2版本 1.轉換函式 cast expr as type 2.資料型別判斷 typeof type value 3.uuid函式 select uuid uuid 2e2e4db5 6fe3 436d 92a8 bdecc40f1ddd4.資料庫的輔助資訊函式 4.1 查詢登入...
JsonObject 和其他型別資料的轉換
1.list集合轉換成json list list newarraylist list.add first list.add second jsonarray jsonarray2 jsonarray.fromobject list 2.map集合轉換成json map map newhashmap...
String型別和其他型別間的資料轉換
1 string 轉化成 基本資料型別 利用基本資料型別對應的包裝類的par xx 或 valueof 方法 注意 string 物件的字面量 是 數字型別。否則會報異常 numberformatexception parse是解析的意思,所以integer.parseint str 就是把str解...