2

我的查询:

CREATE VIEW cambiodatos AS 
SELECT 
    a.last_name||','||a.first_name AS "Nombre", 
    a.salary AS "Salario", 
    b.name AS "Nombre Departamento", 
    c.name AS "Nombre de Region"
FROM 
    s_emp a, s_dept b, s_region c
WHERE 
    a.dept_id = b.id AND b.region_id = c.id

UPDATE 
     cambiodatos 
SET 
     name = 'North America'
WHERE 
     last_name = 'Biri'||','||first_name = 'Ben'

错误:

ORA-00933: SQL command not properly ended
4

6 回答 6

2

你得到这个错误的确切原因是你有这个 WHERE 子句:

last_name = 'Biri'||','||first_name = 'Ben'

这不是合法的语法。

这将是:

last_name = 'Biri' AND first_name = 'Ben'

或者是这样的:

name = 'Biri'||','||'Ben'

但是你可以这样写:

name = 'Biri,Ben'

问题是在我看来您使用的是第二个 || 那里是一个 AND 子句,但这不适合您要添加的逗号。

也许您正在尝试执行此操作?

last_name || ',' || first_name = 'Biri,Ben'

在任何情况下,正如其他人所指出的那样,如果您解决了该语法问题,您只会收到有关缺少列名的其他错误消息。

于 2009-04-20T09:42:50.330 回答
1

First, separate you queries with a semicolon and fix your SET conditions:

CREATE VIEW cambiodatos AS 
SELECT 
    a.last_name||','||a.first_name AS "Nombre", 
    a.salary AS "Salario", 
    b.name AS "Nombre Departamento", 
    c.name AS "Nombre de Region"
FROM 
    s_emp a, s_dept b, s_region c
WHERE 
    a.dept_id = b.id AND b.region_id = c.id;

UPDATE 
     cambiodatos 
SET 
     name = 'North America'
WHERE 
     last_name = 'Biri'
     AND first_name = 'Ben'

That's the reason of your error ORA-00933

Second, your UPDATE statement will fail, as the view you created does not contain field name.

This query will compile:

UPDATE 
     cambiodatos 
SET 
     "Nombre de Region" = 'North America'
WHERE 
     "Nombre" = 'Biri, Ben'

, but most probably will fail as s_region is not key-preserved in this view.

To update, use this instead:

MERGE
INTO    s_region c
USING   (
        SELECT  b.region_id
        FROM    s_emp a, s_dept b
        WHERE   a.last_name || ',' || a.first_name = 'Biri, Ben'
                AND b.id = a.dept_id
        ) q
ON      c.id = q.region_id
WHEN MATCHED THEN
UPDATE
SET     c.name = 'North America'
于 2009-04-20T09:29:40.440 回答
0

看起来您想要在更新中使用 AND

UPDATE 
     cambiodatos 
SET 
     name = 'North America'
WHERE 
     last_name = 'Biri' AND first_name = 'Ben'
于 2009-04-18T20:04:17.937 回答
0

在过去 7 年左右的时间里,我根本没有使用过 Oracle,但您不需要 ; 在声明的末尾?

于 2009-04-18T20:05:29.743 回答
0

首先,我认为您的 UPDATE 命令格式不正确。其次,您使用的是基础表中的字段,而不是运行更新的视图。另外,我认为您不能更新基于联接的视图。请参阅对此问题的回复。如果你可以看起来像这样。

UPDATE 
     cambiodatos 
SET 
     [Nombre de Region] = 'North America'
WHERE 
     Nombre = 'Biro, Ben'
于 2009-04-18T20:09:23.167 回答
-1

CREATE VIEW cambiodatos AS SELECT a.last_name||','||a.first_name AS "Nombre", a.salary AS "Salario", b.name AS "Nombre Departamento", c.name AS "Nombre de Region" FROM s_emp a, s_dept b, s_region c WHERE a.dept_id = b.id AND b.region_id = c.id ; /* 缺少分号?*/

UPDATE cambiodatos SET name = 'North America' WHERE last_name = 'Biri'||','||first_name = 'Ben' /* 缺少 And last_name = <> AND first_name = <> */

于 2009-04-20T03:42:40.073 回答