插入脚本中的高级替换
Advance Replace in insert scripts
我有以下 2 条插入语句,它们是我从 sql 开发人员从开发环境中导出的。之后我从 dev 中删除了这些记录。现在我想在 dev 中再次 运行 这个插入语句,因为这些是我的备份,但我收到错误,因为虚拟列 ORD_DAYID 不能在插入脚本中使用。所以我想排除此列以及使用替换函数或我不知道的任何工具的相应值。我以前不知道我有这个 table 的虚拟专栏。我想知道是否有任何工具或功能可以 select ORD_DAYID 并且相应的值也得到 selected 然后我可以删除它们然后我可以 运行 在测试环境中再次插入语句。
P.S 我只提到了 2 个示例插入语句,但有 1000 个插入语句。因此,很难从具有相应值的插入语句中手动删除此 ORD_DAYID。
Insert into test_ord (IS_GRP,ORD_DAYID,REF_CAMPA_CODE) values (1,20150813,null);
Insert into test_ord (IS_GRP,ORD_DAYID,REF_CAMPA_CODE) values (1,20150828,null);
您可以在 Notepad++ 等编辑器中使用正则表达式编辑 INSERT 语句。
所以要改变这个...
Insert into test_ord (IS_GRP,ORD_DAYID,REF_CAMPA_CODE) values (1,20150813,null);
...进入这个...
Insert into test_ord (IS_GRP,REF_CAMPA_CODE) values (1,null);
您需要 搜索 模式:
Insert into test_ord \(IS_GRP,ORD_DAYID,REF_CAMPA_CODE\) values \(([0-9]+),([0-9]+),null\);
和替换模式:
Insert into test_ord \(IS_GRP,REF_CAMPA_CODE\) values \(,null\);
显然,您需要细化搜索模式,以满足 1000 条语句中 IS_GRP 和 REF_CAMPA_CODE 的所有不同值。
" is there any way where we can count the place of column and value and replace it with null"
没有。虚拟列的问题在于它们不能在 INSERT 或 UPDATE 语句中被引用。所以你需要把它完全排除在投影之外。
"i am not able to find those option in notepad++"
真的吗?搜索和替换不是一个奇特的选项:
- 从菜单中:
Search > Find > Replace [tab]
(或[ctrl]+h
)
- 作为搜索模式 select
regular expression
单选按钮
- 创建一个没有虚拟列的辅助 table。
- 将您的数据恢复到此辅助table。
- 将数据从辅助table转移到原始table。
-- this is your table
create table mytab(A number, b number, s as (a+b));
--fill it with data
insert into mytab(a,b) values(1,1);
insert into mytab(a,b) values(1,2);
insert into mytab(a,b) values(2,1);
insert into mytab(a,b) values(2,2);
commit;
-- check its content
select * from mytab;
-- now delete the rows
delete from mytab;
commit;
-- restore your data
--------------------
-- create a table similar the table you want to restore
-- but the virtual colums as regular columns.
create table ctas as
select * from mytab where 1!=0;
-- insert your backup data
insert into ctas(a,b,s) values(1,1,2);
insert into ctas(a,b,s) values(1,2,3);
insert into ctas(a,b,s) values(2,1,3);
insert into ctas(a,b,s) values(2,2,4);
commit;
-- transfer the data to the table you want to restore
insert into mytab(a,b) select a,b from ctas;
我有以下 2 条插入语句,它们是我从 sql 开发人员从开发环境中导出的。之后我从 dev 中删除了这些记录。现在我想在 dev 中再次 运行 这个插入语句,因为这些是我的备份,但我收到错误,因为虚拟列 ORD_DAYID 不能在插入脚本中使用。所以我想排除此列以及使用替换函数或我不知道的任何工具的相应值。我以前不知道我有这个 table 的虚拟专栏。我想知道是否有任何工具或功能可以 select ORD_DAYID 并且相应的值也得到 selected 然后我可以删除它们然后我可以 运行 在测试环境中再次插入语句。
P.S 我只提到了 2 个示例插入语句,但有 1000 个插入语句。因此,很难从具有相应值的插入语句中手动删除此 ORD_DAYID。
Insert into test_ord (IS_GRP,ORD_DAYID,REF_CAMPA_CODE) values (1,20150813,null);
Insert into test_ord (IS_GRP,ORD_DAYID,REF_CAMPA_CODE) values (1,20150828,null);
您可以在 Notepad++ 等编辑器中使用正则表达式编辑 INSERT 语句。
所以要改变这个...
Insert into test_ord (IS_GRP,ORD_DAYID,REF_CAMPA_CODE) values (1,20150813,null);
...进入这个...
Insert into test_ord (IS_GRP,REF_CAMPA_CODE) values (1,null);
您需要 搜索 模式:
Insert into test_ord \(IS_GRP,ORD_DAYID,REF_CAMPA_CODE\) values \(([0-9]+),([0-9]+),null\);
和替换模式:
Insert into test_ord \(IS_GRP,REF_CAMPA_CODE\) values \(,null\);
显然,您需要细化搜索模式,以满足 1000 条语句中 IS_GRP 和 REF_CAMPA_CODE 的所有不同值。
" is there any way where we can count the place of column and value and replace it with null"
没有。虚拟列的问题在于它们不能在 INSERT 或 UPDATE 语句中被引用。所以你需要把它完全排除在投影之外。
"i am not able to find those option in notepad++"
真的吗?搜索和替换不是一个奇特的选项:
- 从菜单中:
Search > Find > Replace [tab]
(或[ctrl]+h
) - 作为搜索模式 select
regular expression
单选按钮
- 创建一个没有虚拟列的辅助 table。
- 将您的数据恢复到此辅助table。
- 将数据从辅助table转移到原始table。
-- this is your table create table mytab(A number, b number, s as (a+b)); --fill it with data insert into mytab(a,b) values(1,1); insert into mytab(a,b) values(1,2); insert into mytab(a,b) values(2,1); insert into mytab(a,b) values(2,2); commit; -- check its content select * from mytab; -- now delete the rows delete from mytab; commit; -- restore your data -------------------- -- create a table similar the table you want to restore -- but the virtual colums as regular columns. create table ctas as select * from mytab where 1!=0; -- insert your backup data insert into ctas(a,b,s) values(1,1,2); insert into ctas(a,b,s) values(1,2,3); insert into ctas(a,b,s) values(2,1,3); insert into ctas(a,b,s) values(2,2,4); commit; -- transfer the data to the table you want to restore insert into mytab(a,b) select a,b from ctas;