通过OracleDB sqlplus在Shell脚本中使用for循环

我正在使用此脚本:

#!/bin/sh
for i in $(seq 1 20);
do
 echo "CREATE TABLE eugene_$i (id NUMber NOT NULL);
 ! sleep 10
 DeclARE j NUMber;
 BEGIN
  FOR j IN 1..20 LOOP
   select * from eugene_$i;
   ! sleep 10
  END LOOP;
 END;
 DROP TABLE eugene_$i;" | sqlplus system/password &
done
wait

我的目的是使连接保持活动状态,并运行重复性查询以进行测试。

目标是每次选择后等待10秒,然后调用下一个。

我根本没有选择。我认为内部for循环存在语法问题。

hongfuxiao 回答:通过OracleDB sqlplus在Shell脚本中使用for循环

在PL / SQL中发出select语句(作为隐式游标或显式游标)时,需要将值提取到变量中。您可以返回一行或批量将许多行收集到一个或多个变量中(例如,返回的每一列有一个标量变量,或者每行有一条记录)。

因此,脚本中的PL / SQL应该类似于:

DECLARE
  -- no need to declare the j variable; that's implicit to the `FOR ... loop`
  id number; 
BEGIN
 FOR j IN 1..20 LOOP
  select *
  into   id
  from   eugene_$i;
  ! sleep 10 -- I'm not sure this will work in your script; it's not Oracle syntax,but may get translated by your script?
 END LOOP;
END;
/
本文链接:https://www.f2er.com/3073684.html

大家都在问