Oracle 函數 與 預存程序 的應用

來源:互聯網
上載者:User

函數 與 預存程序 
 
Oracle 資料庫中不僅可以使用 單條語句對資料庫進行增、刪、改、 查 操作,而且可以多條語句組成一個i額語句塊, 並一起執行。  
這些語句塊可以進行顯示命名, 並被其他應用調用。 這些命名的語句塊 被稱為 函數 與 預存程序。  
 
Oracle 中的 自訂函數; 
Oracle 中的 預存程序; 
封裝函數 與 預存程序—程式包。 
 
--  函數  
 
--  函數是 Oracle 中 的常用對象之一,  與 其他編程 語言 函數 一樣,  Oracle 中的函數也必須返回 一個值。 這也是函數 區別  於  預存程序的重要特徵。  
 
-- 函數簡介:   
1. 函數 與 功能的劃分 
2. 函數 的  參數 
3. 函數 的  傳回值 
 
建立 函數 

  1. --1. 建立函數    
  2.   
  3. --create or replace function get_hello_msg return varchar2 as   
  4. --begin   
  5. --  return 'hello world';   
  6. --end get_hello_msg;   
  7. --/   
  8.   
  9. SQL> create or replace function get_hello_msg  
  10.     return varchar2 as  
  11.     begin  
  12.        return 'hello world';  
  13.     end get_hello_msg;  
  14.     /  
  15.   
  16. 函數已建立。  
  17.   
  18.   
  19.   
  20.   
  21. --2. 在資料字典 中  查看函數的資訊  select object_name, object_type, status from user_objects where lower(object_name)='get_hello_msg';   
  22.   
  23. SQL> set linesize 180;  
  24. SQL> select object_name, object_type, status from user_objects where lower(object_name)='get_hello_msg';  
  25.   
  26. OBJECT_NAME                                                                                                              OBJECT_TYPE         STATUS  
  27. ------------------------------------------------------------------------------------------------------------------------------------ --------------   
  28. GET_HELLO_MSG                                                                                                            FUNCTION            VALID  
  29.   
  30.   
  31.   
  32. --3. 查看函數的傳回值   
  33.   
  34. --set serverout on;   
  35. --declare msg varchar2(20);   
  36. --begin   
  37. --  msg := get_hello_msg;   
  38. --  dbms_output_line(msg);   
  39. --end;   
  40. --/   
  41.   
  42. SQL> set serverout on;  
  43. SQL> declare msg varchar2(20);  
  44.     begin msg := get_hello_msg; dbms_output.put_line(msg); end;  
  45.     /  
  46.       
  47. hello world  
  48.   
  49. PL/SQL 過程已成功完成。  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.