我正在尝试删除所有空格字符(tab,cr,lf),我找到的最佳表达式(实际上有效)是:
syslib.oreplace(
syslib.oreplace(
syslib.oreplace(my_string,X'0a',''),X'0d',''),X'09','')
有什么更优雅的吗?我不能在一个矿场电话中删除所有这些吗?
答案 0 :(得分:1)
我使用了以下基于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;
答案 1 :(得分:0)
这不会起作用吗?
sel COALESCE( OREPLACE('no spaces',' '), '')