Oracle資料庫PL/SQL預存程序遊標觸發器

來源:互聯網
上載者:User

標籤:oracle 預存程序 遊標 觸發器

  1. 建立一個添加FOOD的預存程序


  2. create or replace procedure add_food_pro (name in varchar,price in number,description in varchar)as begininsert into food (f_name,f_price,description)values(name,price,description);commit;end;--下面的代碼是調用預存程序beginadd_food_pro(‘糖醋魚‘,12,‘美味‘);end;

建立一個帶有輸出參數的預存程序,以a+b=c為例

create or replace procedure add_num_pro (a in int,b in int,c out int)as beginc:=a+b;end;--接下來調用預存程序declarec int;begin add_num_pro(10,20,c);dbms_output.put_line(c);end;--注意最後的dbms_output.put_line();--如果想要看到結果,需要在開啟控制台,set serveroutput on

oracle資料庫中遊標的使用

declare  cursor c is select *from employees;  hang employees%rowtype;begin--開啟遊標open c;loop  fetch c into hang;  dbms_output.put_line(‘該員工的姓名是‘||hang.first_name||‘,工資是‘||hang.salary);  exit when c%notfound;end loop;--關閉遊標if c%isopen then close c;end if;end;

建立一個函數

--建立一個函數,可以去掉字串的空格create or replace function noblank1( str varchar)return varcharisbeginreturn replace(str,‘ ‘,‘‘);end;--調用函數select noblank1(‘  dfa d s a ‘) from dual;

建立一個觸發器

--建立一個觸發器create or replace trigger stu_update_tribefore update on studentfor each rowbegindbms_output.put_line(‘某條記錄已經更新,原來的資料是‘||:old.age||‘新的資料是‘||:new.age);end;--觸發觸發器update student set age=21;


本文出自 “Java大白的戰地” 部落格,請務必保留此出處http://8023java.blog.51cto.com/10117207/1669102

Oracle資料庫PL/SQL預存程序遊標觸發器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.