Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server SQL SERVER sp“OACreate抛出错误”;“ODSOLE扩展程序”;执行128行之后_Sql Server_Regex_Ole Automation - Fatal编程技术网

Sql server SQL SERVER sp“OACreate抛出错误”;“ODSOLE扩展程序”;执行128行之后

Sql server SQL SERVER sp“OACreate抛出错误”;“ODSOLE扩展程序”;执行128行之后,sql-server,regex,ole-automation,Sql Server,Regex,Ole Automation,我需要根据正则表达式从输入中提取匹配文本。由于SQL Server中没有对正则表达式的内置支持,因此我编写了以下UDF来完成这项工作 CREATE FUNCTION GetMatch ( @Pattern VARCHAR(255), @Text VARCHAR(1000) ) RETURNS VARCHAR(1000) AS BEGIN DECLARE @Response INT, @ObjRegexExp INT, @ObjMatch INT, @Matchcount

我需要根据正则表达式从输入中提取匹配文本。由于SQL Server中没有对正则表达式的内置支持,因此我编写了以下UDF来完成这项工作

CREATE FUNCTION GetMatch
(
    @Pattern VARCHAR(255),
    @Text VARCHAR(1000)
)
RETURNS VARCHAR(1000)
AS
BEGIN
    DECLARE @Response INT, @ObjRegexExp INT, @ObjMatch INT, @Matchcount INT, @Match VARCHAR(1000);
    DECLARE @source VARCHAR(500), @description VARCHAR(500);

    EXEC @Response = sp_OACreate 'VBScript.RegExp', @ObjRegexExp OUT;

    IF @Response = 0
        EXEC @Response = sp_OASetProperty @ObjRegexExp, 'Pattern', @Pattern;
    IF @Response = 0
        EXEC @Response = sp_OASetProperty @ObjRegexExp, 'IgnoreCase', 1;
    IF @Response = 0
        EXEC @Response = sp_OASetProperty @ObjRegexExp, 'MultiLine', 0;
    IF @Response = 0
        EXEC @Response = sp_OASetProperty @ObjRegexExp, 'Global', 0;                        
    IF @Response = 0
        EXEC @Response = sp_OAMethod @ObjRegexExp, 'execute', @ObjMatch OUT, @Text;
    IF @Response = 0
        EXEC @Response = sp_OAGetProperty @ObjMatch, 'count', @Matchcount OUT;

    IF @Response = 0 AND @Matchcount >= 1
        EXEC @Response = sp_OAGetProperty @ObjMatch, 'item(0).Value', @Match OUT;

    IF @Response <> 0
    BEGIN
        EXEC @Response = sp_OAGetErrorInfo @ObjRegexExp, @source OUT, @description OUT;
        SET @Match = 'source ' + ISNULL(@source, '') + ' -- description ' + ISNULL(@description, '');
    END

    RETURN @Match;
END
GO
每次成功执行128次,然后生成错误ODSOLE扩展过程,我已经用sp_OAGetErrorInfo捕获了该过程。知道这是什么原因吗


现在是2018年。为什么要使用SQL Server笨拙的自动化过程来实现这一点,而不是使用现代CLR方法?不幸的是,由于其他限制,我无法使用CLR。我不知道它是否能解决这个问题(不幸的是,我们没有看到错误描述,只是看到了源代码,它没有告诉我们太多),但为了清洁起见,我建议添加一个
sp\u OADestroy
来清洁创建的对象。@Damien\u不信者感谢大副。正如你所说,我试着添加了sp_OADestroy。它稍微改善了结果。现在我最多可以看到255行。但在那之后又是同样的故事。FYI说明为空。请尝试将
NULL
而不是
@ObjRegexExp
作为第一个参数传递到
sp_OAGetErrorInfo
,看看这是否会使它更容易实现。
SELECT Barcode, dbo.GetMatch('(^[a-zA-Z]+)', Barcode) BarcodePrefix
FROM TestData