我有一个 Java 程序,可以将文件的修订版本保存到数据库中。我目前正在添加一个函数,我可以在其中更改数据库中文件的名称。问题是,每个修订版都以 Date@Time File_Name 的格式保存。例如“[email protected] File.pdf”。所有修订版本都使用相同的文件 ID 存储,因此无论是哪个修订版本,都可以通过文件 ID 找到相同的文件。如何在不更改名称的 Date@Time 部分的情况下更新修订的名称。例如--将“[email protected] File.pdf”更改为“[email protected] NewFileName.pdf”。
我觉得第一步是选择所有具有我正在寻找的文件 ID 的行。
select name
from allFiles
where fileID = '1'
This isn't hard, but now I would like to change all the file names how I mentioned above for each one of the files with that file ID. Thus, I will probably need to use a loop. Something like the one below.
WHILE @cnt < cnt_total
BEGIN {...statements...}
SET @cnt = @cnt + 1;
END;
To summarize, I need to change the name of all files with a certain file ID. But when changing the name, only change the second part where the actual file name is and not change the date section.
If it helps, the modified date that is in the first part of the name is also stored as its own column in the DB. But the date also needs to be in the name to prevent duplicates.
As I can see from your sample data, the column Modified
contains the date@time part which is the prefix of each value of the column Name
.
If this is the case then do this update:
UPDATE allFiles
SET Name = Modified || 'newfilename'
WHERE Name = Modified || 'oldfilename'
请参阅演示。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句