当前位置:网站首页>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');
边栏推荐
- 企业级分布式爬虫框架入门
- Ardupilot software in the loop simulation and online debugging
- 博途1200/1500PLC上升沿下降沿指令编程应用技巧(bool数组)
- 我的第二次博客——C语言
- Getting started with saltstack
- 11、 学习MySQL UNION 操作符
- 诺基亚扩大与英国电信的5G协议,将成其最大无线接入设备供应商
- NDK 系列(5):JNI 从入门到实践,爆肝万字详解!
- 英文翻译葡萄牙语-批量英文转换葡萄牙语-各种语言免费互译转换
- Smart contract security - overflow vulnerability
猜你喜欢

Fantasy 5 (ue5) game engine complete course 2022

Prometheus部署

BLDC 6-step commutation simulink

这个客制化键盘,秀翻我了~

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

SaltStack配置管理

How openocd directly downloads programs to STM32 board through stlink (solved)

Business visualization - let your flowchart "run" (4. Actual business scenario test)

Cvpr21 unsupervised anomaly detection cutpaste:self supervised learning for anomaly detection and localization

NDK 系列(5):JNI 从入门到实践,爆肝万字详解!
随机推荐
我的第二次博客——C语言
IMU 加热
英文翻译葡萄牙语-批量英文转换葡萄牙语-各种语言免费互译转换
英文翻译阿拉伯语-批量英文翻译阿拉伯语工具免费
英文翻译意大利语-批量英文翻译意大利语工具免费
调用整数或字符数组函数里的参数应该传入啥
芯片功耗性能验证:从困境到超越
C language cycle sentence strengthening exercises
BLDC 6步换相 simulink
使用SaltStack自动化部署Zabbix
2022年全国最新消防设施操作员(中级消防设施操作员)题库及答案
英文翻译西班牙语-批量英文翻译西班牙工具免费
Pytoch: quickly find the main diagonal elements and non diagonal elements of NxN matrix
Search problems and technologies
Doxygen document generation tool
Dockler的基础用法
博途1200/1500PLC上升沿下降沿指令编程应用技巧(bool数组)
npm安装和卸载全局包
Iclr21 (classification) - future classic "vit" an image is worth 16x16 words (including code analysis)
Ardupilot software in the loop simulation and online debugging