使用 TOAD 从 Oracle 创建更新脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11217302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:55:30  来源:igfitidea点击:

Creating an update script from Oracle using TOAD

sqloracletoad

提问by dawriter

In Oracle, using TOAD, we are able to create an insert script from a table.

在 Oracle 中,使用 TOAD,我们能够从表创建插入脚本。

However, I need to create an UPDATE script based on the values of each row

但是,我需要根据每一行的值创建一个 UPDATE 脚本

where the CLIENTID is 'blah blah'

Originally, what I did was create an Excel spreadsheet with all the necessary data and for each row, I pasted a

最初,我所做的是创建一个包含所有必要数据的 Excel 电子表格,对于每一行,我粘贴了一个

UPDATE TABLE BLAH BLAH SET COLUMN1 = "xxx", COLUMN2 = '' where CLIENT_ID = "123'

..but I ran into some difficulties with exporting the spreadsheet into a text based DOS file and converting it to a .sqlas so to edit but it was messy and unpredictable.

..但是我在将电子表格导出为基于文本的 DOS 文件并将其转换为 DOS 文件.sql以进行编辑时遇到了一些困难,但它很混乱且不可预测。

Has anyone have a better idea I can implement?

有没有人有更好的主意我可以实施?

回答by Rajesh Chamarthi

I haven't seen any feature in Toad that helps write update queries in this fashion. But loading data directly is something that Toad makes very easy.

我还没有在 Toad 中看到任何有助于以这种方式编写更新查询的功能。但是直接加载数据是 Toad 非常容易的事情。

May be you could do this.

也许你可以做到这一点。

create table tmp_excel_data
( column1 varchar2(100),
  column2 varchar2(100),
  client_id varchar2(100)
);

Use toad to directly load data into this table. The update is simple from this point.

使用 toad 直接将数据加载到该表中。从这一点来看,更新很简单。

update CLIENT_DATA tgt
  tgt.column1 = (select column1
                  from tmp_excel_data src
                  where tgt.client_id = src.client_id);

--dont forget to commit.

This will also let you cleanse your data (removing dups..for example) if needed.

如果需要,这还可以让您清理数据(例如删除重复项……)。

回答by lazygeek

I usually do something like this:

我通常做这样的事情:

SELECT 'UPDATE <TABLE_NAME> SET status =''' || status || '''  WHERE id =' || ID ||';'
FROM <TABLE_NAME>
WHERE <condition>