达梦数据库与Oracle的兼容性总体来说还是不错的,下面我们来一起探索一下包过程函数的基本功能的实现与一些注意点。
匿名块
结构:
匿名块
Declare (可选项,申请变量)
Begin –开始
Boby;
Exception (可选项,异常处理)
End;
来一个hello world
SQL> set serveroutput on
SQL> begin
2 print(‘hello world’);
3 end;
4 /
hello world
DMSQL 过程已成功完成
已用时间: 0.630(毫秒). 执行号:372.
带参数的过程包
案例:根据员工的编号找出员工所在的部门?
Create or replace procedure ljb.p_emp(BH IN INT)
AS
Dept INT;
BEGIN
Select department_id into dept from employees where employee_id=bh;
Print(dept);
END;
/
SQL> select employee_id from employees;
行号 EMPLOYEE_ID
1 1
2 2
3 3
已用时间: 0.417(毫秒). 执行号:376.
SQL> select department_id from departments;
行号 DEPARTMENT_ID
1 1
2 2
3 3<