当前位置:网站首页>Stored procedure trial 2 -- establish a test table to test different types of stored procedures
Stored procedure trial 2 -- establish a test table to test different types of stored procedures
2022-07-27 08:02:00 【Shenzhi Kalan Temple】
The previous article recorded the basic knowledge points of stored procedures https://mochou.blog.csdn.net/article/details/116503996, This article tries different types of stored procedures by establishing test tables
-- ************* Build a test table
CREATE TABLE szsz.produre_test_table(
ID1 INTEGER PRIMARY KEY,
NAME1 VARCHAR2(50),
num1 INTEGER,
bz VARCHAR2(50)
);
SELECT * FROM produre_test_table
-- ************** Parameterless stored procedure
CREATE OR REPLACE PROCEDURE testMyProcedure AS
n_num NUMBER(10);
v_car VARCHAR2(50);
BEGIN
SELECT COUNT(*) INTO n_num FROM products;
v_car := 'Geely';
DBMS_OUTPUT.put_line(v_car || ' The number is ' || n_num);
INSERT INTO produre_test_table VALUES(1,v_car,n_num,'T');
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
INSERT INTO produre_test_table VALUES(101,'testMyProcedure',0,'F');
RAISE;
END;
-- Run stored procedures EXECUTE szsz.testMyProcedure;
BEGIN
szsz.testMyProcedure;
END;
-- ************** Parameterized stored procedures
create or replace procedure test_procedure1(v_name in VARCHAR2,d_date OUT DATE) as
v_name1 varchar2(10);
n_num NUMBER(32);
begin
v_name1 := v_name;
SELECT COUNT(*) INTO n_num FROM products;
IF n_num > 1 THEN
d_date :=SYSDATE;
ELSIF N_NUM = 0 THEN
d_date := '1970-01-01 00:00:00';
END IF;
dbms_output.put_line(' name :' || v_name1||', Age :' || n_num||', Time :' || d_date);
INSERT INTO produre_test_table VALUES(3,V_NAME1,N_NUM,'F');
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
INSERT INTO produre_test_table VALUES(102,'test_procedure1',0,'F');
RAISE ;
end;
-- In the parameter in For input
-- || Connection string
-- The parameter does not need to write the specific type size
-- perform
DECLARE
test1 DATE;
begin
test_procedure1('zs',test1);
end;
-- ************** stored procedure - The cursor
CREATE OR REPLACE PROCEDURE cur_procedure(id1 NUMBER) AS
v_name VARCHAR2(50);
n_NUM NUMBER(10);
CURSOR cur IS SELECT ID1,NAME1,num1 FROM produre_test_table;
BEGIN
SELECT COUNT(1) INTO n_Num FROM produre_test_table;
IF n_num > 1 THEN
FOR RES IN cur LOOP
dbms_output.put_line(' name :' || RES.NAME1 ||', Age :' || RES.NUM1||' !!!');
UPDATE produre_test_table A SET A.ID1 = RES.ID1+1000;
END LOOP;
END IF;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
INSERT INTO produre_test_table VALUES(103,'cur_procedure',0,'F');
RAISE ;
end;
-- perform
BEGIN
cur_procedure(100);
END;
边栏推荐
- Happy holidays, everyone
- SETTA 2020 国际学术会议即将召开,欢迎大家参加!
- 【已解决】新版Pycharm(2022)连接服务器进行上传文件报错“Command rsync is not found in PATH”,无法同步文件
- Hu related configuration
- Can Linux install sqlserver
- Lua iterator
- How to obtain the cash flow data of advertising services to help analyze the advertising effect?
- 这次龙蜥展区玩的新花样,看看是谁的 DNA 动了?
- An ordinary autumn recruitment experience
- SQL labs SQL injection platform - level 1 less-1 get - error based - Single Quotes - string (get single quote character injection based on errors)
猜你喜欢

On data security

擎创科技加入龙蜥社区,共建智能运维平台新生态

Digital transformation driven by enterprise architecture!

How to update PIP3? And running PIP as the 'root' user can result in broken permissions and conflicting behavior

DEMO SUBMIT 某程序并获取该程序ALV数据

如何在 60 秒内去分析和定位问题?
![[resolved] the new version of pychart (2022) connects to the server to upload files and reports an error of](/img/13/573d8ae55eb25580a5628b469dfab3.png)
[resolved] the new version of pychart (2022) connects to the server to upload files and reports an error of "command Rsync is not found in path", and the files cannot be synchronized

C# 事件用法案例 订阅事件+=

An ordinary autumn recruitment experience

Applet payment management - new payment docking process
随机推荐
C语言:随机生成数+插入排序
杂谈:手里有竿儿,肩上有网,至于背篓里有多少鱼真的重要吗?
Dasctf2022.07 enabling game password WP
Regular and sed exercises
[stonedb class] introductory lesson 1: popular science of database knowledge
Harbor can't log in with the correct password
Lua有状态迭代器
C language: random number + Hill sort
The dragon lizard exhibition area plays a new trick this time. Let's see whose DNA moved?
【万字长文】吃透负载均衡,和阿里大牛的技术面谈
C语言:随机生成数+希尔排序
Dormitory access control system made by imitating the boss (III)
Debug: generic related "unresolved external symbols"
C#winform 窗体事件和委托结合用法
How to log in multiple wechat on the computer
End of year summary
CommonTitleBar hide left right
Demo:pa30 Bank Country Code default CN enhancement
Shell loop exercise
What about idea Chinese garbled code