SQL 视图协助
我在使用这个 sql 视图时遇到了一些问题。
CREATE OR REPLACE VIEW view_themed_booking AS
SELECT tb.*,
CASE
WHEN (tb.themed_party_size % 2) = 0 THEN
(tb.themed_party_size-2)/2
ELSE ((tb.themed_party_size-2)/2) + 0.5
END themed_tables
FROM themed_booking tb;
有人可以帮我吗?我试图在视图末尾添加一列,表示 (S-2)/2
的自然数结果,其中 S
是 themed_party_size< /代码>。
当我说自然数结果时,我的意思是对以 .5 结尾的答案进行四舍五入,因此如果 S=7
答案将为 3
而不是 2.5.
当我尝试运行上面的代码时出现的错误是
Error starting at line 1 in command:
CREATE OR REPLACE VIEW view_themed_booking AS
SELECT tb.*,
CASE WHEN (tb.themed_party_size % 2) = 0
THEN (tb.themed_party_size-2)/2
ELSE ((tb.themed_party_size-2)/2) + 0.5
END themed_tables
FROM themed_booking tb
Error at Command Line:3 Column:34
Error report:
SQL Error: 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.
*Action:
如果它有影响,我正在使用连接到 Oracle 服务器的 sqldeveloper,这样我就可以使用 PL/SQL。
I'm having a little trouble with this sql view.
CREATE OR REPLACE VIEW view_themed_booking AS
SELECT tb.*,
CASE
WHEN (tb.themed_party_size % 2) = 0 THEN
(tb.themed_party_size-2)/2
ELSE ((tb.themed_party_size-2)/2) + 0.5
END themed_tables
FROM themed_booking tb;
Can anyone help me here? I'm trying to add a column to the end of the view that the natural number result of (S-2)/2
where S
is the themed_party_size
.
When i say natural number result i mean like round up the answers that end in .5 so if S=7
the answer would be 3
and not 2.5
.
The error I get when I try and run the above code is
Error starting at line 1 in command:
CREATE OR REPLACE VIEW view_themed_booking AS
SELECT tb.*,
CASE WHEN (tb.themed_party_size % 2) = 0
THEN (tb.themed_party_size-2)/2
ELSE ((tb.themed_party_size-2)/2) + 0.5
END themed_tables
FROM themed_booking tb
Error at Command Line:3 Column:34
Error report:
SQL Error: 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.
*Action:
If it makes a difference I am using sqldeveloper connected to an oracle server so I can use PL/SQL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
错误消息告诉您问题是什么。
查看行:3 列:34
这是一个无效字符
我怀疑您正在尝试使用模运算符。
由于您使用的是 oracle PL/SQL,因此应该使用
mod
这是参考 Oracle/PLSQL:Mod 函数
The error message is telling you what the problem is.
Look at Line:3 Column:34
It is an invalid character
My suspicion is that you are trying to use the modulo operator.
Since you are using oracle PL/SQL, you should use
mod
Here is a reference Oracle/PLSQL: Mod Function
我认为您可以使用
CEIL()
或ROUND()
函数进行简化:不确定为什么会出现该错误。也许这是 Oracle 中不可用的
%
运算符。此链接表明:PL/SQL 基础知识。不过似乎有一个 MOD() 函数。I think you can simplify with the
CEIL()
orROUND()
function:Not sure why you get that error. Perhaps it's the
%
operator that is not available in Oracle. This links suggests so: Fundamentals of PL/SQL. There seems to be aMOD()
function though.