SQL에서 regex.split를 구현하는 함수를 만들었습니다. 코드는 다음과 같습니다.SQL 서버에 대한 regex split 구현
private static IEnumerable<IndexedValue<T>> ToIndexedValue<T>(IEnumerable<T> list)
{
int idx = 1;
foreach (T value in list)
yield return new IndexedValue<T>(++idx, value);
}
private struct IndexedValue<T>
{
public int Index;
public T Value;
public IndexedValue(int index, T value)
{
Index = index;
Value = value;
}
}
[SqlFunction(FillRowMethodName = "FillSplit",
TableDefinition = "[ID] int, [Value] nvarchar(max)")]
public static IEnumerable RegexSplit(SqlString input, SqlString pattern)
{
if (input.IsNull)
input = String.Empty;
if (pattern.IsNull)
pattern = String.Empty;
try
{
return ToIndexedValue<string>(Regex.Split(input.Value, pattern.Value, Options));
}
catch
{
throw;
}
}
public static void FillSplit(object obj, out int id, out SqlString value)
{
IndexedValue<string> iv = (IndexedValue<string>)obj;
id = iv.Index;
value = iv.Value;
}
그러나 시도 할 때 id 값은 있지만 텍스트 값은 비어 있습니다. 누군가 도울 수 있습니까?
이 원본을 찾고, 속는 사람입니다. 편집 : 사실은 속마귀,하지만 속는 내 대답은 :) – leppie