oracle+plsql+command,Oracle总结之plsql编程(基础七)

紧接基础六,对oracle角色和权限的管理之后,在接下来的几次总结中来就最近工作中用过的plsql编程方面的知识进行总结,和大家分享!

原创作品,转自请注明出处:https://www.cnblogs.com/sunshine5683/p/10296531.html

一、plsql块

1、只包括执行部分的plsql块

打开输出选项:set serveroutput on;

begin

dbms_output.put_line('');

end;

18587e2b7684d5a1fffac6bb6e4e4af1.png3669573

如上,只有打开了serveroutput才可以看到输出信息。

2、包含定义部分和执行部分的plsql块

declare

v_name  varchar2(5);--定义字符串变量

begin

select ename into v_name from emp where empno=&no;

dbms_output.put_line(‘雇员们’||v_name);

end

d2a79561c000b76609cb3c0b1ef826b2.png3669573

输入编号,OK

c730d41a6cc4232fbae070d1d893c597.png3669573

3、包含定义部分、执行部分、例外处理部分的plsql块(即完整的plsql块)

在通常的plsql块中,难免会遇到执行中的错误,然后再编写的过程中应该尽量对可能出现的异常进行处理,所以这种情况下异常处理就显得格外重要。

declare

v_name  varchar2(5);--定义字符串变量

begin

select ename into v_name from emp where empno=&no;

dbms_output.put_line(‘雇员们’||v_name);

exception

when no_data_found then

dbms_output.put_line('输入有误');

end

下面实例就是当输入的编号不存在时,不会保存,输出提示“输入有误”!

c3ebdf165f2388bb51335bd8649e51ef.png3669573

4、创建存储过程

create procedure sp_test1(spName varchar2, newsal number)is

begin

update scott.emp set sal=newsal where ename=spName;

end;

3c8d3afdf1f8bed67fba2a6c9ef0880e.png3669573

调用该存储过程

a50ee45440bca43067f680343c4915fb.png3669573

由上图可以看到调用存储过程前后的变化

二、使用java调用存储过程

1 //使用java调用oracle中的存储过程2 //注意要引入oracle的jar包classes12.jar

3 packagexhq.test;4 import java.sql.*;5 public classTestOracleProcedure{6 public static voidmain(String [] args){7 try{8 //1、加载驱动

9 Class.forName("oracle.jdbc.driver.OracleDriver");10 //2、得到连接

11 Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","user","password");12 //创建CallableStatement

13 CallableStatement cs = conn.prepareCall("{call sp_test1(?,?)}");14 //给?赋值

15 cs.setString(1,"SMITH");16 cs.setInt(2,10);17 //执行

18 cs.execute();19 //关闭

20 cs.close();21 conn.close();22 }catch(Exception e){23 e.printStackTrace();24 }25 }26 }

今天总结到此结束,下次接着继续总结!

d49395b0aba05d8cb3a9dfee972aaf28.png

3669573

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
32位版本的 PLSQL 正式版。 安装请查看说明。 APRIL 17, 2020 - VERSION 14.0 RELEASED Built-in Version Control support for Git and Subversion For these file control operations PL/SQL Developer relies on a 3rd party shell extension that must be installed on your system. In the screenshots above “GIT Extensions” has been used. Worksets A workset is a set of Program Windows, SQL Windows, Test Windows, Command Windows, Report Windows and Diagram Windows that you are working on. Internal difference viewer The new viewer allows you to ignore differences in case and white space as usual, but it can also ignore differences in comments. Program Window enhancements The Program Window now highlights transaction statements, so that you can visually recognize the code that affects a transaction. As soon as you place the cursor on a transaction statement, all related statements within a program unit will be highlighted Debugger enhancements A variable name and value can now be copied to the clipboard through the new “Copy variable” popup menu item. Editor enhancements A function key “Editor: Refresh Code Assistant” has been added, to bring the Code Assistant up to date after creating new database objects. When selecting a word, all matching words will be highlighted. Marked editor text is automatically copied to the search field of the Find function. SQL Window enhancements You can now display multiple result sets simultaneously and can compare them: CLOBs and BLOBs are now fetched on demand to improve query performance. Single record view will now show column comments if available. The EXCEL and CSV export filenames can now include substitution variable values. The EXCEL and CSV export filenames can now include %time%, %hh%, %mi% and %ss% variables. For the “Export Results as SQL file” function you can now customize the initialization and finalization. The WITH_PLSQL hint is now supported. Command Window enhancements New EXPORT TABLES and EXPORT OBJECTS commands have been added. This allows you to automate frequent export jobs. You can easily build the command-line from the interactive export tools. The BEAUTIFY <file> command now supports wildcards. The CONNECT command now shows the database list after typing @. The WITH_PLSQL hint is now supported. Object Browser enhancements The Object Browser will now show all overloaded versions of functions and procedures. You can now filter on multiple comma-separated object names (e.g. “dept%, emp%”). You can now refresh materialized views from the popup menu. File Browser enhancements Git and Subversion support has been added. File icons now indicate the PL/SQL Developer file type. You can now filter files based on the name, size, date, read-only status, and version control status. You can specify the filter in the options dialog You also can enter the filter expression directly at the top of the File Browser All windows shell functions are now available from the popup menu. You can now create a specific PL/SQL Developer file type from the “Create File” popup menu item. You can now add multiple files to a project at once. Project enhancements Git and Subversion support has been added. File icons now indicate the PL/SQL Developer file type. Table Definition Editor enhancements The Index and Partition storage can now be edited, copied, and pasted directly in the grid. Support for Row Archival has been added. Test Manager enhancements You can now add multiple Test Script files at once. You can now drag & drop Test Script files from the File Browser. You can now enable or disable multiple items at once. Connection List enhancements Window icons now indicate the PL/SQL Developer window type. Connection status icon moved to the left for consistency. Session Window enhancements You can now define Session Actions that can be performed from the popup menu of the session list: Session Actions can display feedback by writing dbms_output. Other enhancements Function keys have been added for “Search Bar” functions (Focus, Search, Go to next, Go to previous). Substitution variable checkbox and list values can now refer to other variable values as &variable. An “Unregister License” function has been added. Fixes Fixes for multiple monitors with different display scaling (file selector, print dialogs, MDI window title bars, scrollbar width) Conditional sections could be displayed incorrectly in the Code Contents Define Connections and Select Connection tree was incorrect on a secondary display with different DPI settings Menu items with icons from templates were too small on high dpi monitors Ribbon / Menu customization form options were not preserved Editors with a right margin and wrapping enabled did not wrap at the right margin View Stack Dump function now places the error lines in center of the editor Connection matches did not process proxy user expressions (user1[user2]@database) correctly for the application background DBMS_Jobs could not be edited on Oracle19 (‘xxxx’ is not a valid

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值