如何将列值设置为Oracle中的选择查询中的null?

发布于 2025-02-12 16:06:55 字数 650 浏览 0 评论 0原文

我想选择一个等于特定页面项目值的列值,然后选择其他值作为null。 主表数据如下:

idfirst_numberssecond_numbers
111122222
134341112

first_numbers = 1112的值等于:p4_number = 1112页面项目,所以我想要的预期结果是:

idfirst first_numberssecond_numbers second_numbers
11112null
1 null 1null 11112 null11112

I want to select a column value which is equal to a specific page item value and select the other values as null.
The main table data is the following:

idfirst_numberssecond_numbers
111122222
134341112

The value of first_numbers=1112 is equal to :p4_number=1112 page item so the expected result which I want is:

idfirst_numberssecond_numbers
11112null
1null1112

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

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

发布评论

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

评论(1

花期渐远 2025-02-19 16:06:55

使用案例表达式:

示例数据:

SQL> with test (id, first_numbers, second_numbers) as
  2    (select 1, 1112, 2222 from dual union all
  3     select 2, 3434, 1112 from dual
  4    )

查询本身:

  5  select id,
  6    case when first_numbers  <> &&P4_NUMBER then null else first_numbers  end first_numbers,
  7    case when second_numbers <> &&P4_NUMBER then null else second_numbers end second_numbers
  8  from test;
Enter value for p4_number: 1112

        ID FIRST_NUMBERS SECOND_NUMBERS
---------- ------------- --------------
         1          1112
         2                         1112

SQL>

当您使用Apex时,您将使用bind(而不是替换)变量,即

... case when first_numbers  <> :P4_NUMBER then
                                ^
                                |
                              this

Use CASE expression:

Sample data:

SQL> with test (id, first_numbers, second_numbers) as
  2    (select 1, 1112, 2222 from dual union all
  3     select 2, 3434, 1112 from dual
  4    )

Query itself:

  5  select id,
  6    case when first_numbers  <> &&P4_NUMBER then null else first_numbers  end first_numbers,
  7    case when second_numbers <> &&P4_NUMBER then null else second_numbers end second_numbers
  8  from test;
Enter value for p4_number: 1112

        ID FIRST_NUMBERS SECOND_NUMBERS
---------- ------------- --------------
         1          1112
         2                         1112

SQL>

As you use Apex, you'd use bind (instead of substitution) variable, i.e.

... case when first_numbers  <> :P4_NUMBER then
                                ^
                                |
                              this
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文