zoukankan      html  css  js  c++  java
  • 存储过程

    --无参数无返回值
    create proc pl
    as
    begin
    select*from Student
    end
    exec pl
    drop proc pl
    --有参数无返回值
    create proc p2
    @banj_id char(10), @Ssex char(2)
    as
    begin
    select*from Student where Class=@banj_id and Ssex=@Ssex 
    end
    drop proc p2
    exec p2 95031,男
    --默认参数无返回值
    create proc p3
    @Ssex char(2)=as
    select*from Student where Ssex like @Ssex+'%'
    exec p3 
    --有返回值无参数
    create proc p4
    @Sno char(10) output
    as 
    begin
    select @Sno=Sname from Student where Sno=105
    end
    declare @rt char(10)
    exec p4 @rt output
    print @rt
    --有返回值有参数
    create proc p5
    @a int,@b int,
    @c int output
    as
    begin
    set @c=@a+@b
    end
    declare @rt int
    exec p5 1,2,@rt output
    print @rt
    --返回值return写法,只能返回单个数据值
    alter proc p5
    @a int,@b int
    as
    begin
    return @a+@b
    end
    declare @rt int
    exec @rt=p5 1,2
    print @rt
    
    --动态查询
    --解析执行语句
    exec('select*form Student')
    
    create proc p6
    @tablename varchar(15)
    as
    begin
    exec('select*from '+@tablename)
    end
    drop proc p6
    exec p6 'Student'
    
    create proc p7
    @tablename char(10),@column char(10),@value char(10)
    as
    declare @query varchar(255)
    select @query='select*from '+@tablename+' where '+@colum=@value
    exec (@query)
    exec p7 student,class,95033
    --标量函数返回唯一数据值
    create function f1 ()
    returns int
    as
    begin
    return 1
    end
    select dbo.f1()
    
    create function f2
    (@a int ,@b int)
    returns int
    as 
    begin
    return @a+@b
    end
    declare @rt int
    select @rt=dbo.f2(1,2)
    print @rt
    --内嵌表值函数
    create function f3
    ()
    returns table
    as
    return(select *from student) 
    select*from dbo.f3()
    --多语句表值函数
    alter function f4
    ()
    returns @t table
    (sno int,sname varchar(20))
    as
    begin
    insert into @t select top 2 sno,sname from student
    return
    end
    select*from dbo.f4()
  • 相关阅读:
    Weka回归
    R语言知识体系概览
    HDU 1020 Encoding POJ 3438 Look and Say
    FtpClient.storeFile返回false解决方法
    Docker安装ruby2.1
    定制一套属于自己的博客样式(转载)
    Docker常见问题解决
    The method getJspApplicationContext(ServletContext) is undefined for the type
    解决httpServletRequest.getParameter获取不到参数
    淘宝知名工程师(转载)
  • 原文地址:https://www.cnblogs.com/liuyudong0825/p/4764505.html
Copyright © 2011-2022 走看看