当前位置:网站首页>Oracle insert数据时字符串中有‘单引号问题
Oracle insert数据时字符串中有‘单引号问题
2022-07-28 17:46:00 【浅殇忆流年】

在我们把Excel表格数据插入表中的时候,常常使用拼接insert 语句的方式;
当excel表格数据遇到单引号的时候,最后得到的insert into如下:
insert into test(id,name,age)values(sys_guid(),'张'三','28');
此时得到的SQL执行会报错。
解决方案:
判断一下val1,val2中是否含有单引号,若含单引号,则将单引号’替换成两个单引号’'的格式。
下面提供一个简单的工具类:
public static String replaceStr(String sourceStr) {
if (StrUtil.isBlank(sourceStr)) {
return "";
}
String substring = sourceStr.substring(1, sourceStr.length() - 1);
if (substring.contains("'")) {
String replaceStr = substring.replace("'", "''");
return "'" + replaceStr + "'";
}
return sourceStr;
}
最终处理得到的SQL语句如下:
insert into test(id,name,age)values(sys_guid(),'张''三','28');
边栏推荐
- 使用SaltStack自动化部署Zabbix
- 远光软件获得阿里云产品生态集成认证,携手阿里云共建新合作
- 可转债概念表 x Notion 给你方便快捷的体验!
- After reading the thesis for three years, I learned to read the abstract today
- Fantasy 5 (ue5) game engine complete course 2022
- 企业级分布式爬虫框架入门
- NDK 系列(5):JNI 从入门到实践,爆肝万字详解!
- Rust 入门指南(modules 和工程结构)
- New this prototype precompiled exercise
- When CNN meets transformer cmt:revolutionary neural networks meet vision transformers
猜你喜欢

Nips18 (AD) - unsupervised anomaly detection using geometric transformations using geometric augmentation

彻底理解位运算——左移、右移

Swing事件处理的过程是怎样的?

企业级分布式爬虫框架入门

Android-第十三节03xUtils-数据库框架(增删改查)详解

Pytoch: quickly find the main diagonal elements and non diagonal elements of NxN matrix

App自动化测试是怎么实现H5测试的

SaltStack入门

JS modify table font and table border style

Cvpr19 - adjust reference dry goods bag of tricks for image classification with revolutionary neural network
随机推荐
With the help of panel industry innovation, will FPGA become the best choice for TCON?
Saltstack system initialization
2022年全国最新消防设施操作员(中级消防设施操作员)题库及答案
远光软件获得阿里云产品生态集成认证,携手阿里云共建新合作
彻底理解位运算——与(&)、非(~)、或(|)、异或(^)
Pandownload revival tutorial
Germany and Portugal have announced that they will not disable Huawei 5g equipment, but Germany will set strict restrictions!
为研发高端光刻胶,晶瑞股份斥资7500万元购买SK海力士的ASML光刻机
使用SaltStack自动化部署Zabbix
SaltStack常用的模块
The opening price soared by 215%! Domestic signal chain chip enterprise Xinhai Technology landed on the scientific innovation board
SaltStack之数据系统
Doxygen document generation tool
Rust 入门指南(rustup, cargo)
lua语言的左对齐函数(手写)
SaltStack之salt-ssh
芯片功耗性能验证:从困境到超越
MySQL8 Encrypting InnoDB Tablespaces
BLDC 6步换相 simulink
宝塔面板搭建小说CMS管理系统源码实测 - ThinkPHP6.0