首页 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();

本文来自网络,不代表青岛站长网立场。转载请注明出处: https://www.0532zz.com/html/shujuku/mssql/20210117/16303.html
上一篇
下一篇

作者: dawei

【声明】:青岛站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

返回顶部