当前位置:网站首页>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');
边栏推荐
- MySQL8 Status Variables: Internal Temporary Tables and Files
- Share several coding code receiving verification code platforms, which will be updated in February 2022
- redis 主从架构(sizeof函数怎么计算)
- Transformer for anomaly detection - instra "painting transformer for anomaly detection"
- Sudo rosdep init error: cannot download default
- NPM installing and uninstalling global packages
- BeanFactory not initialized or already closed - call ‘refresh‘ before accessing beans via the Applic
- 助力面板行业创新,FPGA将成屏厂TCON最佳选择?
- 测试开发备忘
- App自动化测试是怎么实现H5测试的
猜你喜欢

Rust 入门指南(rustup, cargo)

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

VAE: understanding and implementation of variational self encoder

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

SaltStack进阶

When CNN meets transformer cmt:revolutionary neural networks meet vision transformers

使用SaltStack自动化部署LNMP

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

Rust Getting Started Guide (modules and engineering structures)

SaltStack系统初始化
随机推荐
Huawei shares in Nanjing core vision, laying out the solid-state laser radar chip field
Asp net MVC web development tutorial
Update of objects in ES6
Saltstack configuration management
idea properties文件显示\u不显示中文的解决
App自动化测试是怎么实现H5测试的
MySQL8 Encrypting InnoDB Tablespaces
NPM installing and uninstalling global packages
With the help of panel industry innovation, will FPGA become the best choice for TCON?
shared_ptr 和 make_shared 的使用
Cvpr19 - adjust reference dry goods bag of tricks for image classification with revolutionary neural network
测试开发备忘
德国、葡萄牙均宣布不会禁用华为5G设备,但德国会设定严格限制条件!
Smart contract security - overflow vulnerability
MySQL8 tmp_table_size和max_heap_table_size
Pagoda panel construction novel CMS management system source code measurement - thinkphp6.0
When CNN meets transformer cmt:revolutionary neural networks meet vision transformers
英文翻译意大利语-批量英文翻译意大利语工具免费
The opening price soared by 215%! Domestic signal chain chip enterprise Xinhai Technology landed on the scientific innovation board
WPF implements MessageBox message prompt box with mask