PL/SQL 中的函数和过程有什么区别? [英] What is the difference between function and procedure in PL/SQL?

查看:35
本文介绍了PL/SQL 中的函数和过程有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PL/SQL 中的函数和过程有什么区别?

What is the difference between function and procedure in PL/SQL ?

推荐答案

过程没有返回值,而函数有.

A procedure does not have a return value, whereas a function has.

示例:

CREATE OR REPLACE PROCEDURE my_proc
   (p_name IN VARCHAR2 := 'John') as begin ... end

CREATE OR REPLACE FUNCTION my_func
   (p_name IN VARCHAR2 := 'John') return varchar2 as begin ... end

注意函数在参数列表和as"关键字之间有一个返回子句.这意味着函数体中的最后一条语句应该是这样的:

Notice how the function has a return clause between the parameter list and the "as" keyword. This means that it is expected to have the last statement inside the body of the function read something like:

return(my_varchar2_local_variable);

其中 my_varchar2_local_variable 是一些应该由该函数返回的 varchar2.

Where my_varchar2_local_variable is some varchar2 that should be returned by that function.

这篇关于PL/SQL 中的函数和过程有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆