这好像一个sql语句写不出来啊
解决方案 »
- 不知道表的结构,如何操作表,并按照一定的顺序显示表里的记录。
- oracle中使用dbms_lob包从文件中读出文本数据到数据库的clob字段出线乱码,怎么解决,代码如下:
- vb程序如何响应oracle中的数据库插入事件?
- Oracle高难度问题
- SQL*Loader装载Blob问题,高手都过来看呀
- 关于数据文件的几个问题
- 数据大小超出此类型的最大值?
- ★★★★★★OracleOraHome90Agent服务是做什么用的?
- OracleOraHome81ManagementServer 启动不来!!
- 怎样进行pb6.5和oracle for 95 的连接???
- 备份数据时出现ORA-03120错误?怎么处理
- 请问各位大侠一个关于TRIGGER的一个简单的问题?
(
select col1,col2 from tb where to_char(col1,'yyyymm')='200409'
union
select to_date('20040901','yyyymmdd')+rownum-1,0 from dba_tables where rownum<31
)
group by to_char(col1,'yyyymmdd')
(
select col1,col2 from tb where to_char(col1,'yyyymm')='&YYYYMM'
union
select to_date('20040901','yyyymmdd')+rownum-1 col1,0 col2 from dba_tables where rownum<31
)
group by to_char(col1,'yyyymmdd')
select a.m,b.col2 from
(select to_date('2004-09','yyyy-mm')+rownum-1 m
from dba_tables
where rownum-1<=(select last_day(to_date('2004-09','yyyy-mm'))-to_date('2004-09','yyyy-mm') from dual)) a,表A b
where a.m=b.col1(+);
(select to_date('2004-09','yyyy-mm')+rownum-1 m
from dba_tables
where rownum-1<=(select last_day(to_date('2004-09','yyyy-mm'))-to_date('2004-09','yyyy-mm') from dual)) a,表A b
where trunc(a.m)=b.col1(+);
---------- ----------
2004-11-01 5
2004-11-02 15
2004-11-20 12
2004-11-22 18
2004-11-30 30select b.col1,decode(a.col2,null,0,a.col2) col2
from
(select col1,col2 from aa where substrb(col1,1,7)='2004-11') a,
(
select c.mydate||d.zero col1,0 col2 from
(select 'gene' gene,substrb(col1,1,7) mydate from aa where substrb(col1,1,7)='2004-11' and rownum=1) c,
(select 'gene' gene,'-'||trim(to_char(rownum,'00')) zero from dba_tables where rownum<=to_char(last_day(to_date('2004-11','yyyy-mm')),'dd')) d
where c.gene=d.gene
) b
where b.col1=a.col1(+)
/COL1 COL2
----------- ----------
2004-11-01 5
2004-11-02 15
2004-11-03 0
2004-11-04 0
..............略
2004-11-27 0
2004-11-28 0
2004-11-29 0
2004-11-30 30已选择30行。现在将条件改成'2004-12'
select b.col1,decode(a.col2,null,0,a.col2) col2
from
(select col1,col2 from aa where substrb(col1,1,7)='2004-12') a,
(
select c.mydate||d.zero col1,0 col2 from
(select 'gene' gene,substrb(col1,1,7) mydate from aa where substrb(col1,1,7)='2004-12' and rownum=1) c,
(select 'gene' gene,'-'||trim(to_char(rownum,'00')) zero from dba_tables where rownum<=to_char(last_day(to_date('2004-12','yyyy-mm')),'dd')) d
where c.gene=d.gene
) b
where b.col1=a.col1(+)
/未选定行再将表里的日期改掉
SQL> update aa set col1='2004-12-'||substrb(col1,9,2);已更新5行。SQL> commit;提交完成。SQL> select * from aa;COL1 COL2
---------- ----------
2004-12-01 5
2004-12-02 15
2004-12-20 12
2004-12-22 18
2004-12-30 30再执行语句
select b.col1,decode(a.col2,null,0,a.col2) col2
from
(select col1,col2 from aa where substrb(col1,1,7)='2004-12') a,
(
select c.mydate||d.zero col1,0 col2 from
(select 'gene' gene,substrb(col1,1,7) mydate from aa where substrb(col1,1,7)='2004-12' and rownum=1) c,
(select 'gene' gene,'-'||trim(to_char(rownum,'00')) zero from dba_tables where rownum<=to_char(last_day(to_date('2004-12','yyyy-mm')),'dd')) d
where c.gene=d.gene
) b
where b.col1=a.col1(+)
/COL1 COL2
----------- ----------
2004-12-01 5
2004-12-02 15
2004-12-03 0
2004-12-04 0
....................略
2004-12-28 0
2004-12-29 0
2004-12-30 30
2004-12-31 0已选择31行。=======================
这时候select到的是31行,因为12月是31天的。
语句会根据给定的月份自动判断是显示30行,28行,29行还是31行我已经把条件->"月份"都写在了where子句里,不过要写3个地方
CodeMagic(ErrorDetector) 你们的语句,如果表里没有"2004-09“,也会select出来30条记录
不知道楼主是不是,在表里没有记录的情况下,也要显示该月的记录,都是0?to GerryYang(轻尘)
你的语句不管你输入什么值,都显示2004年09月的记录我觉得条件不应该写在字段里
比如select to_date('2004-09','yyyy-mm') from ......
我已经把条件都写在了where字句里
并且如果表里没有2004年9月的记录,我是不会select出来记录的,当然这也许我理解错误
也许应该如ORARichard(没钱的日子好难过啊) 和 CodeMagic(ErrorDetector那样
即使表里没有记录,也要显示30个或31个或28,或29条值为0的记录?
(select to_date('2004-09','yyyy-mm')+rownum-1 m
from dba_tables
where rownum-1<=(select last_day(to_date('2004-09','yyyy-mm'))-to_date('2004-09','yyyy-mm') from dual)) a,表A b
where trunc(a.m)=b.col1(+);这句话会将col2的null值改成0;
我的改一下也可以