嵌套表 - ORA-00902: 无效数据类型
Nested tables - ORA-00902: invalid datatype
当我想将变量 "price" 的数据类型识别为对象类型 "rsd" 时遇到问题。当我创建 table 时,它会返回 SQL 异常:ORA-00902:无效数据类型
CREATE OR REPLACE TYPE "RSD" AS OBJECT (
currency number(9,2),
MEMBER FUNCTION get_currency RETURN number)
INSTANTIABLE NOT FINAL;
CREATE OR REPLACE TYPE BODY "RSD" AS
MEMBER FUNCTION get_currency RETURN number IS
BEGIN
RETURN SELF.currency;
END;
END;
CREATE TABLE bill_item(
bill_ID number,
rb number,
price rsd,
item_id number,
CONSTRAINT scpk PRIMARY KEY (bill_id));
你能帮帮我吗?
我怀疑您是将它作为脚本执行的,并且您一定遇到了 TYPE BODY 的编译错误。您尚未关闭其范围。
不要将所有步骤作为脚本一起执行。一次执行一个。循序渐进,一定会成功的。
或者,在每个块的末尾放置一个正斜杠,然后作为脚本执行。
SQL> CREATE OR REPLACE TYPE "RSD" AS OBJECT (
2 currency number(9,2),
3 MEMBER FUNCTION get_currency RETURN number)
4 INSTANTIABLE NOT FINAL
5 /
Type created.
SQL>
SQL> CREATE OR REPLACE TYPE BODY "RSD" AS
2 MEMBER FUNCTION get_currency RETURN number IS
3 BEGIN
4 RETURN SELF.currency;
5 END;
6 END;
7 /
Type body created.
SQL>
SQL> CREATE TABLE bill_item(
2 bill_ID number,
3 rb number,
4 price rsd,
5 item_id NUMBER,
6 CONSTRAINT scpk PRIMARY KEY (bill_id))
7 /
Table created.
SQL> desc bill_item;
Name Null? Type
----------------------------------------- -------- ------
BILL_ID NOT NULL NUMBER
RB NUMBER
PRICE RSD
ITEM_ID NUMBER
SQL>
SQL> select * from bill_item;
no rows selected
当我想将变量 "price" 的数据类型识别为对象类型 "rsd" 时遇到问题。当我创建 table 时,它会返回 SQL 异常:ORA-00902:无效数据类型
CREATE OR REPLACE TYPE "RSD" AS OBJECT (
currency number(9,2),
MEMBER FUNCTION get_currency RETURN number)
INSTANTIABLE NOT FINAL;
CREATE OR REPLACE TYPE BODY "RSD" AS
MEMBER FUNCTION get_currency RETURN number IS
BEGIN
RETURN SELF.currency;
END;
END;
CREATE TABLE bill_item(
bill_ID number,
rb number,
price rsd,
item_id number,
CONSTRAINT scpk PRIMARY KEY (bill_id));
你能帮帮我吗?
我怀疑您是将它作为脚本执行的,并且您一定遇到了 TYPE BODY 的编译错误。您尚未关闭其范围。
不要将所有步骤作为脚本一起执行。一次执行一个。循序渐进,一定会成功的。
或者,在每个块的末尾放置一个正斜杠,然后作为脚本执行。
SQL> CREATE OR REPLACE TYPE "RSD" AS OBJECT (
2 currency number(9,2),
3 MEMBER FUNCTION get_currency RETURN number)
4 INSTANTIABLE NOT FINAL
5 /
Type created.
SQL>
SQL> CREATE OR REPLACE TYPE BODY "RSD" AS
2 MEMBER FUNCTION get_currency RETURN number IS
3 BEGIN
4 RETURN SELF.currency;
5 END;
6 END;
7 /
Type body created.
SQL>
SQL> CREATE TABLE bill_item(
2 bill_ID number,
3 rb number,
4 price rsd,
5 item_id NUMBER,
6 CONSTRAINT scpk PRIMARY KEY (bill_id))
7 /
Table created.
SQL> desc bill_item;
Name Null? Type
----------------------------------------- -------- ------
BILL_ID NOT NULL NUMBER
RB NUMBER
PRICE RSD
ITEM_ID NUMBER
SQL>
SQL> select * from bill_item;
no rows selected