【问题标题】:oracle sql query for selecting Even number columnsoracle sql查询选择偶数列
【发布时间】:2019-10-19 21:52:23
【问题描述】:

在 oracle sql 中,当我试图获取下面的输出时,它会抛出错误。

select city,id from station where id % 2 = 0;

错误:

ORA-00911: invalid character
00911. 00000 -  "invalid character"
*Cause:    identifiers may not start with any ASCII character other than
           letters and numbers.  $#_ are also allowed after the first
           character.  Identifiers enclosed by doublequotes may contain
           any character other than a doublequote.  Alternative quotes
           (q'#...#') cannot use spaces, tabs, or carriage returns as
           delimiters.  For all other contexts, consult the SQL Language
           Reference Manual.

【问题讨论】:

    标签: sql database oracle select where-clause


    【解决方案1】:

    Oracle 不支持用于取模的 % 运算符。你需要使用function mod():

    select city,id from station where mod(id, 2) = 0;
    

    Demo on DB Fiddle

    【讨论】:

    • 太好了,成功了,非常感谢,我还有一个关于出生日期的问题,很快就会发布问题
    • 您好,您能帮我解决以下问题吗?我有一个表 STUDENT 具有以下结构:描述学生; Name Type SNO NUMBER(2) SNAME VARCHAR2(15) DOB DATE AGE NUMBER(2) TNO NUMBER(2) 现在在 DOB 列中插入数据时,出现错误 INSERT INTO STUDENT (SNO,SNAME,DOB,AGE,TNO) VALUES ('42','IRONMAN','01-01-1991','29','1');错误: 错误报告: SQL 错误: ORA-01843: not a valid month 01843. 00000 - "not a valid month" PLZ HELP
    • @Jack:cmets 并不是真的要问新问题……我建议问一个 new 问题。此外,如果此答案正确回答了您的原始问题,请点击绿色复选标志accept it...谢谢。
    • @Jack 看起来您需要为 DOB 提供 date,而不是 '01-01-1991'。见the SQL Language docs for date literal syntax
    猜你喜欢
    • 1970-01-01
    • 2015-10-26
    • 2013-07-17
    • 2020-09-15
    • 2012-12-30
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    • 2016-03-15
    相关资源
    最近更新 更多