2008-12-10 13 views
11

मान लिया जाये कि निम्नलिखित परिभाषा: मान छोटा कर दिया जा रहा हैसीएलआर यूडीएफ में एक nvarchar (अधिकतम) कैसे वापस करें?

/// <summary> 
/// Replaces each occurrence of sPattern in sInput with sReplace. This is done 
/// with the CLR: 
/// new RegEx(sPattern, RegexOptions.Multiline).Replace(sInput, sReplace). 
/// The result of the replacement is the return value. 
/// </summary> 
[SqlFunction(IsDeterministic = true)] 
public static SqlString FRegexReplace(string sInput, string sPattern, 
     string sReplace) 
{ 
    return new Regex(sPattern, RegexOptions.Multiline).Replace(sInput, sReplace); 
} 

लंबाई> 4000 के साथ sInput के लिए एक nvarchar(max) मूल्य में पासिंग परिणाम होगा (यानी इस यूडीएफ बुला का परिणाम nvarchar(4000) है के रूप में करने का विरोध किया nvarchar(max)

उत्तर

24

ओह, जो कुछ भी है, मैं इस सवाल का जवाब अपने आप को पाया:

/// <summary> 
/// Replaces each occurrence of sPattern in sInput with sReplace. This is done 
/// with the CLR: 
/// new RegEx(sPattern, RegexOptions.Multiline).Replace(sInput, sReplace). 
/// The result of the replacement is the return value. 
/// </summary> 
[SqlFunction(IsDeterministic = true)] 
[return: SqlFacet(MaxSize = -1)] 
public static SqlString FRegexReplace([SqlFacet(MaxSize = -1)]string sInput, 
     string sPattern, string sReplace) 
{ 
    return new Regex(sPattern, RegexOptions.Multiline).Replace(sInput, sReplace); 
} 

विचार एसक्यूएल सर्वर के लिए संकेत है कि इनपुट और वापसी मान डिफ़ॉल्ट nvarchar(4000) नहीं हैं, लेकिन एक अलग आकार है।

मैं विशेषताओं के बारे में एक नई चाल सीखा: वे [return: AttributeName(Parameter=Value, ...)] सिंटेक्स के साथ रिटर्न मान पर भी मानकों के साथ ही विधि ही (काफी स्पष्ट) में जोड़ा जा सकता है, लेकिन।

+0

आप एक स्टार हैं, महोदय :) –

+0

उस तंत्र को संदर्भित संदर्भ में स्पष्ट रूप से वर्णित किया गया है - जिस उत्तर में आप नीचे मतदान करते हैं। – bielawski

संबंधित मुद्दे