我需要一个具有列account name,account id,date created,balance & address
的表。在这种情况下,帐户名有2个列,名为first name & last name & address
有5列line1,line2,city,state,pincode
。使用嵌套表是实现此目的的最佳方法吗?
我尝试使用python中的cx_Oracle
模块为oracle-11g创建嵌套表,但它给了我错误,但我无法解决。代码如下:
`self.CUR.execute(""" CREATE TYPE ADDRESS_SUB_COLUMNS AS OBJECT(
line1 VARCHAR2(30),
line2 VARCHAR2(30),
city VARCHAR2(20),
state VARCHAR2CHAR(10),
zip CHAR(6)
);
/""")
self.CUR.execute(""" CREATE TYPE ADDRESS_TABLE IS TABLE OF ADDRESS_SUB_COLUMNS;
/""")
self.CUR.execute("""CREATE TABLE CUSTOMERS (
custid VARCHAR2(14),
address ADDRESS_TABLE )NESTED TABLE address STORE AS customer_addresses""")`
我遇到的错误是:
`Traceback (most recent call last):
File "python/home.py", line 386, in <module>
menuObject = mainMenu()
File "python/home.py", line 133, in __init__
super().__init__(self.cur) #Call to constructor in parent2 (TABLE_USERS) : passing cur from parent1
File "python/home.py", line 72, in __init__
self.createTable()
File "python/home.py", line 93, in createTable
/""")
cx_Oracle.DatabaseError: ORA-06545: PL/SQL: compilation error - compilation aborted
ORA-06550: line 8, column 30:
PLS-00103: Encountered the symbol "/" The symbol "/" was ignored.
ORA-06550: line 0, column 0:
PLS-00565: ADDRESS_SUB_COLUMNS must be completed as a potential REF target (object type
)`
有人可以帮我吗?
答案 0 :(得分:0)
“ /”字符是SQL * Plus命令终止符。您不能在cx_Oracle中使用它。试试
self.CUR.execute(""" CREATE TYPE ADDRESS_SUB_COLUMNS AS OBJECT(
line1 VARCHAR2(30),
line2 VARCHAR2(30),
city VARCHAR2(20),
state VARCHAR2CHAR(10),
zip CHAR(6)
);""")
我会让“最佳”问题成为练习。