我有一条日志消息,我必须通过sql查询从中提取列, 消息的样子:
“设备= EOHCS-ZA-JIS-FW严重性=高来自= EOHCloudFAZ(FL1KVM0000005594)触发器=系统日志关键系统警报log =” logver = 54 itime = 1528457940 devid = FG1K5D3I13800425 devname = FWJIS01 vd = 95_LHC date = 2018- 06-08 time = 13:34:55 logid = 0100044546 type = event子类型= system level =信息logdesc =“属性已配置” user =“ JoshuaK” ui =“ ha_daemon” action =编辑cfgtid = 701760128 cfgpath =“ system.settings “ cfgattr =” gui-allow-unnamed-policy [disable-> enable]“ msg =”编辑system.settings“”“
有人可以给我一个主意
答案 0 :(得分:0)
我有一个针对SQL Server的解决方案,您可以使用PATINDEX并提取日志消息。
下面是从值中提取的代码
declare @input nVarchar(max),@from nVarchar(MAX)
declare @FromStart int,@FromEnd int
set @input='device=EOHCS-ZA-JIS-FW severity=high from=EOHCloudFAZ(FL1KVM0000005594) trigger=Syslog Critical System Alerts log="logver=54 itime=1528457940 devid=FG1K5D3I13800425 devname=FWJIS01 vd=95_LHC date=2018-06-08 time=13:34:55 logid=0100044546 type=event subtype=system level=information logdesc="Attribute configured" user="JoshuaK" ui="ha_daemon" action=Edit cfgtid=701760128 cfgpath="system.settings" cfgattr="gui-allow-unnamed-policy[disable->enable]" msg="Edit system.settings';
SET @FromStart=PATINDEX('%from=%',@input)+5;
SET @FromEnd=PATINDEX('% trigger=%',@input)-@FromStart;
SELECT @from=SUBSTRING(@input,@FromStart,@FromEnd)
SELECT @from
注意:对相应的数据库服务器使用PATINDEX的等效项。另外请注意,仅当输入字符串具有定义顺序的参数时,此方法才有效。