大虾帮忙啊,一个存储过程!

zhangxuenian 2005-09-19 03:55:39
表名格式如HISDATA20050101,HISDATA20050102,一天一张表
有可能某天的表不存在,
要求写sql 语句 一次查询一年的数据
SQL Server 和Oracle
...全文
88 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
waterfirer 2005-09-19
  • 打赏
  • 举报
回复
SQL Server
select name from dbo.sysobjects where xtype='U' and substring(name,1,11)='HISDATA' + year(getdate());

Oracle
select table_name from user_tables where substr(table_name,1,11)='HISDATA' || to_char(sysdate,'yyyy');
取出来的是需要的表名,然后拼串,再查询就行了
zjw7789 2005-09-19
  • 打赏
  • 举报
回复
select * from (select table_name from all_tables where substr(table_name,1,11)='HISDATA' || to_char(sysdate,'yyyy'));
waterfirer 2005-09-19
  • 打赏
  • 举报
回复
select table_name from user_tables where substr(table_name,1,11)='HISDATA' || to_char(sysdate,'yyyy');
做游标,就是需要的表。
然后拼串就行了

17,082

社区成员

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

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