plsql过程语言之uxdb与oracle语法差异

news2025/7/25 10:10:42

序号

场景

uxdb

oracle

1

在存储过程中使用goto子句

create or replace procedure uxdbc_oracle_extension_plsql_goto_0001_procedure01(t1 int)

language plsql

as $$

begin

if t1%2=0 then

goto even_number;

else

goto odd_number;

end if;

<<even_number>>

raise info 'this is a even number';

goto end_lb;

<<odd_number>>

raise info 'this is a odd number';

<<end_lb>>

null;

end;

$$;

call uxdbc_oracle_extension_plsql_goto_0001_procedure01(10);

create or replace procedure uxdbc_oracle_extension_plsql_goto_0001_procedure01(t1 in int)

is

begin

if t1 mod 2 = 0 then

goto even_number;

else

goto odd_number;

end if;

<<even_number>>

dbms_output.put_line('this is a even number');

goto end_lb;

<<odd_number>>

dbms_output.put_line('this is a odd number');

<<end_lb>>

null;

end;

/

call uxdbc_oracle_extension_plsql_goto_0001_procedure01(10);

序号

场景

uxdb

oracle

2

在函数中使用goto子句

create or replace function uxdbc_oracle_extension_plsql_goto_0002_function01(t1 int) returns text

language plsql

returns null on null input

as $$

declare p varchar(30);

begin

if t1%2=0 then

goto even_number;

else

goto odd_number;

end if;

<<even_number>>

p := cast($1 as text) || ' is a even number';

goto end_lb;

<<odd_number>>

p := cast($1 as text) || ' is a odd number';

<<end_lb>>

return p;

end;

$$;

select uxdbc_oracle_extension_plsql_goto_0002_function01(10);

create or replace function uxdbc_oracle_extension_plsql_goto_0002_function01(t1 in int) return varchar

is p varchar(30);

begin

if t1 mod 2 =0 then

goto even_number;

else

goto odd_number;

end if;

<<even_number>>

p := t1 || ' is a even number';

goto end_lb;

<<odd_number>>

p := t1 || ' is a odd number';

<<end_lb>>

return p;

end;

/

select uxdbc_oracle_extension_plsql_goto_0002_function01(10) from dual;

序号

场景

uxdb

oracle

3

在匿名块中使用goto子句

declare t1 int:=7;

begin

if t1%2=0 then

goto even_number;

else

goto odd_number;

end if;

<<even_number>>

raise info 'this is a even number';

goto end_lb;

<<odd_number>>

raise info 'this is a odd number';

<<end_lb>>

null;

end;

/

do language plsql $$

declare t1 int:=10;

begin

if t1%2=0 then

goto even_number;

else

goto odd_number;

end if;

<<even_number>>

raise info 'this is a even number';

goto end_lb;

<<odd_number>>

raise info 'this is a odd number';

<<end_lb>>

null;

end;

$$;

declare t1 int:=10;

begin

if t1 mod 2 =0 then

goto even_number;

else

goto odd_number;

end if;

<<even_number>>

dbms_output.put_line('this is a even number');

goto end_lb;

<<odd_number>>

dbms_output.put_line('this is a odd number');

<<end_lb>>

null;

end;

/

序号

场景

uxdb

oracle

4

标签可以出现在子块前

declare

p text;

n int := 39;

begin

for j in 2..round(sqrt(n)) loop

if n % j = 0 then

p := 'is not a prime number';

goto check_odd;

end if;

end loop;

p := ' is a prime number';

<<check_odd>> --here

begin

raise info '% %',n,p;

if n%2=0 then

p := 'is a even number';

else

p := 'is a odd number';

raise info '% %',n,p;

end if;

end;

end;

/

declare

p varchar(30);

n int := 39;

begin

for j in 2..round(sqrt(n)) loop

if n mod j = 0 then

p := 'is not a prime number';

goto check_odd;

end if;

end loop;

p := ' is a prime number';

<<check_odd>> --here

begin

dbms_output.put_line(n||p);

if n mod 2=0 then

p := 'is a even number';

else

p := 'is a odd number';

dbms_output.put_line(n||p);

end if;

end;

end;

/

序号

场景

uxdb

oracle

5

标签可以出现在if语句之前

declare

p text;

n int := 39;

begin

for j in 2..round(sqrt(n)) loop

if n % j = 0 then

p := 'is not a prime number';

goto check_odd;

end if;

end loop;

p := ' is a prime number';

raise info '% %',n,p;

<<check_odd>> --here

if n%2=0 then

p := 'is a even number';

else

p := 'is a odd number';

end if;

raise info '% %',n,p;

end;

/

declare

p varchar(30);

n int := 39;

begin

for j in 2..round(sqrt(n)) loop

if n mod j = 0 then

p := 'is not a prime number';

goto check_odd;

end if;

end loop;

p := ' is a prime number';

dbms_output.put_line(n||p);

<<check_odd>> --here

if n mod 2=0 then

p := 'is a even number';

else

p := 'is a odd number';

end if;

dbms_output.put_line(n||p);

end;

/

序号

场景

uxdb

oracle

6

goto语句可以从一个子if语句跳到父if语句中

declare i int :=7;

begin

if i != 0 then

if i > 0 then

raise info 'is zhengshu.';

goto lb;

else

raise info 'is fushu.';

end if;

<<lb>>

raise info 'outer';

else

raise info 'is 0.';

end if;

end;

/

declare i int :=7;

begin

if i != 0 then

if i > 0 then

dbms_output.put_line('is zhengshu.');

goto lb;

else

dbms_output.put_line('is fushu.');

end if;

<<lb>>

dbms_output.put_line('outer');

else

dbms_output.put_line('is 0.');

end if;

end;

/

序号

场景

uxdb

oracle

7

goto语句可以将控制转移出if判断语句

create table uxdbc_oracle_extension_plsql_goto_0031_table01(id int, name varchar(10),job varchar(10),hiredate date);

insert into uxdbc_oracle_extension_plsql_goto_0031_table01 values (120, 'Weiss','shouyin','2020-09-01');

insert into uxdbc_oracle_extension_plsql_goto_0031_table01 values (121, null,'daogou','2021-05-05');

insert into uxdbc_oracle_extension_plsql_goto_0031_table01 values (122, 'Weiss2',null,'2019-01-10');

insert into uxdbc_oracle_extension_plsql_goto_0031_table01 values (123, 'Weiss3','qingjie',null);

create or replace procedure uxdbc_oracle_extension_plsql_goto_0031_procedure01 (v_id int)

language plsql

as $$

declare v_name varchar(10);

v_job varchar(10);

v_hiredate varchar(10);

begin

select name, job, hiredate into v_name, v_job, v_hiredate from uxdbc_oracle_extension_plsql_goto_0031_table01 where id = v_id;

if v_name is null then

goto invalid_emp;

end if;

if v_job is null then

goto invalid_emp;

end if;

if v_hiredate is null then

goto invalid_emp;

end if;

raise info 'this is a validated without errors.';

<<invalid_emp>>

raise info 'this is not a valid employee.';

end;

$$;

call uxdbc_oracle_extension_plsql_goto_0031_procedure01(120);

call uxdbc_oracle_extension_plsql_goto_0031_procedure01(121);

create table uxdbc_oracle_extension_plsql_goto_0031

_table01(id int, name varchar(10),job varchar(10),hiredate date);

insert into uxdbc_oracle_extension_plsql_goto_0031_table01 values (120, 'Weiss','shouyin',to_date('2020-09-01','YYYY-MM-DD'));

insert into uxdbc_oracle_extension_plsql_goto_0031_table01 values (121, null,'daogou',to_date('2021-05-05','YYYY-MM-DD'));

insert into uxdbc_oracle_extension_plsql_goto_0031_table01 values (122, 'Weiss2',null,to_date('2019-01-10','YYYY-MM-DD'));

insert into uxdbc_oracle_extension_plsql_goto_0031_table01 values (123, 'Weiss3','qingjie',null);

create or replace procedure uxdbc_oracle_extension_plsql_goto_0031_procedure01 (v_id int)

is v_name varchar(10);

v_job varchar(10);

v_hiredate varchar(10);

begin

select name, job, hiredate into v_name, v_job, v_hiredate from uxdbc_oracle_extension_plsql_goto_0031_table01 where id = v_id;

if v_name is null then

goto invalid_emp;

end if;

if v_job is null then

goto invalid_emp;

end if;

if v_hiredate is null then

goto invalid_emp;

end if;

dbms_output.put_line('this is a validated without errors.');

<<invalid_emp>>

dbms_output.put_line('this is not a valid employee.');

end;

/

call uxdbc_oracle_extension_plsql_goto_0031_procedure01(120);

call uxdbc_oracle_extension_plsql_goto_0031_procedure01(121);

序号

场景

uxdb

oracle

8

case语句

declare

season int;

temperature int;

begin

season:=20;

temperature:=38;

case season

when 10 then

raise info 'spring';

when 20 then

raise info 'summer';

goto temp_start;

when 30 then

raise info 'autumn';

when 40 then

raise info 'winter';

else

raise info 'is invalid season';

end case;

<<temp_start>>

case

when temperature>30 then

raise info 'so hot';

when temperature>15 then

raise info 'so comfortable';

else

raise info 'so cold';

end case;

end;

/

declare

season int;

temperature int;

begin

season:=20;

temperature:=38;

case season

when 10 then

dbms_output.put_line('spring');

when 20 then

dbms_output.put_line('summer');

goto temp_start;

when 30 then

dbms_output.put_line('autumn');

when 40 then

dbms_output.put_line('winter');

else

dbms_output.put_line('is invalid season');

end case;

<<temp_start>>

case

when temperature>30 then

dbms_output.put_line('so hot');

when temperature>15 then

dbms_output.put_line('so comfortable');

else

dbms_output.put_line('so cold');

end case;

end;

/

序号

场景

uxdb

oracle

9

goto语句可以从exception中跳转到父块中

declare i int :=0;

begin

<<LB1>>

i := i + 1;

raise info '%',i;

begin

<<LB2>>

if i =1 then

raise exception numeric_value_out_of_range;

else

raise exception division_by_zero;

end if;

exception

when numeric_value_out_of_range then

goto LB1;

when division_by_zero then

raise info 'division_by_zero';

when others then

raise info 'error';

end;

end;

/

declare i int :=0;

numeric_value_out_of_range exception;

division_by_zero exception;

begin

<<LB1>>

i := i + 1;

dbms_output.put_line(i);

begin

<<LB2>>

if i =1 then

raise numeric_value_out_of_range;

else

raise division_by_zero;

end if;

exception

when numeric_value_out_of_range then

goto LB1;

when division_by_zero then

dbms_output.put_line('division_by_zero');

when others then

dbms_output.put_line('error');

end;

end;

/

序号

场景

uxdb

oracle

10

goto语句在内外循环之间跳转,最后跳出嵌套循环

declare

s int := 0;

i int := 0;

j int;

begin

<<outer_loop>>

loop

i := i + 1;

j := 0;

<<inner_loop>>

loop

j := j + 1;

s := s + i * j;

if j<=5 then

goto inner_loop;

elsif (i * j) <= 15 then

goto outer_loop;

else

goto end_loop;

end if;

end loop inner_loop;

end loop outer_loop;

<<end_loop>>

raise info 'end_loop';

raise info 'The sum of products equals:% ',s;

end;

/

declare

s int := 0;

i int := 0;

j int;

begin

<<outer_loop>>

loop

i := i + 1;

j := 0;

<<inner_loop>>

loop

j := j + 1;

s := s + i * j;

if j<=5 then

goto inner_loop;

elsif (i * j) <= 15 then

goto outer_loop;

else

goto end_loop;

end if;

end loop inner_loop;

end loop outer_loop;

<<end_loop>>

dbms_output.put_line('end_loop');

dbms_output.put_line('The sum of products equals: '||s);

end;

/

序号

场景

uxdb

oracle

11

如果goto语句过早地退出游标for loop语句,游标将关闭

create table uxdbc_oracle_extension_plsql_goto_0047_table01(id int, name varchar(10),job varchar(10));

insert into uxdbc_oracle_extension_plsql_goto_0047_table01 values (120, 'Weiss','shouyin');

insert into uxdbc_oracle_extension_plsql_goto_0047_table01 values (121, 'Weiss1','daogou');

insert into uxdbc_oracle_extension_plsql_goto_0047_table01 values (122, 'Weiss2','kuaiji');

insert into uxdbc_oracle_extension_plsql_goto_0047_table01 values (123, 'Weiss3','qingjie');

declare

p varchar(10);

c cursor for select id,name,job from uxdbc_oracle_extension_plsql_goto_0047_table01;

begin

for v in c loop

raise info '%---%---%', v.id,v.name,v.job;

if v.id=120 then

goto end_loop;

end if;

end loop;

<<end_loop>>

raise info 'end_loop,cursor close';

end;

/

create table uxdbc_oracle_extension_plsql_goto_0047_table01(id int, name varchar(10),job varchar(10));

insert into uxdbc_oracle_extension_plsql_goto_0047_table01 values (120, 'Weiss','shouyin');

insert into uxdbc_oracle_extension_plsql_goto_0047_table01 values (121, 'Weiss1','daogou');

insert into uxdbc_oracle_extension_plsql_goto_0047_table01 values (122, 'Weiss2','kuaiji');

insert into uxdbc_oracle_extension_plsql_goto_0047_table01 values (123, 'Weiss3','qingjie');

declare

p varchar(10);

v_id int;

v_name varchar(10);

v_job varchar(10);

cursor c is select id,name,job from uxdbc_oracle_extension_plsql_goto_0047_table01;

begin

open c;

fetch c into v_id,v_name,v_job;

dbms_output.put_line(v_id||'---'||v_name||'---'||v_job);

if v_id=120 then

goto end_loop;

end if;

<<end_loop>>

close c;

dbms_output.put_line('end_loop,cursor close');

end;

/

序号

场景

uxdb

oracle

12

函数递归调用

create or replace function uxdbc_oracle_extension_plsql_goto_0053_function01(x number) returns number

language plsql

as $$

declare f number;

begin

if x=0 then

f := 1;

else

goto lb_digui;

end if;

<<lb_digui>>

f := x * uxdbc_oracle_extension_plsql_goto_0053_function01(x-1);

return f;

end;

$$;

select uxdbc_oracle_extension_plsql_goto_0053_function01(5);

create or replace function uxdbc_oracle_extension_plsql_goto_0053_function01(x number) return number

is f number;

begin

if x=0 then

f := 1;

else

goto lb_digui;

end if;

<<lb_digui>>

f := x * uxdbc_oracle_extension_plsql_goto_0053_function01(x-1);

return f;

end;

/

select uxdbc_oracle_extension_plsql_goto_0053_function01(5) from dual;

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/368356.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

LAMP平台部署及应用

LAMP平台部署及应用 &#x1f4d2;博客主页&#xff1a; 微笑的段嘉许博客主页 &#x1f4bb;微信公众号&#xff1a;微笑的段嘉许 &#x1f389;欢迎关注&#x1f50e;点赞&#x1f44d;收藏⭐留言&#x1f4dd; &#x1f4cc;本文由微笑的段嘉许原创&#xff01; &#x1f4c…

117.Android 简单的拖拽列表+防止越界拖动(BaseRecyclerViewAdapterHelper) 两种方式实现

//一.第一种方式 通过BaseItemDraggableAdapter类和其提供的的拖拽监听实现&#xff1a; //1.第一步 导入依赖库和权限&#xff1a; //依赖库&#xff1a; //RecyclerView implementation com.android.support:recyclerview-v7:28.0.0//RecyclerAdapter implementation com.…

WAF:ModSecurity on Nginx(15)

预备知识 Nginx概述 Nginx ("engine x") 是一个高性能的HTTP和 反向代理 服务器&#xff0c;也是一个 IMAP/POP3/SMTP服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的&#xff0c;第一个公开版本0.1.0发布于2004年10月4日。其将源代…

Mysql的函数GROUP_CONCAT和FIND_IN_SET

业务场景&#xff1a; 表A&#xff1a;存在 customer_phone&#xff1b;bac_id主键 表B&#xff1a;存在 主键id&#xff1b;bac_id字段 customer_phone:用户手机号&#xff1b; bac_id:主键 表A &#xff1a;每个手机号可能会对应多个主键&#xff1b;要查询每个客户手机号包…

我该怎么选择IB课程?

IB用6大学科组及3大课程核心构建知识体系&#xff0c;涵盖广博、注重知行合一&#xff0c;对学生的综合素质的提升以及综合竞争力的打造都十分有益。IB选课建议 六大学科组中的每个课程分为HL&#xff08;高难度&#xff09;和SL&#xff08;标准水平&#xff09; HLIB课程&…

「RISC-V Arch」SBI 规范解读(上)

术语 SBI&#xff0c;Supervisor Binary Interface&#xff0c;管理二进制接口 U-Mode&#xff0c;User mode&#xff0c;用户模式 S-Mode&#xff0c;Supervisor mode&#xff0c;监督模式 VS-Mode&#xff0c;Virtualization Supervisor mode&#xff0c;虚拟机监督模式 …

三菱FX3U与威纶MT8071IP走RS422通讯

一、准备工作 1.需要工具&#xff1a; 电脑一台、PLC&#xff1a;三菱FX3U一个、触摸屏&#xff1a;威纶MT8071一个、 &#xff08;三菱圆形编程口转USB&#xff09;一根、触摸屏与电脑通讯线一根&#xff08;T型口数据线&#xff09;、PLC与触摸屏通讯线&#xff1a;电烙…

谷歌搜索留痕的技术公式【2023年新版】

本文主要分享谷歌搜索留痕的技术公式&#xff0c;让你更简单的去学习谷歌留痕的技术原理 本文由光算创作&#xff0c;有可能会被修改和剽窃&#xff0c;我们佛系对待这样的行为吧。 谷歌搜索留痕的技术公式是什么&#xff1f; 答案是&#xff1a;需要做排名的关键词海量能搜…

Apache Hadoop生态部署-hadoop单机安装

目录 查看服务架构图-服务分布、版本信息 1&#xff1a;安装包下载 2&#xff1a;配置环境变量 3&#xff1a;服务配置 &#xff08;1&#xff09;core-site.xml &#xff08;2&#xff09;配置 hadoop-env.sh &#xff08;3&#xff09;HDFS 配置文件hdfs-site.xml &a…

【Redis】数据库和缓存如何保证一致性?

【Redis】数据库和缓存如何保证一致性&#xff1f; 文章目录【Redis】数据库和缓存如何保证一致性&#xff1f;常见方案先更新缓存&#xff0c;再更新数据库先更新数据库&#xff0c;再更新缓存并发情况下的思考先删除缓存&#xff0c;再更新数据库先更新数据库&#xff0c;再删…

StopWatch计时器

前言 开发中&#xff0c;为了评估性能&#xff0c;我们通常会使用System.currentTimeMillis() 去计算程序运行耗时 long startTimeSystem.currentTimeMillis();//业务代码... long endTimeSystem.currentTimeMillis(); System.out.println("耗时:" (endTime-startT…

Java多线程(三)---synchronized、Lock和volatile

Java内存模型&#xff08;非JVM&#xff09;Java内存模型(Java Memory Model简称JMM)&#xff0c;是一种共享内存模型&#xff0c;是多线程的东西&#xff0c;并不是JVM&#xff08;Java Virtual Machine(Java虚拟机)的缩写&#xff09;&#xff0c;这是俩玩意儿&#xff01;&a…

Ubuntu 22.04.2 发布,可更新至 Linux Kernel 5.19

Ubuntu 22.04 LTS (Jammy Jellyfish) Ubuntu 22.04.2 发布&#xff0c;可更新至 Linux Kernel 5.19 请访问原文链接&#xff1a;Ubuntu 22.04 LTS (Jammy Jellyfish)&#xff0c;查看最新版。原创作品&#xff0c;转载请保留出处。 作者主页&#xff1a;www.sysin.org 发行说…

ssh远程登录报错:kex_exchange_identification: Connection closed by remote host

基本信息系统&#xff1a;MacOS Catalina 10.15.7报错信息&#xff1a;终端登录远程服务器时报错&#xff1a;kex_exchange_identification: Connection closed by remote host复制然而服务商的一键登录或VNC登录正常。解决方案首先使用以下命令debug登录过程&#xff0c;以便定…

这可能是Spring Boot Starter 讲的最清楚的一次了

前面我们简单介绍了如何使用消息中间件Apache Pulsar&#xff0c;但是在项目中那样使用&#xff0c;显然是不太好的&#xff0c;不管从易用性和扩展性来看&#xff0c;都是远远不够&#xff0c; 为了和springboot项目集成&#xff0c;写一个pulsar-spring-boot-starter是非常有…

Linux核心技能:2023主流监控Prometheus详解,附官方可复制中文文档教程

Prometheus既是一个时序数据库&#xff0c;又是一个监控系统&#xff0c;更是一套完备的监控生态解决方案。作为时序数据库&#xff0c;目前Prometheus已超越了老牌的时序数据库OpenTSDB、Graphite、RRDtool、KairosDB等&#xff0c;如图所示。 &#xff08;来源网络&#xff0…

QT+OpenGL鼠标操作和模型控制

文章目录QTOpenGL鼠标操作和模型控制鼠标拾取理论有点小复杂从鼠标计算射线第 0 步&#xff1a;2D 视口坐标第 1 步&#xff1a;3d归一化设备坐标第 2 步&#xff1a;4d齐次剪辑坐标第 3 步&#xff1a;4d眼(相机)坐标第 4 步&#xff1a;4d 世界坐标代码展示模型控制多模型加载…

自动执行自动化测试用例

phpunit 接口自动化测试系列 所有自动化测试用例最终的目的都是一样的&#xff0c;实现无人值守的自动化运行。而目前最常用的就是Jenkins来实现这个功能&#xff0c;在前面的WebdriverPython页面自动化的教程中我们已经详细讲解了如何将自动化测试用例接入到Jenkins中。本章我…

RK系列(RK3568) i2s 音频输入 麦克风驱动

平台&#xff1a;Android12SOC&#xff1a;RK3568外围芯片&#xff1a;XS9922i2s简介&#xff1a;从上图看I2s主要的线有&#xff1a;SDO SCLK LRCK MCLK I2S协议只定义三根信号线&#xff1a;串行时钟信号SCLK(BCLK)、数据信号SD和左右声道选择信号WS。&#xff08;1&#xff…

QT入门Containers之QStackedWidget

目录 一、QStackedWidget界面相关 1、布局介绍 2、插入界面 3、插入类界面 二、Demo展示 此文为作者原创&#xff0c;创作不易&#xff0c;转载请标明出处&#xff01; 一、QStackedWidget界面相关 1、布局介绍 QStackedWidget这个控件在界面布局时&#xff0c;使用还…