zoukankan      html  css  js  c++  java
  • sql server 扩展存储过程

    C# 代码

    using Microsoft.SqlServer.Server;
    using System;
    using System.Collections.Generic;
    using System.Data.SqlTypes;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Threading.Tasks;
    
    
    public partial class UserDefinedFunctions
    {
        public static SqlString ExampleUDF()
        {
            return new SqlString("Hello");
        }
        [SqlFunction(IsDeterministic = true, IsPrecise = true)]
        public static bool RegExIsMatch(string pattern, string matchString)
        {
            Regex reg = new Regex(pattern.TrimEnd(null));
            return reg.Match(matchString.TrimEnd(null)).Success;
        }
    }
    

    SQL SERVER 代码

    加载程序集

    USE InvestorRelations
    CREATE ASSEMBLY ExampleUDF
    FROM 'E:学习SessionTestTestKZCCGCinDebugTestKZCCGC.dll'

    创建函数

    CREATE FUNCTION ExampleUDFTwo()
    RETURNS nvarchar(1000)
    AS EXTERNAL NAME ExampleUDF.UserDefinedFunctions.ExampleUDF;
    

      

     表值函数:

    C#代码

    using Microsoft.SqlServer.Server;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data.SqlTypes;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Threading.Tasks;
    
    
    public partial class UserDefinedFunctions
    {
        [SqlFunction(FillRowMethodName = "FillRow")]
        public static IEnumerable DirectoryList(string sRootDir, string sWildCard, bool bIncludeSubDirs)
        {
            ArrayList aFileArray = new ArrayList();
            DirectorySearch(sRootDir, sWildCard, bIncludeSubDirs, aFileArray);
            return aFileArray;
        }
        private static void DirectorySearch(string directory, string sWildCard, bool bIncludeSubDirs, ArrayList aFileArray)
        {
            GetFiles(directory, sWildCard, aFileArray);
            if (bIncludeSubDirs)
            {
                foreach (string d in Directory.GetDirectories(directory))
                {
                    DirectorySearch(d, sWildCard, bIncludeSubDirs, aFileArray);
                }
            }
        }
        private static void GetFiles(string d, string sWildCard, ArrayList aFileArray)
        {
            foreach (string f in Directory.GetFiles(d, sWildCard))
            {
                FileInfo fi = new FileInfo(f);
                object[] column = new object[2];
                column[0] = fi.FullName;
                column[1] = fi.LastWriteTime;
                aFileArray.Add(column);
            }
        }
        private static void FillRow(object obj, out string filename, out DateTime date)
        {
            object[] row = (object[])obj;
            filename = (string)row[0];
            date = (DateTime)row[1];
        }
    }
    

      SQL SERVER 代码

    ALTER DATABASE InvestorRelations
    SET TRUSTWORTHY ON;
    
    
    USE InvestorRelations
    
    CREATE ASSEMBLY fExampleTVF
    FROM 'E:学习SessionTestTestKZCCGCinDebugTestKZCCGC.dll'
    WITH PERMISSION_SET=EXTERNAL_ACCESS
     
    CREATE FUNCTION fTVFExample(
    @RootDir nvarchar(max),
    @WildCard nvarchar(max),
    @IncludeSubDirs bit
    )
    RETURNS TABLE (
    	FileName nvarchar(max),
    	LastWriteTime datetime
    )
    AS EXTERNAL NAME fExampleTVF.UserDefinedFunctions.DirectoryList
    
    SELECT FILENAME,LASTWRITETIME
    FROM dbo.fTVFExample('E:学习','*.ppt',0)
    

      

  • 相关阅读:
    寻找研究基于NS2研究覆盖网络的小伙伴:)
    ubuntu14.04 键盘错位小问题
    关于NS2安装的若干问题
    关于ubuntu下词典安装
    与NS2一起度过第一个圣诞夜!(NS2入门学习参考资料)
    【转】影响CSS渲染速度的十条编码方法与建议
    类型初始值设定项引发异常
    【转】实用的CSS Hack
    【转】CSS技巧:五个方面促进你写出更加专业的CSS代码
    IIS6.0架构
  • 原文地址:https://www.cnblogs.com/hank-chen/p/6265767.html
Copyright © 2011-2022 走看看