查询动态表名

brinkmanyh 2010-11-23 11:54:54
现在有几张表
table201009
table201010
table201011

希望做一个视图,根据当前月份读取表
...全文
152 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
brinkmanyh 2010-11-24
  • 打赏
  • 举报
回复
4,5楼的大大理解错了我的意思

6楼的兄弟,你这样是可以得出表名,但是变成了另外一个问题:如何用结果集作为表名
gelyon 2010-11-23
  • 打赏
  • 举报
回复
--动态sql拼接你的表名:
sql_str:='select * from table'||to_char(sysdate,'yyyymm');
execute immediate sql_str;
cooltyx 2010-11-23
  • 打赏
  • 举报
回复
给你最简单的sql:

select a.table_name from user_tables a where upper(a.table_name) = 'TABLE' || to_char(sysdate,'yyyymm');


注:user_tables是任何版本的oracle都自带的一张系统视图。
minitoy 2010-11-23
  • 打赏
  • 举报
回复
select 字段列表 from (
select t.*,'201009' table_month from table201009 t
union all
select t1.*,'201010' table_month from table201010 t1
union all
select t2.*,'201011' table_month from table201011 t2)
where table_month=to_char(sysdate,'yyyymm')
minitoy 2010-11-23
  • 打赏
  • 举报
回复
select 字段列表 from (
select t.*,'201009' table_month from table201009 t
union all
select t1.*,'201010' table_month from table201009 t1
union all
select t2.*,'201011' table_month from table201009 t2)
where table_month=to_char(sysdate,'yyyymm')
brinkmanyh 2010-11-23
  • 打赏
  • 举报
回复
人工置顶。。。
brinkmanyh 2010-11-23
  • 打赏
  • 举报
回复
执行报错?
能不能详细点把VIEW的一并写出来?

17,140

社区成员

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

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