[英]Select does not work - Oracle
我从Oracle开始。 我使用SQL Developer,并且尝试启动类似这样的SQL请求:
select date_depart,* from train where no_train='111';
显示一条错误消息:“ missing expression”请问我如何解决这个问题?
如果要在*
通配符旁边使用其他任何列或表达式,则必须使用全名指定*
引用哪个表:
select no_train, train.* from train where no_train='111';
或使用别名:
select t.no_train, t.* from train t where no_train='111';
但是,当通配符*
获取所有列时,您将看到train_no
两次。 最好列出所需的列:
select t.train_no, t.train_type, t.depot, ... -- whatever your real columns are
from train t
where t.train_no = 111
如果火车号实际上是数字数据类型,则不应将文字111
括在引号中。 始终使用正确的数据类型,不要强制或依赖隐式数据转换。
假设您想要一个包含列no_train
和表中所有列的结果,包括将显示两次的no_train
,那么您可能需要添加一个别名:
select no_train, t.*
from train t
where no_train='111';
例如,使用这样的表
create table train(no_train, descr) as ( select 111, 'descr' from dual);
这将给出:
SQL> select no_train, t.*
2 from train t
3 where no_train='111';
NO_TRAIN NO_TRAIN DESCR
---------- ---------- -----
111 111 descr
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.