我試圖刪除所有空白字符(TAB,CR,LF),我已經找到了最好的表達方式(即實際工作)是:使用Teradata的syslib.oreplace刪除所有空格字符
syslib.oreplace(
syslib.oreplace(
syslib.oreplace(my_string,X'0a',''),X'0d',''),X'09','')
有什麼更優雅的?我不能在一個單獨的電話號碼中刪除所有的電話嗎?
我試圖刪除所有空白字符(TAB,CR,LF),我已經找到了最好的表達方式(即實際工作)是:使用Teradata的syslib.oreplace刪除所有空格字符
syslib.oreplace(
syslib.oreplace(
syslib.oreplace(my_string,X'0a',''),X'0d',''),X'09','')
有什麼更優雅的?我不能在一個單獨的電話號碼中刪除所有的電話嗎?
我用它是基於isprint()
C函數以下UDF:
#define SQL_TEXT Latin_Text
#include "sqltypes_td.h"
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
/*
||-------------------------------------------------------------------
|| retain_print()
||
|| Description:
|| Accepts an input string and returns only the printable characters
|| including space based on the isprint() C function.
||
|| Note: tabs, vertical tabs, form feeds, newlines, and carriage
|| returns will be stripped. Otherwise, the isspace() function
|| would have been used to check for space.
||
|| Arguments:
|| sStrIn: string to be processed
|| result: processed string or spaces if invalid.
||
|| Examples:
|| retain_print("ABCD. 1234")
|| returns "ABCD. 1234"
||
|| Sample Use:
|| SELECT nullif(retain_print('ABCD. 1234'), ' ');
||-------------------------------------------------------------------
*/
void retain_print(VARCHAR_LATIN *sStrIn,
VARCHAR_LATIN *result)
{
int slen; /* sStrIn length in chars */
int iposin; /* position of input string */
int iposout; /* position of output string */
char strout[10000]; /* output string */
/*
||------------------------------------------------
|| Loop thru testing for alpha.
||------------------------------------------------
*/
iposin = 0;
iposout = 0;
slen = strlen((const char *) sStrIn);
if (slen < 1) {
goto ERROR;
}
while ((slen > iposin)) {
/* Check if argument is a printable character (including a space) */
if (isprint(sStrIn[iposin])) {
strout[iposout] = sStrIn[iposin];
iposout = iposout + 1;
}
/* The argument is not a printable character replace with a space */
else {
strout[iposout] = ' ';
iposout = iposout + 1;
}
iposin = iposin + 1;
}
strout[iposout] = '\0';
strcpy((char *) result, strout);
goto EXIT;
ERROR:
strcpy((char *) result, " ");
EXIT:
return;
稍微調整一下,可以利用其他C函數(如isalnum())來擴展UDF庫。 – 2012-03-19 13:20:43
whoa,我希望使用更標準的otranslate/oreplace函數,而不是新的UDF,但是我會讓我的DBA看看這個,並讓您知道這是否對我們有幫助! – ihadanny 2012-03-19 16:08:05
不會這項工作?
sel COALESCE(OREPLACE('no spaces',' '), '')
我用這個確切的代碼來清理一些數據!謝謝!! – banging 2012-05-03 17:22:48