Oracle數據庫——函數 http://www.jb51.net/article/40469.htm

1====分析函數  至關於把分組後的結果加到每一行裏oracle

SELECT  t.loan_contract_no,t.loan_name,t.loan_amount,ROWNUM,
  row_number() over (PARTITION  BY t.area_no  ORDER BY t.loan_amount DESC),--行號
  round(avg(t.loan_amount) over (PARTITION  BY t.area_no  ORDER BY t.loan_amount DESC)),
  round(SUM(t.loan_amount) over (PARTITION  BY t.area_no  ORDER BY t.loan_amount DESC)),
  round(rank() over (PARTITION  BY t.area_no  ORDER BY t.loan_amount DESC)),--排名不連續
  round(dense_rank() over (PARTITION  BY t.area_no  ORDER BY t.loan_amount DESC)),--排名序號連續
  round(MAX(t.loan_amount) over (PARTITION  BY t.area_no  ORDER BY t.loan_amount DESC)),
  round(MIN(t.loan_amount) over (PARTITION  BY t.area_no  )),--不能加 ORDER BY t.loan_amount DESC
  round(first_value(t.loan_amount) over (PARTITION  BY t.area_no )),
  round(last_value(t.loan_amount) over (PARTITION  BY t.area_no )),
  lag(t.loan_amount,1,1) over (  ORDER BY t.loan_amount DESC),--最大用1填充
  lead(t.loan_amount,1,0) over (  ORDER BY t.loan_amount DESC)--最小用0填充
 
   FROM account_info t   WHERE t.grant_loan_date>'2016-04-01';app

select t.* 
from scott.emp t ORDER BY t.deptno,t.sal;
SELECT t.deptno,t.ename,t.sal,last_value(t.sal) over (PARTITION BY t.deptno ORDER BY t.sal ROWS BETWEEN 2 preceding AND 2 following ) from scott.emp t;
SELECT t.deptno,t.ename,t.sal,MAX(t.sal) over (PARTITION BY t.deptno ORDER BY t.sal ROWS between unbounded preceding AND unbounded following ) from scott.emp t;
SELECT t.empno,t.deptno,t.ename,t.sal,SUM(t.sal) over (PARTITION BY t.deptno ORDER BY t. ename) from scott.emp t ORDER BY 2,3;
SELECT t.empno,t.deptno,t.ename,t.sal,SUM(t.sal) over (PARTITION BY t.deptno ORDER BY t. ename ROWS BETWEEN unbounded preceding AND CURRENT ROW) from scott.emp t ORDER BY 2,3;函數

 

一、instrspa

Oracle/PLSQL中,instr函數返回要截取的字符串在源字符串中的位置。只檢索一次,就是說從字符的開始code

  到字符的結尾就結束。索引

  語法以下:字符串

  instr( string1, string2 [, start_position [, nth_appearance ] ] )get

  參數分析:string

  string1it

  源字符串,要在此字符串中查找。

  string2

  要在string1中查找的字符串.

start_position

  表明string1 的哪一個位置開始查找。此參數可選,若是省略默認爲1. 字符串索引從1開始。若是此參數爲正,從左到右開始檢索,若是此參數爲負,從右到左檢索,返回要查找的字符串在源字符串中的開始索引。

  nth_appearance

  表明要查找第幾回出現的string2. 此參數可選,若是省略,默認爲 1.若是爲負數系統會報錯。

  注意:

  若是String2在String1中沒有找到,instr函數返回0.

SELECT  code , name , dept, occupation FROM staff  WHERE code IN ('A10001','A10002');

或者:

SELECT  code , name , dept, occupation FROM staff  WHERE code = 'A10001' OR code = 'A10002';

或者

SELECT  code , name , dept, occupation FROM staff  WHERE
instr('A10001,A10002',code)>0;

 

SELECT code, name, dept, occupation  FROM staff  WHERE instr(code, '001') > 0;

等同於

SELECT code, name, dept, occupation  FROM staff  WHERE code LIKE '%001%' ;

//計算年齡

SELECT Extract(year from sysdate)-Extract(year FROM to_date(i.DATE_OF_BIRTH,'yyyy-mm-dd')) FROM crf_p2p_loan_idcard_info i ;

相關文章
相關標籤/搜索