从加载到数据库中的CSV数据中快速删除单引号

时间:2022-09-15 15:16:07

I have a database built from CSV files loaded from an external source. For some reason, an ID number in many of the tables is loaded into the CSV / database encased in single quotes - here's a sample line:

我有一个从外部源加载的CSV文件构建的数据库。出于某种原因,许多表中的ID号被加载到用单引号括起来的CSV /数据库中 - 这是一个示例行:

 "'010010'","MARSHALL MEDICAL CENTER NORTH","8000 ALABAMA HIGHWAY 69","","","GUNTERSVILLE","AL","35976","MARSHALL","2565718000","Acute Care Hospitals","Government - Hospital District or Authority","Yes"

Is there any SQL I can run on the already-established database to strip these single quotes, or do I have to parse every CSV file and re-import?

是否有任何SQL可以在已经建立的数据库上运行以去除这些单引号,或者我是否必须解析每个CSV文件并重新导入?

1 个解决方案

#1


2  

I believe the following would do it (test it first):

我相信以下会做(先测试):

UPDATE U
SET YourID = REPLACE(YourID, '''', '')
FROM MyTable AS U
WHERE YourID LIKE '''%'''

If it works right, do a full backup before running it in production.

如果工作正常,请在生产中运行之前执行完整备份。

#1


2  

I believe the following would do it (test it first):

我相信以下会做(先测试):

UPDATE U
SET YourID = REPLACE(YourID, '''', '')
FROM MyTable AS U
WHERE YourID LIKE '''%'''

If it works right, do a full backup before running it in production.

如果工作正常,请在生产中运行之前执行完整备份。