加入收藏 | 设为首页 | 会员中心 | 我要投稿 台州站长网 (https://www.0576zz.cn/)- 边缘计算、中间件、数据处理、数据分析、智能存储!
当前位置: 首页 > 数据库 > MsSql > 正文

函数和存过的创建调用

发布时间:2021-01-17 12:55:21 所属栏目:MsSql 来源:互联网
导读:函数[in out 参数]--函数[in out 参数]create or replace function get_test(m_id in number, str1 out varchar2) --参数不需要类型长度return varchar2 is str2 varchar2(10); --变量需要类型长度beginselect t.ename, t.jobinto str1, str2from scott.emp t

函数[in out 参数]

get_test(m_id ,str1 out ) str2 (); t.empno <span style="color: #008080;">--<span style="color: #008080;">调用函数[位置表示法]
<span style="color: #0000ff;">declare<span style="color: #000000;">
s1 <span style="color: #0000ff;">varchar2(<span style="color: #800000; font-weight: bold;">10<span style="color: #000000;">);
s2 <span style="color: #0000ff;">varchar2(<span style="color: #800000; font-weight: bold;">10<span style="color: #000000;">);
s3 <span style="color: #0000ff;">number(<span style="color: #800000; font-weight: bold;">30) <span style="color: #0000ff;">default <span style="color: #800000; font-weight: bold;">7521; <span style="color: #008080;">--<span style="color: #008080;">default 默认值
<span style="color: #0000ff;">begin<span style="color: #000000;">
s3:<span style="color: #808080;">=<span style="color: #800000; font-weight: bold;">7566<span style="color: #000000;">;
s2 :<span style="color: #808080;">= get_test(s3,s1);<span style="color: #008080;">--<span style="color: #008080;">参数次序
dbms_output.put_line(s1 <span style="color: #808080;">|| <span style="color: #ff0000;">' <span style="color: #ff0000;">' <span style="color: #808080;">||<span style="color: #000000;"> s2);
<span style="color: #0000ff;">end<span style="color: #000000;">;

<span style="color: #008080;">--<span style="color: #008080;">调用函数 [名称表示法]
<span style="color: #0000ff;">declare<span style="color: #000000;">
s1 <span style="color: #0000ff;">varchar2(<span style="color: #800000; font-weight: bold;">10<span style="color: #000000;">);
s2 <span style="color: #0000ff;">varchar2(<span style="color: #800000; font-weight: bold;">10<span style="color: #000000;">);
<span style="color: #0000ff;">begin<span style="color: #000000;">
s2 :<span style="color: #808080;">= get_test( str1<span style="color: #808080;">=>s1,m_id<span style="color: #808080;">=><span style="color: #800000; font-weight: bold;">7521); <span style="color: #008080;">--<span style="color: #008080;">名称的对应关系,次序并不重要
dbms_output.put_line(s1 <span style="color: #808080;">|| <span style="color: #ff0000;">' <span style="color: #ff0000;">' <span style="color: #808080;">||<span style="color: #000000;"> s2);
<span style="color: #0000ff;">end;

存储过程1

<span style="color: #0000ff;">create <span style="color: #808080;">or <span style="color: #ff00ff;">replace <span style="color: #0000ff;">procedure get_test1(m_id <span style="color: #808080;">in <span style="color: #0000ff;">number,str1 out <span style="color: #0000ff;">varchar2) <span style="color: #008080;">--<span style="color: #008080;">参数不需要类型长度
<span style="color: #0000ff;">is
<span style="color: #0000ff;">begin
<span style="color: #0000ff;">select t.ename <span style="color: #0000ff;">into str1 <span style="color: #0000ff;">from scott.emp t <span style="color: #0000ff;">where t.empno <span style="color: #808080;">=<span style="color: #000000;"> m_id;
<span style="color: #0000ff;">end<span style="color: #000000;"> get_test1;

<span style="color: #008080;">--<span style="color: #008080;">调用
<span style="color: #0000ff;">declare<span style="color: #000000;">
s1 <span style="color: #0000ff;">varchar2(<span style="color: #800000; font-weight: bold;">100<span style="color: #000000;">);
<span style="color: #0000ff;">begin<span style="color: #000000;">
get_test1(<span style="color: #800000; font-weight: bold;">7521<span style="color: #000000;">,s1);
dbms_output.put_line(s1);
<span style="color: #0000ff;">end;

存储过程2

get_test2(m_id (); t.ename str1 scott.emp t t.empno get_test2();

(编辑:台州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读