IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

Oracle(变量定义、接收用户输入、if语句、循环语句)

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

PL/SQL(Procedure Language/SQL):是Oracle对sql语言的过程化扩展,在SQL语言的基础上增加了过程处理语言(分支、循环等),使得SQL语言具有过程处理能力,它是一种面向过程的语言。·

1、实现过程

declare:开头,后面是说明部分

说明部分:定义变量、光标申明、例外说明

程序:begin开始

dbms_output:存储过程(存储函数)

end:结束

2、打印Hello World

(1)书写程序:

99_1.png

(2)打开数据库开关并运行重新:

99_2.png

(3)在PL/SQL中运行:

99_3.png

99_4.png

3、定义引用型变量和变量的赋值

(1)引用型变量的定义:

pename emp.ename%type;
psal emp.sal%type;

例如:第一句话的意思是定义变量pename,该变量的数据类型和emp表的ename属性的数据类型保持一致。

(2)变量的赋值:

select ename,sal into pename,psal from emp where empno='7369';

将查询的的ename和sal的值分别赋值给变量pename和psal。

(3)程序:

declare 
pename emp.ename%type;
psal emp.sal%type;
begin
select ename,sal into pename,psal from emp where empno='7369';
dbms_output.put_line(pename||'的薪水是'||psal);
end;

99_5.png

4、记录型变量

(1)定义记录型变量:

emp_rec emp%rowtype;

(2)程序:

declare 
emp_rec emp%rowtype;
begin
select * into emp_rec from emp where empno='7369';
dbms_output.put_line(emp_rec.ename||'的薪水是'||emp_rec.sal);
end;

99_6.png

5、 if语句、接收用户输入:

(1)接收用户输入:

accept num prompt '请输入一个数字';

(2)if语句:

begin
  if pnum = 0 then dbms_output.put_line('您输入的数字是0');
    elsif pnum = 1 then dbms_output.put_line('您输入的数字是1');
      elsif pnum = 2 then dbms_output.put_line('您输入的数字是2');
        else dbms_output.put_line('您输入的是其他数字');
        end if;
end;

(3)完整程序:

set serveroutput on
accept num prompt '请输入一个数字';
declare 
pnum number :=#
begin
  if pnum = 0 then dbms_output.put_line('您输入的数字是0');
    elsif pnum = 1 then dbms_output.put_line('您输入的数字是1');
      elsif pnum = 2 then dbms_output.put_line('您输入的数字是2');
        else dbms_output.put_line('您输入的是其他数字');
        end if;
end;
/

6、循环语句

(1)while:

输出1-10:

declare
step number :=1;
begin
while step<=10
loop
dbms_output.put_line(step);
step:=step+1;
end loop;
end;

(2)for:

declare
step number :=1;
begin
for step in 1..10 loop
dbms_output.put_line(step);
end loop;
end;

文章永久链接:https://tech.souyunku.com/?p=22382


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(93) 打赏



未经允许不得转载:搜云库技术团队 » Oracle(变量定义、接收用户输入、if语句、循环语句)

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367