• 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)
    

      

  • 相关阅读:
    mxGraph 3.7.2
    ER模型
    帮忙画个ER图_百度知道
    ER图
    Download Devart T4 Editor
    Codeuml —— 设计 UML 图表跟你编码一样快
    使用 Sublime + PlantUML 高效地画图
    Rappid Diagramming Framework
    Activiti Designer 5.15.0 发布,可视化流程设计器
    JavaScript Diagramming
  • 原文地址:https://www.cnblogs.com/hank-chen/p/6265767.html
Copyright © 2020-2023  润新知