oracle触发器及异常处理 简单例子
2024-08-26 18:32:05
- create sequence person_seq
- start with 1
- increment by 1
- order --按顺序
- nocycle --不循环不重复
- ;
- insert into person values(person_seq.nextval,null,'iteye);
- delete from person;
- update person set user_name ='zwllxs6' where id = 3;
- ---触发器
- create or replace trigger person_tr before insert or update or delete on person
- for each row
- Declare
- can_not_update_exception EXCEPTION;
- begin
- dbms_output.put_line('testest');
- if inserting then
- dbms_output.put_line('inserting');
- end if;
- if updating then
- dbms_output.put_line('updating');
- dbms_output.put_line('old: '||:old.user_name);
- dbms_output.put_line('new: '||:new.user_name);
- if(:old.user_name<>:new.user_name) then
- dbms_output.put_line('不一样,不能更新');
- Raise_application_error(-20000,'不一样,不能更新');
- end if;
- end if;
- if deleting then
- dbms_output.put_line('deleting');
- end if;
- end;
- Class.forName("oracle.jdbc.driver.OracleDriver");
- Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl", "scott", "******");
- // 创建状态
- Statement stmt = conn.createStatement();
- // 执行SQL语句,返回结果集
- ResultSet rs = stmt.executeQuery("SELECT * FROM person");
- while (rs.next()) {
- int id = rs.getInt("id");
- String userName = rs.getString("user_name");
- System.out.println("id: "+id);
- System.out.println("userName: "+userName);
- }
- int num=stmt.executeUpdate("update person set user_name ='zwllxs5' where id = 3");
- System.out.println("num: "+num);
最新文章
- C#图像处理笔记
- js设置鼠标悬停改变背景色
- 30秒懂SQL中的join(2幅图+30秒)
- 十二天 mysql操作
- [工作中的设计模式]迭代子模式Iterator
- class的使用
- 终于成功仿了一次Kalman滤波器
- cdoj 1253 阿里巴巴和n个大盗 博弈论
- textarea中的文字自动换行问题
- codeforces 652E Pursuit For Artifacts 边双连通分量
- SpringMVC 之文件上传 MultipartResolver
- android 广播分类
- hdu 5532 Almost Sorted Array(模拟)
- HTML-滚动字幕的源代码(可作滚动公告)
- 【复习】VueJS之内部指令
- Python“函数式编程”中常用的函数
- UVA10384-The Wall Pushers(迭代加深搜索)
- Java笔试面试题整理第一波
- java使用elasticsearch进行模糊查询之must使用-项目中实际使用
- page = new String(request.getQueryString().getBytes(";ISO-8859-1";),";GBK";);解决前台传后台乱码问题