简体   繁体   English

如何在 Oracle 数据库的计算列中使用 case 语句

[英]How can I use case statement in computed column in Oracle database

Can I use Case statement in computed column in Oracle.我可以在 Oracle 的计算列中使用 Case 语句吗?

I have filename column in table which can be used to populate source of data.我在表中有文件名列,可用于填充数据源。 eg.例如。 if filename contains abc than source system is ABC, if filename contains def then source of data is DEF.如果文件名包含abc而源系统是 ABC,如果文件名包含def那么数据源是 DEF。

I need to alter the table with new column source (which should be computed from existing file name column)我需要用新的列更改表(应该从现有的文件名列计算)

Yes, you can do that.是的,你可以这么做。 For example:例如:

CREATE TABLE TEST_TAB
  (N1     NUMBER,
   S2     VARCHAR2(10) GENERATED ALWAYS AS (CASE
                                              WHEN N1 IS NULL THEN 'NULL'
                                              WHEN N1 < 0 THEN 'NEGATIVE'
                                              WHEN N1 = 0 THEN 'ZERO'
                                              WHEN N1 > 0 THEN 'POSITIVE'
                                            END));

dbfiddle here dbfiddle在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM