当我想识别变量的数据类型时,我遇到了问题"价格"作为对象类型" rsd"。当我创建表时,它返回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));
你能帮帮我吗?
答案 0 :(得分:2)
我怀疑你是以脚本的形式执行的,你必须有 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