[英]Oracle SQL add new column based on value of other column
I'm looking for some help to create a new column based on values from another column - if this is even possible... This is not an ideal solution but I'm out running out of options.我正在寻找一些帮助来根据另一列的值创建一个新列 - 如果这甚至可能的话......这不是一个理想的解决方案,但我已经没有选择了。
I need to replace the beginning folder paths, change the direction of the \ and change the extension我需要替换开始的文件夹路径,更改 \ 的方向并更改扩展名
Existing Field:
\\BRRNAKCL12\Audiofiles22\1Year\Diogarfngal_ZZZZZZZZZ\2020\Aug\03\5249013\5249013-07-25-18-96572.cca
New Field:
/location/TELEDATA/2020/Aug/03/5249013/5249013-07-25-18-96572.wav
Oracle version Version 19.2.1.247 Oracle 版本 版本 19.2.1.247
Thank you in advance先感谢您
You can add a new column to your table named NewField:您可以在名为 NewField 的表中添加一个新列:
Alter table TableName add NewField varchar(500);
Then update NewField by replacing some characters as you wish from ExistingField.然后通过替换 ExistingField 中的一些字符来更新 NewField。
update TableName set NewField= replace(replace(existingfield,'\','/'),'.cca','.wav')
Here I have just replace '' with '/' and '.cca' with '.wav'.在这里,我只是将 '' 替换为 '/' 和 '.cca' 替换为 '.wav'。
To replace path also:还要替换路径:
update TableName set NewField= '/location/TELEDATA/'||substr(replace(replace(existingfield,'\','/'),'.cca','.wav'),instr(replace(replace(existingfield,'\','/'),'.cca','.wav'),'/2020',1,1) + 1)
DB-Fiddle: DB-小提琴:
Schema and insert statements:模式和插入语句:
create table mytable (existingfield varchar(500));
insert into mytable values('
\\BRRNAKCL12\Audiofiles22\1Year\Diogarfngal_ZZZZZZZZZ\2020\Aug\03\5249013\5249013-07-25-18-96572.cca');
Add new column:添加新列:
Alter table mytable add NewField varchar(500);
Update query:更新查询:
update mytable set NewField= '/location/TELEDATA/'||substr(replace(replace(existingfield,'\','/'),'.cca','.wav'),instr(replace(replace(existingfield,'\','/'),'.cca','.wav'),'/2020',1,1) + 1)
Select query: Select 查询:
select * from mytable;
Output: Output:
EXISTINGFIELD![]() |
NEWFIELD![]() |
---|---|
\BRRNAKCL12\Audiofiles22\1Year\Diogarfngal_ZZZZZZZZZ\2020\Aug\03\5249013\5249013-07-25-18-96572.cca ![]() |
/location/TELEDATA/2020/Aug/03/5249013/5249013-07-25-18-96572.wav ![]() |
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.