Splunk Search

How to read data from a CSV file and put into DB Connect’s query?

ritesh21aggarwa
Engager

Hi,

I want to pull data from a CSV file and put that all data in a SQL query.
For e.g.-
In CSV:
'ABC','DEF','GHI','JKL','MNO'
SQL QUERY:
SELECT emp_name FROM emp WHERE emp_name IN ('ABC','DEF','GHI','JKL','MNO')

I want these “emp_name” get into my SQL query form CSV automatically.

Please help me on this.

Regards,
Ritesh Aggarwal

Tags (1)

jcoates_splunk
Splunk Employee
Splunk Employee

try putting the database query command into a map command. I just messed around with this on DBX2, appears to work well:

state="WA" OR state="CA" | map search="|dbxquery query=\"SELECT%20*%20FROM%20%60northwind%60.%60employees%60%20WHERE%20Region%3D%22$state$%22\" connection=\"dbx-mysql\""

I used this page to url encode: http://meyerweb.com/eric/tools/dencoder/

Forgot to mention -- this will be wicked slow and may make your DBA angry because it's calling that sql command over and over again. If you're going to do this in production, you should just index or lookup your database table and then do the whole job in SPL.

0 Karma
Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...