简体   繁体   English

如何在Oracle 11g中更新具有不同值的列?

[英]How to update a column with different values in Oracle 11g?

I have a table with name "User_Report" with these columns. 我有一个名为“ User_Report”的表,其中包含这些列。

ID       Name    City    zip    Report_File
101      AAA     PPP     123     -----
102      BBB     QQQ     345     -----
103      CCC     RRR     567     -----
104      FFF     SSS     789     -----

I added Report_File new column and i need to update this column with Name+".rpt". 我添加了Report_File新列,我需要用Name +“。rpt”更新此列。 How i can update Report_File column with corressponding Name column data in a single update statement? 如何在单个更新语句中使用对应的名称列数据更新Report_File列?

Please send me one example? 请给我举个例子吗?

Thanks in advance. 提前致谢。

Please try below query. 请尝试下面的查询。 In oracle double pipes ( || ) are used for concatenation of strings: 在oracle中,双管道( || )用于字符串的串联:

Update User_Report
SET Report_File=Name||'.rpt';

OR keyword CONCAT can be used. 可以使用关键字CONCAT Refer LINK 参考链接

Update User_Report
SET Report_File=CONCACT(Name, '.rpt')

Your report_file column appears to be a calculated value, if it will never deviate, then you might consider a virtual column. 您的report_file列似乎是一个计算值,如果它永远不会偏离,那么您可以考虑使用虚拟列。

alter table user_report add (report_file varchar(40) as (name||'.rpt'));

This way you never have to worry about keeping it in synch, it will always be in synch if name changes or new values are inserted. 这样,您就不必担心保持同步,如果更改名称或插入新值,它将始终保持同步。

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

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