萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> oracle教程 >> Oracle ORA-00903錯誤具體原因分析

Oracle ORA-00903錯誤具體原因分析

ORA-00903 invalid table name

ORA-00903:無效的表名

Cause A table or cluster name is invalid or does not exist. This message is also issued if an invalid cluster name or no cluster name is specified in an ALTER CLUSTER or DROP CLUSTER statement.

Action Check spelling. A valid table name or cluster name must begin with a letter and may contain only alphanumeric characters and the special characters $, _, and #. The name must be less than or equal to 30 characters and cannot be a reserved word.

原因:表名或簇名不存在或無效,當運行ALTER CLUSTER 或 DROP CLUSTER語句時,會出現此錯誤信息。

方案:檢查拼寫是否正確。一個有效的表名或簇名必須以字母開頭,只含有字母或數字,不能超過30個字符,可以包含一些特殊字符$, _, #。表名或簇名不能是關鍵字。

案例一: 使用 DBMS_SQL包執行DDL語句

The DBMS_SQL package can be used to execute DDL statements directly from PL/SQL.

這是一個創建一個表的過程的例子。該過程有兩個參數:表名和字段及其類型的列表。

CREATE OR REPLACE PROCEDURE ddlproc (tablename varchar2, cols varchar2) AS
cursor1 INTEGER;
BEGIN
cursor1 := dbms_sql.open_cursor;
dbms_sql.parse(cursor1, 'CREATE TABLE ' || tablename || '
( ' || cols || ' )', dbms_sql.v7);
dbms_sql.close_cursor(cursor1);
end;
/
SQL> execute ddlproc ('MYTABLE','COL1 NUMBER, COL2 VARCHAR2(10)');
PL/SQL procedure successfully completed.
SQL> desc mytable;
Name Null? Type
------------------------------- -------- ----
COL1 NUMBER
COL2 VARCHAR2(10)

注意:DDL語句是由Parese命令執行的。因此,不能對DDL語句使用bind變量,否則你就會受到一個錯誤信息。下面的在DDL語句中使用bind變量的例子是錯誤的。

**** Incorrect Example ****
CREATE OR REPLACE PROCEDURE ddlproc (tablename VARCHAR2,
colname VARCHAR2,
coltype VARCHAR2) AS
cursor1 INTEGER;
ignore INTEGER;
BEGIN
cursor1 := dbms_sql.open_cursor;
dbms_sql.parse(cursor1, 'CREATE TABLE :x1 (:y1 :z1)', dbms_sql.v7);
dbms_sql.bind_variable(cursor1, ':x1', tablename);
dbms_sql.bind_variable(cursor1, ':y1', colname);
dbms_sql.bind_variable(cursor1, ':z1', coltype);
ignore := dbms_sql.execute(cursor1);
dbms_sql.close_cursor(cursor1);
end;
/

  • 共2頁:
  • 上一頁
  • 1
  • 2
  • 下一頁
copyright © 萬盛學電腦網 all rights reserved