******这条SQL为什么不能执行,解决立即给分*****
表结构如下:
create table T1
(
SID VARCHAR2(10),
SNAME VARCHAR2(20),
VAL1 VARCHAR2(20),
VAL2 NUMBER,
VAL3 DATE
)
create table T2
(
SID VARCHAR2(10),
VAL1 DATE
)
表T1内容如下:
1 Insert into t1 values ('a','aa','aa1',1,to_date('2003-03-03','yyyy-mm-dd'))
2 Insert into t1 values ('b','bb','bb1',1,to_date('2003-04-03','yyyy-mm-dd'))
3 Insert into t1 values ('c','cc','cc1',1,to_date('2003-05-03','yyyy-mm-dd'))
4 Insert into t1 values ('d','dd','dd1',1,to_date('2003-06-03','yyyy-mm-dd'))
表T2内容如下:
1 Insert into t2 values ('a',to_date('2003-03-01','yyyy-mm-dd'))
2 Insert into t2 values ('b',to_date('2003-04-01','yyyy-mm-dd'))
3 Insert into t2 values ('c',to_date('2003-05-01','yyyy-mm-dd'))
Q1.Oracle9不支持以下语句?
select sid as tID,sname as tNAME from t1
where tid='b'
如果我要表示选择sid='b'的记录,难道必须用where sid='b'而不能用where tid='b'吗?
如果语句改为
select sid || sname as tCbo from t1
想从中找出sid || sname='bbb'的记录难道也只能用where sid || sname='bbb',而不能用where tCbo='bbb'吗?
如果是更复杂的复合字段呢?
Q2.经典错误ora-03113
执行以下语句
select * from
(
select sid || sname as tCbo,
(case when exists(Select sid From t2
Where sid=t1.sid And to_char(val1,'yyyymm')='200303')
then '是' else '否' end) as f
from t1
)
where f='d'
先报ora-03113 通信通道的文件结束,再报ora-03114 未连接到oracle,将where f='d'改为where tcbo='d',错误消失。
以下是我的试验结果。
1.
select sid as tID,sname as tNAME from t1
where tid='b'
Oracle9:"tid",无效的标志符。
Asa9:正常执行。
Sql Server2000:列名 'tid' 无效。
2.
select sid || sname as tCbo,
(case when exists(Select sid From t2
Where sid=t1.sid And to_char(val1,'yyyymm')='200303')
then '是' else '否' end) as f
from t1
Oracle9:正常执行。
select sid + sname as tCbo,
(case when exists(Select sid From t2
Where sid=t1.sid And year(val1)=2003 and month(val1)=03)
then '是' else '否' end) as f
from t1
Asa9:正常执行。
Sql Server2000:正常执行。
3.
select * from
(
select sid || sname as tCbo,
(case when exists(Select sid From t2
Where sid=t1.sid And to_char(val1,'yyyymm')='200303')
then '是' else '否' end) as f
from t1
)
Oracle9:正常执行。
select * from
(
select sid + sname as tCbo,
(case when exists(Select sid From t2
Where sid=t1.sid And year(val1)=2003 and month(val1)=03)
then '是' else '否' end) as f
from t1
) tt
Asa9:正常执行。
Sql Server2000:正常执行。
4.
select * from
(
select sid || sname as tCbo,
(case when exists(Select sid From t2
Where sid=t1.sid And to_char(val1,'yyyymm')='200303')
then '是' else '否' end) as f
from t1
)
where f='d'
Oracle9:先报ora-03113 通信通道的文件结束,再报ora-03114 未连接到oracle,将where f='d'改为where tcbo='d',错误消失。
select * from
(
select sid + sname as tCbo,
(case when exists(Select sid From t2
Where sid=t1.sid And year(val1)=2003 and month(val1)=03)
then '是' else '否' end) as f
from t1
) tt
where f='d'
Asa9:正常执行。
Sql Server2000:正常执行。