oracle經常使用語句

1.去掉字段空格(可將全部的空格都去掉):replace(t.service_type,' ','');html

2.時間:to_date('2018/1/1', 'yyyy-mm-dd'); oracle

select to_date(to_char(sysdate,'yyyy-mm-dd')|| ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss') from dual; ---保存時,使用某天的23::59:59分數據函數

3.取某個字段值中;的第一個:substr(temp.email, 0, instr(temp.email,';');學習

注意:若某個字段的值是空,則不能使用null != 'TYPE',網站

須要轉換一下,否則會查詢不到值:nvl(UPPER(A.sex),'N') <> 'F'url

4.多列轉行或是樹結構:sys_connect_by_path(t.dz, '#')spa

如:.net

4.某個字段以下:a,b,c,想要分開顯示爲三條數據:(後面的只是取的1,2的值而已。如果知道會有多少個,的值,則須要union屢次,而後再去掉空值便可)3d

select regexp_substr('a,b,c,d,e,','[^,]+',1,rownum)   
       from dual connect by rownum<=length(regexp_replace('a,b,c,', '[^,]', null));code

---- 或是:

select regexp_substr(service_type, '[^,]+', 1, 1) str,
                         a.supplier_number
                    from  A a
UNION all
select regexp_substr(service_type, '[^,]+', 1, 2) str,
                         a.supplier_number
                    from  A a    

---- 或是:

select t.supplier_number,
       substr(t.service_type, 0, instr(t.service_type, ',') - 1) as prefix
       /*,substr(t.service_type,
              instr(t.service_type, ',') + 1,
              length(t.service_type)) as suffix*/
  from test1 t
  union all
select t.supplier_number,
       /*substr(t.service_type, 0, instr(t.service_type, ',') - 1) as prefix,*/
       substr(t.service_type,
              instr(t.service_type, ',') + 1,
              length(t.service_type)) as suffix
  from test1 t where t.service_type is not null order by supplier_number,prefix asc

數據:

結果:

5.存儲過程:入門學習(https://www.cnblogs.com/dc-earl/articles/9260111.html,https://www.cnblogs.com/dc-earl/articles/9265144.html)

基本結構:

create or replace procedure 名稱(name in varchar,count out int) --- 若沒有參數時,可不用帶上(),in輸入參數,out輸出參數

as /is ---其中視圖只能用as,遊標只能用is

---聲明變量,省份

sf varchar(50);---varchar必須指定長度

begin

```````

sf:='GX';---變量賦值

dbms_output.put_line('name='||name||',age='||age);---控制檯打印,||鏈接字符串

end 名稱;

----- 異常:

執行:https://www.cnblogs.com/sdd53home/p/5169046.html

有參數的調用:

declare

  name varchar(10);
  age  int ;
begin
   myDemo05(name=>name,age=>10);
   dbms_output.put_line( 'name=' ||name);
end;

 6.oracle中的utl_http:能夠捕捉網站頁面的內容或是調用一個url的接口完成某項功能

https://blog.csdn.net/rznice/article/details/72625680

7.CHR() --將ASCII碼轉換爲字符;ASCII() --將字符轉換爲ASCII碼

https://blog.csdn.net/wangnan537/article/details/17676037

 8.在排序時,null默認是最大值,

order by P.parental_ib ,P.creation_date desc(parental_ib字段使用的是升序,creation_date降序)

order by P.parental_ib desc ,P.creation_date desc(parental_ib字段使用的是降序切Null在前面,creation_date降序)

order by P.parental_ib desc nulls last,P.creation_date desc (添加了nulls last會將Null放在最後)

9.有的時候想要對某些數據進行組函數的計算時,可是其餘的不想使用組函數,能夠使用以下:

sum(l.after_tax_payment_amount)over(partition  by  h.INVOICE_NUMBER order by  h.INVOICE_NUMBER )after_tax_payment_amount,

這樣,就能夠按照分組,將數據計算了

相關文章
相關標籤/搜索