Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle 在SHELL中迭代PL/SQL结果_Oracle_Shell_Unix - Fatal编程技术网

Oracle 在SHELL中迭代PL/SQL结果

Oracle 在SHELL中迭代PL/SQL结果,oracle,shell,unix,Oracle,Shell,Unix,我想在SHELL脚本中迭代PL/SQL行,并且对于每一行,我想使用当前行执行一些代码。在这一点上,我得到: VALUE='sqlplus -s /nolog <<EOF CONNECT ${CONNECT} select smth from table; / EXIT EOF' for i in "${VALUE[@]}" do ##some code using "i" variable done

我想在SHELL脚本中迭代PL/SQL行,并且对于每一行,我想使用当前行执行一些代码。在这一点上,我得到:

    VALUE='sqlplus -s /nolog <<EOF
     CONNECT ${CONNECT}
       select smth from table;
        /
        EXIT
        EOF'

for i in "${VALUE[@]}"
do
##some code using "i" variable
done

VALUE='sqlplus-s/nolog您可以按如下方式迭代结果集:

SQL> select car_model from available_models
  2  group by car_model ;

CAR_MODEL
------------------------------
Corsair
Executive
Country Squire

SQL>
[oracle@ora12c 1]$ cat test.sh
CONNECT='z_test/welcome1'
VALUE=`sqlplus -s /nolog <<EOF
     CONNECT ${CONNECT}
     set head off
     select car_model from available_models
     group by car_model
        /
        EXIT
EOF`

echo "resultset: "
echo "${VALUE}"

echo " "

echo "now iterate ..."
let rec=0

echo "${VALUE}" |while read line
do
  echo "processing $rec: $line"
  let rec=rec+1
done

[oracle@ora12c 1]$
重写shell脚本(使用WHILE),如下所示:

SQL> select car_model from available_models
  2  group by car_model ;

CAR_MODEL
------------------------------
Corsair
Executive
Country Squire

SQL>
[oracle@ora12c 1]$ cat test.sh
CONNECT='z_test/welcome1'
VALUE=`sqlplus -s /nolog <<EOF
     CONNECT ${CONNECT}
     set head off
     select car_model from available_models
     group by car_model
        /
        EXIT
EOF`

echo "resultset: "
echo "${VALUE}"

echo " "

echo "now iterate ..."
let rec=0

echo "${VALUE}" |while read line
do
  echo "processing $rec: $line"
  let rec=rec+1
done

[oracle@ora12c 1]$
请注意,第#0行为空,应为空,因为它也是结果集的一部分

添加“设置页面大小0”将删除此空行:

[oracle@ora12c 1]$ cat test.sh
CONNECT='z_test/welcome1'
VALUE=`sqlplus -s /nolog <<EOF
     CONNECT ${CONNECT}
     set head off
     set pagesize 0
     select car_model from available_models
     group by car_model
        /
        EXIT
EOF`
......

关于

您可以按如下方式迭代您的结果集:

SQL> select car_model from available_models
  2  group by car_model ;

CAR_MODEL
------------------------------
Corsair
Executive
Country Squire

SQL>
[oracle@ora12c 1]$ cat test.sh
CONNECT='z_test/welcome1'
VALUE=`sqlplus -s /nolog <<EOF
     CONNECT ${CONNECT}
     set head off
     select car_model from available_models
     group by car_model
        /
        EXIT
EOF`

echo "resultset: "
echo "${VALUE}"

echo " "

echo "now iterate ..."
let rec=0

echo "${VALUE}" |while read line
do
  echo "processing $rec: $line"
  let rec=rec+1
done

[oracle@ora12c 1]$
重写shell脚本(使用WHILE),如下所示:

SQL> select car_model from available_models
  2  group by car_model ;

CAR_MODEL
------------------------------
Corsair
Executive
Country Squire

SQL>
[oracle@ora12c 1]$ cat test.sh
CONNECT='z_test/welcome1'
VALUE=`sqlplus -s /nolog <<EOF
     CONNECT ${CONNECT}
     set head off
     select car_model from available_models
     group by car_model
        /
        EXIT
EOF`

echo "resultset: "
echo "${VALUE}"

echo " "

echo "now iterate ..."
let rec=0

echo "${VALUE}" |while read line
do
  echo "processing $rec: $line"
  let rec=rec+1
done

[oracle@ora12c 1]$
请注意,第#0行为空,应为空,因为它也是结果集的一部分

添加“设置页面大小0”将删除此空行:

[oracle@ora12c 1]$ cat test.sh
CONNECT='z_test/welcome1'
VALUE=`sqlplus -s /nolog <<EOF
     CONNECT ${CONNECT}
     set head off
     set pagesize 0
     select car_model from available_models
     group by car_model
        /
        EXIT
EOF`
......

关于

您可以按如下方式迭代您的结果集:

SQL> select car_model from available_models
  2  group by car_model ;

CAR_MODEL
------------------------------
Corsair
Executive
Country Squire

SQL>
[oracle@ora12c 1]$ cat test.sh
CONNECT='z_test/welcome1'
VALUE=`sqlplus -s /nolog <<EOF
     CONNECT ${CONNECT}
     set head off
     select car_model from available_models
     group by car_model
        /
        EXIT
EOF`

echo "resultset: "
echo "${VALUE}"

echo " "

echo "now iterate ..."
let rec=0

echo "${VALUE}" |while read line
do
  echo "processing $rec: $line"
  let rec=rec+1
done

[oracle@ora12c 1]$
重写shell脚本(使用WHILE),如下所示:

SQL> select car_model from available_models
  2  group by car_model ;

CAR_MODEL
------------------------------
Corsair
Executive
Country Squire

SQL>
[oracle@ora12c 1]$ cat test.sh
CONNECT='z_test/welcome1'
VALUE=`sqlplus -s /nolog <<EOF
     CONNECT ${CONNECT}
     set head off
     select car_model from available_models
     group by car_model
        /
        EXIT
EOF`

echo "resultset: "
echo "${VALUE}"

echo " "

echo "now iterate ..."
let rec=0

echo "${VALUE}" |while read line
do
  echo "processing $rec: $line"
  let rec=rec+1
done

[oracle@ora12c 1]$
请注意,第#0行为空,应为空,因为它也是结果集的一部分

添加“设置页面大小0”将删除此空行:

[oracle@ora12c 1]$ cat test.sh
CONNECT='z_test/welcome1'
VALUE=`sqlplus -s /nolog <<EOF
     CONNECT ${CONNECT}
     set head off
     set pagesize 0
     select car_model from available_models
     group by car_model
        /
        EXIT
EOF`
......

关于

您可以按如下方式迭代您的结果集:

SQL> select car_model from available_models
  2  group by car_model ;

CAR_MODEL
------------------------------
Corsair
Executive
Country Squire

SQL>
[oracle@ora12c 1]$ cat test.sh
CONNECT='z_test/welcome1'
VALUE=`sqlplus -s /nolog <<EOF
     CONNECT ${CONNECT}
     set head off
     select car_model from available_models
     group by car_model
        /
        EXIT
EOF`

echo "resultset: "
echo "${VALUE}"

echo " "

echo "now iterate ..."
let rec=0

echo "${VALUE}" |while read line
do
  echo "processing $rec: $line"
  let rec=rec+1
done

[oracle@ora12c 1]$
重写shell脚本(使用WHILE),如下所示:

SQL> select car_model from available_models
  2  group by car_model ;

CAR_MODEL
------------------------------
Corsair
Executive
Country Squire

SQL>
[oracle@ora12c 1]$ cat test.sh
CONNECT='z_test/welcome1'
VALUE=`sqlplus -s /nolog <<EOF
     CONNECT ${CONNECT}
     set head off
     select car_model from available_models
     group by car_model
        /
        EXIT
EOF`

echo "resultset: "
echo "${VALUE}"

echo " "

echo "now iterate ..."
let rec=0

echo "${VALUE}" |while read line
do
  echo "processing $rec: $line"
  let rec=rec+1
done

[oracle@ora12c 1]$
请注意,第#0行为空,应为空,因为它也是结果集的一部分

添加“设置页面大小0”将删除此空行:

[oracle@ora12c 1]$ cat test.sh
CONNECT='z_test/welcome1'
VALUE=`sqlplus -s /nolog <<EOF
     CONNECT ${CONNECT}
     set head off
     set pagesize 0
     select car_model from available_models
     group by car_model
        /
        EXIT
EOF`
......

关于

要么查询没有返回数据,要么for循环中出现错误;在这种情况下,您可以相应地进行更新;在这种情况下,您可以相应地进行更新;在这种情况下,您可以相应地进行更新;在这种情况下,您可以相应地进行更新。