oracle要导出一张表的数据,应该如何用纯语句来写
比如:SELECT*FROM(SELECTSUBSTR(TABLE_NAME,1,LENGTH(TABLE_NAME)-5)TABLE_NAME,SUM(COUNTS)C...
比如:
SELECT *
FROM (SELECT SUBSTR(TABLE_NAME, 1, LENGTH(TABLE_NAME) - 5) TABLE_NAME,
SUM(COUNTS) COUNTS
FROM GLMIS_TABLES_COUNTS
WHERE SUBSTR(TABLE_NAME, -4, 4) >= '2000'
AND SUBSTR(TABLE_NAME, -4, 4) <= '2010'
GROUP BY SUBSTR(TABLE_NAME, 1, LENGTH(TABLE_NAME) - 5)
UNION ALL
SELECT TABLE_NAME, COUNTS
FROM GLMIS_TABLES_COUNTS
WHERE SUBSTR(TABLE_NAME, -4, 4) < '2000'
OR SUBSTR(TABLE_NAME, -4, 4) > '2010') SRC
ORDER BY SRC.TABLE_NAME ASC
这样的SQL,要如何通过语句写在SHELL脚本中,让它能实现导出来 展开
SELECT *
FROM (SELECT SUBSTR(TABLE_NAME, 1, LENGTH(TABLE_NAME) - 5) TABLE_NAME,
SUM(COUNTS) COUNTS
FROM GLMIS_TABLES_COUNTS
WHERE SUBSTR(TABLE_NAME, -4, 4) >= '2000'
AND SUBSTR(TABLE_NAME, -4, 4) <= '2010'
GROUP BY SUBSTR(TABLE_NAME, 1, LENGTH(TABLE_NAME) - 5)
UNION ALL
SELECT TABLE_NAME, COUNTS
FROM GLMIS_TABLES_COUNTS
WHERE SUBSTR(TABLE_NAME, -4, 4) < '2000'
OR SUBSTR(TABLE_NAME, -4, 4) > '2010') SRC
ORDER BY SRC.TABLE_NAME ASC
这样的SQL,要如何通过语句写在SHELL脚本中,让它能实现导出来 展开
展开全部
写一个脚本,内容如下:
sqlplus -s 用户名/密码 <<EOF
set pagesize 0
set line 100
spool 文件名.txt
SELECT *
FROM (SELECT SUBSTR(TABLE_NAME, 1, LENGTH(TABLE_NAME) - 5) TABLE_NAME,
SUM(COUNTS) COUNTS
FROM GLMIS_TABLES_COUNTS
WHERE SUBSTR(TABLE_NAME, -4, 4) >= '2000'
AND SUBSTR(TABLE_NAME, -4, 4) <= '2010'
GROUP BY SUBSTR(TABLE_NAME, 1, LENGTH(TABLE_NAME) - 5)
UNION ALL
SELECT TABLE_NAME, COUNTS
FROM GLMIS_TABLES_COUNTS
WHERE SUBSTR(TABLE_NAME, -4, 4) < '2000'
OR SUBSTR(TABLE_NAME, -4, 4) > '2010') SRC
ORDER BY SRC.TABLE_NAME ASC;
spool off
exit;
EOF
sqlplus -s 用户名/密码 <<EOF
set pagesize 0
set line 100
spool 文件名.txt
SELECT *
FROM (SELECT SUBSTR(TABLE_NAME, 1, LENGTH(TABLE_NAME) - 5) TABLE_NAME,
SUM(COUNTS) COUNTS
FROM GLMIS_TABLES_COUNTS
WHERE SUBSTR(TABLE_NAME, -4, 4) >= '2000'
AND SUBSTR(TABLE_NAME, -4, 4) <= '2010'
GROUP BY SUBSTR(TABLE_NAME, 1, LENGTH(TABLE_NAME) - 5)
UNION ALL
SELECT TABLE_NAME, COUNTS
FROM GLMIS_TABLES_COUNTS
WHERE SUBSTR(TABLE_NAME, -4, 4) < '2000'
OR SUBSTR(TABLE_NAME, -4, 4) > '2010') SRC
ORDER BY SRC.TABLE_NAME ASC;
spool off
exit;
EOF
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询