当前位置:首页 » 编程语言 » sqljson解析

sqljson解析

发布时间: 2022-08-06 13:53:23

Ⅰ 如何解析JSON数组到sql

例如:

源JSON数据:

{
"item1":{
"title":"2",
"value":null,
"visible":true,
"name":"item1",
"enabled":true,
"readonly":false,
"id":"f1f46ce6-9d0b-4eaf-88b7-d35b23a4d2e4"
},
"item2":{
"title":null,
"value":null
"visible":true,
"name":"item2",
"enabled":true,
"readonly":false,
"id":"da2b8a02-cfbd-4de8-8a33-74e2a484475a"
},
"item3":{
"title":"",
"value":null,
"visible":true,
"name":"item3",
"enabled":true,
"readonly":false,
"id":"57ee45d6-41d7-45c2-b022-13220e31d2d2"
}}

SQL查询

SELECT[Key].[key]AS[ItemName],[Value].*FROMOPENJSON(@json,'$')AS[Key]CROSSAPPLYOPENJSON([Key].value)
WITH(
TitleVARCHAR(100)'$.title',
ValueVARCHAR(100)'$.value',
VisibleVARCHAR(100)'$.visible',
NameVARCHAR(100)'$.name',
EnabledVARCHAR(100)'$.enabled',
ReadOnlyVARCHAR(100)'$.readonly',
IdVARCHAR(500)'$.id'
)AS[Value]

Ⅱ SQL server存储过程实现JSON数据解析,然后插入数据库表求高手指点

两种方式
1、SQL有个charindex 函数,可以用这个函数配合substr实现 split功能实现循环插入
2、sql 2008以上存储过程支持表值参数,json反序列化在程序里更方便,所以反序列化之后通过表值参数传递

Ⅲ sql中json解析

你好!

withtas(select'a:[{f:,h:,checindate:''month1:,year:,day:'',checkoutdate:''month:,year:,day:'',},
{checindate:''month2:,year:,day:,'',checkoutdate:''month:,year:,day},
{checindate:''month3:,year:,day:,'',checkoutdate:''month:,year:,day}]'strfromal)
,t1as(SELECTsubstr(str,instr(str,'[')+1,instr(str,']')-instr(str,'[')-1)strFROMT)
,t2as(selectsubstr(str,instr(str,'{')+1,instr(str,'}')-instr(str,'{')-1)strfromt1)
selectstr,substr(str,instr(str,'checindate')+12,instr(str,'checkoutdate')-instr(str,'checindate')-12)fromt2;

得到第一个checindate,直接截取字符串就可以了

别搞得那么复杂了

Ⅳ sql中对json数据字段的查询

先取出string,再在内存里转换为对象并检查。
ps:存json是没问题,但又想存json又想直接查,违反了数据库的范式。

Ⅳ mysql数据库中某个字段存的是json数据,如何对json数据中的数据进行操作

这个可以吧json格式的字符串解析成数组json_decode()函数,变成数组以后就可以方便操作了,可以删除数组中的任意一项,也可以增加一项比如:array_push($data,['sort'=>3,'catentryId'=>10003]),再变成json格式的存入数据库。方法有多种,这里简单的示例下

Ⅵ 如何获取从his系统json的数据解析为xml插入sql用c#实现

序列化只是将数据序列化为完整的准确无误的json格式的数据!
解析指的就是将你上面的json数据一一从json格式中分解出来,的到字符串格式的便于封装bean对像
建立一对多的对象
将value setter给你的bean对象!
最后将bean存数据库

Ⅶ 刚入职的菜鸟,在plsql中怎么拼接json字段

Oracle 12.1.0.2版本有一个新功能就是可以存储、查询、索引JSON数据格式,而且也实现了使用SQL语句来解析JSON,非常方便。JSON数据在数据库中以VARCHAR2, CLOB或者BLOB进行存储。Oracle建议用户在插入JSON数据之前,使用is_json来验证输入JSON数据的正确性。另外,Oracle也提供了相关的函数:
Functions:json_value, json_query, json_table.

Conditions:json_exists, is json, is not json, json_textcontains.

java将json数据解析为sql语句

importjava.util.Iterator;
importjava.util.Set;
importjava.util.Map.Entry;

importcom.google.gson.JsonArray;
importcom.google.gson.JsonElement;
importcom.google.gson.JsonObject;
importcom.google.gson.JsonParser;

publicclassSql
{
publicstaticStringparseSQL(Stringjson)
{
JsonParserparser=newJsonParser();
JsonObjectobj=(JsonObject)parser.parse(json);;
Stringtable=obj.get("table").getAsString();
Stringop_type=obj.get("op_type").getAsString();
Stringsql="";
if("I".equals(op_type))
{
sql+="INSERTINTO"+table+"(";
JsonObjectafter=(JsonObject)obj.get("after");
Set<Entry<String,JsonElement>>entry=after.entrySet();
Iterator<Entry<String,JsonElement>>it=entry.iterator();
Stringvs="values(";
while(it.hasNext())
{
Entry<String,JsonElement>elem=it.next();
Stringkey=elem.getKey();
Stringval=elem.getValue().toString();
sql+=key+",";
vs+=val+",";
}
sql=sql.replaceAll(",\s*$","");
vs=vs.replaceAll(",\s*$","");
sql+=")"+vs+")";
}
elseif("U".equals(op_type))
{
sql+="UPDATE"+table+"SET";
JsonObjectafter=(JsonObject)obj.get("after");
Set<Entry<String,JsonElement>>entry=after.entrySet();
Iterator<Entry<String,JsonElement>>it=entry.iterator();
while(it.hasNext())
{
Entry<String,JsonElement>elem=it.next();
Stringkey=elem.getKey();
Stringval=elem.getValue().toString();
sql+=key+"="+val+",";
}
sql=sql.replaceAll(",\s*$","");
sql+="WHERE";
after=(JsonObject)obj.get("before");
entry=after.entrySet();
it=entry.iterator();
while(it.hasNext())
{
Entry<String,JsonElement>elem=it.next();
Stringkey=elem.getKey();
Stringval=elem.getValue().toString();
sql+=key+"="+val+"AND";
}
sql=sql.replaceAll("\s*AND\s*$","");
}
elseif("D".equals(op_type))
{
sql+="DELETEFROM"+table+"WHERE";
JsonObjectafter=(JsonObject)obj.get("before");
Set<Entry<String,JsonElement>>entry=after.entrySet();
Iterator<Entry<String,JsonElement>>it=entry.iterator();
while(it.hasNext())
{
Entry<String,JsonElement>elem=it.next();
Stringkey=elem.getKey();
Stringval=elem.getValue().toString();
sql+=key+"="+val+"AND";
}
sql=sql.replaceAll("\s*AND\s*$","");
}
returnsql;
}

publicstaticvoidmain(String[]args)
{
Stringinsert=
"{"table":"GG.TCUSTORD","op_type":"I","op_ts":"2013-06-0222:14:36.000000","current_ts":"2015-09-18T13:39:35.447000","pos":"00000000000000001444","tokens":{"R":"AADPkvAAEAAEqL2AAA"},"after":{"CUST_CODE":"WILL","ORDER_DATE":"1994-09-30:15:33:00","PRODUCT_CODE":"CAR","ORDER_ID":"144","PRODUCT_PRICE":17520.00,"PRODUCT_AMOUNT":3,"TRANSACTION_ID":"100"}}";
Stringupdate=
"{"table":"GG.TCUSTORD","op_type":"U","op_ts":"2013-06-0222:14:41.000000","current_ts":"2015-09-18T13:39:35.748000","pos":"00000000000000002891","tokens":{"L":"206080450","6":"9.0.80330","R":"AADPkvAAEAAEqLzAAC"},"before":{"CUST_CODE":"BILL","ORDER_DATE":"1995-12-31:15:00:00","PRODUCT_CODE":"CAR","ORDER_ID":"765","PRODUCT_PRICE":15000.00,"PRODUCT_AMOUNT":3,"TRANSACTION_ID":"100"},"after":{"CUST_CODE":"BILL","ORDER_DATE":"1995-12-31:15:00:00","PRODUCT_CODE":"CAR","ORDER_ID":"765","PRODUCT_PRICE":14000.00,"PRODUCT_AMOUNT":3,"TRANSCATION_ID":"100"}}";
Stringdelete=
"{"table":"GG.TCUSTORD","op_type":"D","op_ts":"2013-06-0222:14:41.000000","current_ts":"2015-09-18T13:39:35.766000","pos":"00000000000000004338","tokens":{"L":"206080450","6":"9.0.80330","R":"AADPkvAAEAAEqLzAAC"},"before":{"CUST_CODE":"DAVE","ORDER_DATE":"1993-11-03:07:51:35","PRODUCT_CODE":"PLANE","ORDER_ID":"600"}}";
System.out.println(parseSQL(insert));
System.out.println(parseSQL(update));
System.out.println(parseSQL(delete));
}
}

热点内容
图片服务器ftp 发布:2025-01-22 15:52:33 浏览:506
sql打开bak文件 发布:2025-01-22 15:47:32 浏览:106
opengl服务器源码 发布:2025-01-22 15:40:02 浏览:908
python部署服务 发布:2025-01-22 15:38:46 浏览:282
压缩机卡装 发布:2025-01-22 15:37:04 浏览:446
每天跑步40分钟可以缓解压力吗 发布:2025-01-22 15:33:24 浏览:448
线性表的链式存储结构与顺序存储 发布:2025-01-22 15:32:45 浏览:295
解压缩大师 发布:2025-01-22 15:26:51 浏览:386
xp访问win7共享打印机无权限 发布:2025-01-22 15:23:22 浏览:830
python中pandas 发布:2025-01-22 15:21:42 浏览:639