0

我们在应用程序中更改了一些用户名,但是数据库中的一些历史记录等也需要更新。有一个文件update_users.list,其中旧用户名和新用户名用空格分隔,每行 2 个用户名。

下面的脚本是正确的,还是有一些明显的问题?

#!/bin/bash

cat update_users.list | while read old_user new_user
do
sqlplus -s $user/$pass@$db > user_output.log <<EOF
UPDATE auf_kopf SET kopf_sach = '%${new_user}%' WHERE kopf_sach = '%${old_user}%';
UPDATE auf_prot SET sach_bearb = '%${new_user}%' WHERE sach_bearb = '%${old_user}%';
UPDATE auf_prot_hint SET sach_bearb = '%${new_user}%' WHERE sach_bearb = '%${old_user}%';
UPDATE ordhist SET user_code = '%${new_user}%' WHERE user_code = '%${old_user}%';
UPDATE liefer_daten SET sach_bearb = '%${new_user}%' WHERE sach_bearb = '%${old_user}%';
UPDATE shipment_head SET shipment_sach = '%${new_user}%' WHERE shipment_sach = '%${old_user}%';
UPDATE lager_bew SET lb_sachbearb = '%${new_user}%' WHERE lb_sachbearb = '%${old_user}%';
UPDATE lager_abzu SET abzu_sachbearb = '%${new_user}%' WHERE abzu_sachbearb = '%${old_user}%';
UPDATE best_kopf SET best_sach = '%${new_user}%' WHERE best_sach = '%${old_user}%';
UPDATE rcpt_header SET user_name = '%${new_user}%' WHERE user_name = '%${old_user}%';
UPDATE stat_kopf SET st_kopf_sach = '%${new_user}%' WHERE st_kopf_sach = '%${old_user}%';
UPDATE stat_mod SET stat_user = '%${new_user}%' WHERE stat_user = '%${old_user}%';
/
exit
EOF
4

1 回答 1

2

我先将输入写入 SQL-scriptfile 然后执行它:

awk '{print "UPDATE TABLE usertable SET col=" $2 " WHERE col=" $1 ";"}' <input >script.sql; 
echo "/" >>script.sql;  
sqlplus user/pass @script.sql;
于 2013-08-07T11:29:05.723 回答