有人可以用 sql 或 teradata 帮我验证一下吗

发布于 2024-12-09 10:18:52 字数 626 浏览 3 评论 0原文

我在 Oracle 中有一行代码,我必须将其转换为 Teradata。 Oracle 查询是

 /* add to avoid invalid number due to junk in column */

AND regexp_instr(table.column, ''[^[:digit:]]'', 1, 1)  = 0 

我在 Teradata 中编写的代码。

AND (CASE WHEN (POSITION('' '' IN TRIM(table.column)) > 0) OR (UPPER(TRIM(table.column))              
        (CASESPECIFIC) <> LOWER(TRIM(table.column)) (CASESPECIFIC)) 
          THEN 1 ELSE 0 end ) = 0

该列定义为 VARCHAR(20) ,但我只想选择数据均为数字的行。我无法验证 Teradata 查询,因为它是一个运行时间非常长的查询,并且我无权创建表,或者更确切地说,我无法验证我拥有的数据库的输出。我尝试过一些方法,看起来确实有效,但我曾经想验证语法和我对 REGEXP_INSTR 的理解。

I have a line of code in Oracle and I had to convert it into Teradata.
The Oracle query is

 /* add to avoid invalid number due to junk in column */

AND regexp_instr(table.column, ''[^[:digit:]]'', 1, 1)  = 0 

The code I have written in Teradata

AND (CASE WHEN (POSITION('' '' IN TRIM(table.column)) > 0) OR (UPPER(TRIM(table.column))              
        (CASESPECIFIC) <> LOWER(TRIM(table.column)) (CASESPECIFIC)) 
          THEN 1 ELSE 0 end ) = 0

The column is defined as a VARCHAR(20) but I only want to select rows where the data is all numeric. I cannot verify the Teradata query as it is a very long-running query and I don't have access to create tables or rather I can not verify the out put on the database I have. I some how tried and it looks like it works but I once wanted to verify the syntax and my understanding of REGEXP_INSTR.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘香 2024-12-16 10:18:52

如果我阅读正确并且根据我的测试,这将破坏您的逻辑(均返回 1):

SELECT (CASE WHEN (POSITION('' '' IN TRIM('1234')) > 0) OR (UPPER(TRIM('1234'))              
        (CASESPECIFIC) <> LOWER(TRIM('1234')) (CASESPECIFIC)) 
          THEN 1 ELSE 0 END )

SELECT (CASE WHEN (POSITION('' '' IN TRIM('abcd ef1')) > 0) OR (UPPER(TRIM('abcd ef1'))              
        (CASESPECIFIC) <> LOWER(TRIM('abcd ef1')) (CASESPECIFIC)) 
          THEN 1 ELSE 0 END )

Teradata Developer's Exchange 包含一个已转换为 Teradata UDF 的 Oracle 函数库,可以帮助您解决此问题。只需付出一点努力,您就可以围绕 isdigit() C 函数编写自己的 UDF。 (isdigit)

现在可能没有帮助,但是最近宣布的 Teradata 14.0 功能之一是支持正则表达式。

编辑:添加了带有 REGEXP_INSTR 的 TD 14 示例,应该可以解决问题

SELECT table.column
  FROM table
WHERE REGEXP_INSTR(table.column, '[^[digit]])') = 0;

If I am reading correctly and based on my testing this will break your logic (both return 1):

SELECT (CASE WHEN (POSITION('' '' IN TRIM('1234')) > 0) OR (UPPER(TRIM('1234'))              
        (CASESPECIFIC) <> LOWER(TRIM('1234')) (CASESPECIFIC)) 
          THEN 1 ELSE 0 END )

SELECT (CASE WHEN (POSITION('' '' IN TRIM('abcd ef1')) > 0) OR (UPPER(TRIM('abcd ef1'))              
        (CASESPECIFIC) <> LOWER(TRIM('abcd ef1')) (CASESPECIFIC)) 
          THEN 1 ELSE 0 END )

The Teradata Developer's Exchange contains a library of Oracle functions that have been converted to Teradata UDF's that may help you address this problem. With a little effort you could write your own UDF around the isdigit() C function. (isdigit)

It may not be helpful now, but one of the recently announced Teradata 14.0 features is support of regular expressions.

EDIT: Added TD 14 example with REGEXP_INSTR that should solve the problem

SELECT table.column
  FROM table
WHERE REGEXP_INSTR(table.column, '[^[digit]])') = 0;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文