数据库连接plsql的问题你了解吗,本站通过大数据汇集了数据库连接plsql的相关解答,希望对你有所帮助。
顺序结构分支结构循环结构
这里我们不用存储过程,先单纯的用PL/SQL做连续,还是oracle pl/sql这本书上的例子
在流程之前普及下PL/SQL中的关系运算符文章连接:
算数运算符
关系运算符
比较运算符
逻辑运算符
这个是简单的顺序流程
这里需要注意是elsif 不是elseif 或者else if
--正确的写法if 条件 then 执行的方法 eslif 条件 then
PL/SQL中的循环大体有三种,loop. while-loop ,for-loop 。这里先展示一个loop
给所有员工按照职位进行加薪

-- loop 循环为员工加薪declare-- constant表示常量,这里我们定义常量常量add_kaifa constant number := 0.20;add_ceshi constant number := 0.10;add_yunwei constant number := 0.10;add_qianduan constant number := 0.15;v_job varchar2(50);--定义游标,游标查询后并不会对表数据进行锁表,如果使用了for update 就会对查询的数据锁表cursor list_job is select job from t_emp for update;begin open list_job;--打开游标 loop fetch list_job into v_job;--提取游标值 exit when list_job%notfound;--当循环到最后一个退出循环 if v_job ='后台开发' then update t_emp te set te.money = te.money*(1+add_kaifa) where current of list_job;--当需要更新或删除被update的数据需使用current of elsif v_job ='测试' then update t_emp te set te.money = te.money*(1+add_ceshi) where current of list_job; elsif v_job='运维' then update t_emp te set te.money = te.money*(1+add_yunwei) where current of list_job; elsif v_job='前段' then update t_emp te set te.money = te.money*(1+add_qianduan) where current of list_job; end if; --输出提示 dbms_output.put_line ('职位为:'||v_job||'的员工加薪成功'); end loop; --异常处理 close list_job;--关闭游标exception when no_data_found then dbms_output.put_line('未找到员工');end;
在PL/SQL中能直接使用DDL语句进行增删查
但是不能直接使用DML语句进行建表等数据库操作,不过我们可以通过变量赋值的方式进行
好了,文章到此结束,希望可以帮助到大家。