如何在Shell脚本中验证更新或选择查询?

时间:2019-02-09 12:55:49

标签: sql linux oracle shell

我正在尝试验证更新或在Shell脚本中选择查询。

例如,我的查询是:

update table_name set col_name = 1 where emp_id = '1234'

如果代码将验证第一个单词必须为update,第二个单词必须为table_name,第三个单词必须为set。我试图进行验证,但无法获得结果。

1 个答案:

答案 0 :(得分:0)

我创建了一个非常简单的python脚本,可在v2和v3中使用。

将内容复制到filename.py并执行sudo chmod +x filename.py

#!/usr/bin/env python

string = "update table_name set col_name = 1 where emp_id = '1234'"

x = string.split(' ')
if "update" != x[0]:
    print("the first word does not contain update, exiting")
    exit
else:
    print("the first word contains update")

if "update" != x[1]:
    print("the second word does not contain table_name, exiting")
    exit
else:
    print("the second word contains table_name")

if "update" != x[2]:
    print("the third word does not contain set, exiting")
    exit
else:
    print("the third word contains set")

print("we're good to go")