存储过程只能创建或者替换,不能修改,因此语法定义为 create [or replace]

存储过程的demo和两种调用方式

create or replace PROCEDURE 过程名(参数表)
as PLSQL子程序体;
as 相当于PL/SQL程序中的declare,as不可省略,后面跟说明部分,定义光标变量之类的。
3.如何调用存储过程:
create or replace PROCEDURE sayhello as
begin
dbms_output.put_line('HELLO WORLD');
end;
3.1.调用存储过程:
execute sayhello;
可简写为 exec sayhello;
3.2.通过PLP/SQL 程序调用
BEGIN
sayhello();
sayhello();
END;
调用存储过程
1、exec sayhelloworld();
2、begin
存储过程名();
end;
存储过程调用方式:
1、exec pro_name();
2、 begin
pro_name();
end;
/
create or replace 存储过程
存储过程和存储函数的共同点:完成特定功能的sql语句。
区别:是否有return 返回函数值。
第一个存储过程:打印Hello World
--创建存储过程
create or replace procedure sayHello
as
--说明部分
begin
dbms_output.put_line("Hello World!");
end;
/
// 调用存储过程:在DOS窗口下运行,两种方式
1、exec sayHelloWorld();
2、begin
sayHelloWorld();
sayHelloWorld();
end;
/
创建存储过程语法
第一个存储过程
创建和使用存储过程
创建存储过程语法:如图。注意:存储过程只能创建或者替换,不能修改,如果要修改就使用replace,它的意思是指如果创建时有相同的存储过程就替换该存储过程。其中AS代表声明(变量、光标)。
举例:通过存储过程,打印Hello World。注意:在讲解PL/SQL时,如果没有声明部分,那么可以不写declare部分,但是在存储过程中AS是不能省略的,即使没有声明。Oracle数据库存储数据库对象默认采取大写方式。
创建存储过程:

调用存储过程:
1、execute 存储过程名。
2、PL/SQL中调用,直接写存储过程名。

存储过程和存储函数的区别在于存储函数可以返回一个值,存储过程不可以
语法:
create or replace procedure 名称(参数)
AS
PLSQL子程序;
调用存储过程
exec sayhellword();
begin
sayhelloword();
sayhelloword();
end;
调用存储过程:set serveroutput on
-- 第一个存储过程:打印Hello World
/*
调用存储过程:
1.exec sayhelloworld();
2.begin
sayhelloworld();
sayhelloworld();
end;
/
*/
create or replace procedure sayhelloworld
as
--说明部分
begin
dbms_output.put_line('Hello World');
end;
/


以不带参数的存储过程为例
创建时检查同名过程 or repalce 可作为修改使用
存储过程无返回值 存储函数无返回值
编写好后运行编译
两种执行方式 exec 和plcql 通过begin和end
创建和使用存储过程
用CREATE PROCEDURE 命令建立存储过程和存储函数。
语法:
create [or replace] PROCEDURE 过程名(参数列表) AS
plsql子程序体;
/*
调用存储过程有两种方式:
1.exec sayHelloworld
2.调用两次这个存储过程
begin
sayHelloworld();
sayHelloworld();
end;
/
*/
create or replace procedure sayHelloworld
as ---相当于declare说明部分,如果没有,可以不写
begin
dbms_output.put_line('Hello World');
end;
/
end;
/
两种调用方式
1、execute 存储过程名字();
2、begin
存储过程名();
存储过程名();
end;
/
即使没有说明部分as也不能省略
语法:create or replace procedure 过程名(参数列表)
as
plsql程序体
创建和使用存储过程:


存储过程和存储函数
在数据库中供所有用户程序调用的子程序(plsql语言书写的程序)
相同点:完成特定功能的程序
区别:是否用retuen 语句返回值
存储函数可以通过return子句返回函数值
存储过程不可以通过return 子句返回函数值
创建和使用存储过程
存储过程只能创建和替换不能修改
语法 : create [or replace] procedure sayhelloword 存储过程名(参数列表)
as
--说明部分
begin
存储程序;
end;
示例 :
create or replace procedure sayhelloworld
as --说明部分
begin
dbms_output.put_line('hello world'); --输出hello world
end;
调用存储过程
1、sqlplus 调用
exec 存储过程名();
连接sqlplus
sqlplus scott/tiger@localhost:1521/orcl
输入用户名 密码
打开屏幕输出开关
set serveroutput on
调用存储过程
exec sayhelloworld();
2、plsql程序调用
begin
存储过程名(); --可以调用多次
end;
如何创建和使用存储过程
用create procedure 命令建立存储过程和存储函数
语法:create [or replace] procedure 过程名 (参数列表)
AS
PLSQL子程序体;
注意:存储过程只能创建和替换,不能够修改
第一个存储过程:打印helloworld
create or replace procedure sayHelloWorld
as
--说明部分
begin
dbms_output.put_line("Hello World !");
end;
/
注意:在plsql中使用存储过程或函数时在执行时需要以/结尾
/*
调用存储过程
1、execute 存储过程名();
例如:exec sayHelloWorld();
2.在其他的plsql中调用存储函数
例如:begin
sayHelloWorld();
sayHelloWorld();
end;
/
注意:使用第二种调用方法可以调用多次存储过程
*/
连接数据库:sqlplus scott/tiger@localhost:1521/orcl
说明:sqlplus 用户名/密码@主机号:数据库端口号/数据库实例名称
打开屏幕的复制开关:set serveroutput on
一、创建存储过程、存储函数
create 【or replace】 procedure 过程名(参数列表)
as
--说明部分
begin
存储程序
end
/
创建存储过程
create or replace procedure sayhelloworld
as
begin
dbms_output.put_line('Hello World');
end;
调用存储过程
1.exec sayhelloworld();
2.befgin
sayhelloworld();
sayhelloworld();
end;
/
创建存储过程的语法。
一、创建存储过程、存储函数
create 【or replace】 procedure 过程名(参数列表)
as
--说明部分
begin
存储程序
end
/
二、调用存储过程
1、execute 过程名
2、begin
存储过程名;
存储过程名;
end
/
三、命令行调用存储过程
1、进入oracle目录
2、plsql 账号/密码@192.168.101.24:1521/orcl
3、host cls
4、打开屏幕输出开关set serverport on
5、调用