正则表达式将十进制运算符从逗号更改为点?

时间:2018-03-07 15:29:09

标签: regex notepad++

我从一个检索到的文本文件中有一堆插入查询,让我们说Oracle DB1。现在我必须在另一个数据库中执行插入SQL,让我们说Oracle DB2。现在问题是DB1中的小数分隔符是","但在DB2中,它是"。"。所以我在插入期间在DB2中收到错误,因为"无效的数字"。如何更改","中的小数点分隔符?到"。"在记事本++中。以下是插入查询的2个示例。

Insert into schema1.tab1 (uniq_identifier,branch,INT_TYPE,NOM_RATE,EFF_RATE,FACTOR,START_DATE,END_DATE,BOOK_AMT,BOOK_FLG,LAST_BOOKED_DATE,INT_PAID_FLG,INT_PAID_AMT,WTAX_AMT,INT_PAYMENT_DATE,END_FLG,REVERSE_FLG,entity_id,create_user_id,creation_time,modified_user_id,modif_time,INT_PAID_TRAN_ID) values ('55000116754','BC000088','G','1.961','1.98','0,000054',to_date('22/06/17 00:00:00','DD/MM/RR HH24:mi:ss'),to_date('04/07/17 00:00:00','DD/MM/RR HH24:mi:ss'),'1252,75','N',to_date('27/06/17 00:00:00','DD/MM/RR HH24:mi:ss'),'Y','1252,73','50,11',null,'Y','N','1000','FINADM',to_date('21/06/17 20:49:50','DD/MM/RR HH24:mi:ss'),'user1',to_date('27/06/17 22:01:20','DD/MM/RR HH24:mi:ss'),null);

Insert into schema1.tab1 (uniq_identifier,branch,INT_TYPE,NOM_RATE,EFF_RATE,FACTOR,START_DATE,END_DATE,BOOK_AMT,BOOK_FLG,LAST_BOOKED_DATE,INT_PAID_FLG,INT_PAID_AMT,WTAX_AMT,INT_PAYMENT_DATE,END_FLG,REVERSE_FLG,entity_id,create_user_id,creation_time,modified_user_id,modif_time,INT_PAID_TRAN_ID) values ('55000065422','BC000008','G','1.961','1.98','0,000054',to_date('20/06/17 00:00:00','DD/MM/RR HH24:mi:ss'),to_date('29/06/17 00:00:00','DD/MM/RR HH24:mi:ss'),'4586,34','N',to_date('27/06/17 00:00:00','DD/MM/RR HH24:mi:ss'),'Y','4586,36','183,45',null,'Y','N','1000','user1',to_date('18/06/17 08:03:49','DD/MM/RR HH24:mi:ss'),'user1',to_date('27/06/17 21:59:42','DD/MM/RR HH24:mi:ss'),null);

现在,如果您看到查询,则有两个带逗号的金额字段。在第一个查询中,我们有'1252,73','50,11',在第二个查询中,我们有'4586,36','183,45'

3 个答案:

答案 0 :(得分:1)

搜索(\d),(\d)

替换为$1.$2

这是一个Javascript演示:

var str = `Insert into schema1.tab1 (uniq_identifier,branch,INT_TYPE,NOM_RATE,EFF_RATE,FACTOR,START_DATE,END_DATE,BOOK_AMT,BOOK_FLG,LAST_BOOKED_DATE,INT_PAID_FLG,INT_PAID_AMT,WTAX_AMT,INT_PAYMENT_DATE,END_FLG,REVERSE_FLG,entity_id,create_user_id,creation_time,modified_user_id,modif_time,INT_PAID_TRAN_ID) values ('55000116754','BC000088','G','1.961','1.98','0,000054',to_date('22/06/17 00:00:00','DD/MM/RR HH24:mi:ss'),to_date('04/07/17 00:00:00','DD/MM/RR HH24:mi:ss'),'1252,75','N',to_date('27/06/17 00:00:00','DD/MM/RR HH24:mi:ss'),'Y','1252,73','50,11',null,'Y','N','1000','FINADM',to_date('21/06/17 20:49:50','DD/MM/RR HH24:mi:ss'),'user1',to_date('27/06/17 22:01:20','DD/MM/RR HH24:mi:ss'),null);`;

console.log(str.replace(/(\d),(\d)/g,'$1.$2'));

答案 1 :(得分:0)

  • 控制 + ħ
  • 找到:\d\K,(?=\d)
  • 替换为:.
  • 检查环绕
  • 检查正则表达式
  • 全部替换

<强>解释

\d      : a digit
\K      : forget all we have seen until this position
,       : a comma
(?=     : lookahead, zerolength asszrertion, make sure we have:
  \d    : a digit
)       : end lookahead

给定示例的结果:

Insert into schema1.tab1 (uniq_identifier,branch,INT_TYPE,NOM_RATE,EFF_RATE,FACTOR,START_DATE,END_DATE,BOOK_AMT,BOOK_FLG,LAST_BOOKED_DATE,INT_PAID_FLG,INT_PAID_AMT,WTAX_AMT,INT_PAYMENT_DATE,END_FLG,REVERSE_FLG,entity_id,create_user_id,creation_time,modified_user_id,modif_time,INT_PAID_TRAN_ID) values ('55000116754','BC000088','G','1.961','1.98','0.000054',to_date('22/06/17 00:00:00','DD/MM/RR HH24:mi:ss'),to_date('04/07/17 00:00:00','DD/MM/RR HH24:mi:ss'),'1252.75','N',to_date('27/06/17 00:00:00','DD/MM/RR HH24:mi:ss'),'Y','1252.73','50.11',null,'Y','N','1000','FINADM',to_date('21/06/17 20:49:50','DD/MM/RR HH24:mi:ss'),'user1',to_date('27/06/17 22:01:20','DD/MM/RR HH24:mi:ss'),null);

Insert into schema1.tab1 (uniq_identifier,branch,INT_TYPE,NOM_RATE,EFF_RATE,FACTOR,START_DATE,END_DATE,BOOK_AMT,BOOK_FLG,LAST_BOOKED_DATE,INT_PAID_FLG,INT_PAID_AMT,WTAX_AMT,INT_PAYMENT_DATE,END_FLG,REVERSE_FLG,entity_id,create_user_id,creation_time,modified_user_id,modif_time,INT_PAID_TRAN_ID) values ('55000065422','BC000008','G','1.961','1.98','0.000054',to_date('20/06/17 00:00:00','DD/MM/RR HH24:mi:ss'),to_date('29/06/17 00:00:00','DD/MM/RR HH24:mi:ss'),'4586.34','N',to_date('27/06/17 00:00:00','DD/MM/RR HH24:mi:ss'),'Y','4586.36','183.45',null,'Y','N','1000','user1',to_date('18/06/17 08:03:49','DD/MM/RR HH24:mi:ss'),'user1',to_date('27/06/17 21:59:42','DD/MM/RR HH24:mi:ss'),null);

答案 2 :(得分:0)

实际上,您不需要在insert语句中更改任何内容,因为小数分隔符是Oracle中特定于会话的参数,可以轻松更改(即参见this question on Ask Tom)。 在执行文件之前更改NLS_NUMERIC_CHARACTERS会话参数(在文件的最开头放置以下行):

alter session set NLS_NUMERIC_CHARACTERS = ',.';