unix shell 调用sqlplus 遍历表

gbcin 2014-05-23 03:07:33
我想在sh文件中写一段script实现功能是

1. 调用sqlplus去查一个表出来
2. 遍历查出来这张表的每一行,统计信息。

例如,有一个销售表 table
customer order
a 12
b 5
c 7
d 20

我想统计的是小于10,大于10小于20,大于20个order的customer个数。
不想通过3次调用select这样来查。

所以想在sh文件中,一次查出表来,然后我自己去遍历做统计。

多谢。
...全文
154 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
gbcin 2014-05-23
  • 打赏
  • 举报
回复
引用 1 楼 wildwave 的回复:
遍历?直接统计不就好了 select count(case when order <10 then 1 end) less_10, count(case when order >=10 and order<20 then 1 end) between_10_20, count(case when order>=20 then 1 end) more_20 from table;
抱歉哈,咱是菜鸟小白。 我是写在sh文件里面: #!/bin/sh sqlplus -S /nolog <<EOF set heading off feedback off pagesize 0 verify off echo off numwidth 6 conn comesa/lUft9SkrGb select count(case when order <10 then 1 end) less_10, count(case when order >=10 and order<20 then 1 end) between_10_20, count(case when order>=20 then 1 end) more_20 from table; exit EOF 不晓得less_10, between_10_20,more_20能不能在 EOF后面shell内使用,还是只能在EOF 之前使用。 我试试看哈。 多谢
小灰狼W 2014-05-23
  • 打赏
  • 举报
回复
遍历?直接统计不就好了 select count(case when order <10 then 1 end) less_10, count(case when order >=10 and order<20 then 1 end) between_10_20, count(case when order>=20 then 1 end) more_20 from table;

17,135

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧