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)
    

      

  • 相关阅读:
    5.3 存储器、I/O和配置读写请求TLP 分类: 浅谈PCI-E 2013-07-22 16:28 413人阅读 评论(0) 收藏
    5.2 TLP的路由 分类: 浅谈PCI-E 2013-07-22 16:28 337人阅读 评论(0) 收藏
    5.1 TLP的格式 分类: 浅谈PCI-E 2013-07-22 16:27 464人阅读 评论(0) 收藏
    第5章 PCIe总线的事务层 分类: 浅谈PCI-E 2013-07-22 16:27 345人阅读 评论(0) 收藏
    1016. Phone Bills (25)
    1018. Public Bike Management (30)
    1076. Forwards on Weibo (30)
    1034. Head of a Gang (30)
    1021. Deepest Root (25)
    1013. Battle Over Cities (25)
  • 原文地址:https://www.cnblogs.com/hank-chen/p/6265767.html
Copyright © 2011-2022 走看看