问题
I have a table like this:
CREATE TABLE T_C_EVO_GAME_CONFIG_CHANGE_LOG(
F_TABLE_MODIFIED VARCHAR2(40),
F_OPERATION_PERFORMED VARCHAR2(30),
F_ROWS_ALTERED INTEGER,
F_LAST_UPDATED_BY VARCHAR2(200),
F_LAST_UPDATED_DATE TIMESTAMP);
I am trying to build a type with the same structure:
create or replace type TYPE_EVOL_CONFIG_CHANGE_LOG as object
(
F_TABLE_MODIFIED T_C_EVO_GAME_CONFIG_CHANGE_LOG.TABLE_MODIFIED%TYPE ,
F_OPERATION_PERFORMED T_C_EVO_GAME_CONFIG_CHANGE_LOG.OPERATION_PERFORMED%TYPE,
F_ROWS_ALTERED T_C_EVO_GAME_CONFIG_CHANGE_LOG.ROWS_ALTERED%TYPE ,
F_LAST_UPDATED_BY T_C_EVO_GAME_CONFIG_CHANGE_LOG.LAST_UPDATED_BY%TYPE ,
F_LAST_UPDATED_DATE T_C_EVO_GAME_CONFIG_CHANGE_LOG.LAST_UPDATED_DATE%TYPE
);
Getting the below error message in creating the Type :
Error(3,25): PLS-00201: identifier 'T_C_EVO_GAME_CONFIG_CHANGE_LOG.TABLE_MODIFIED' must be declared.
Previously I tried to create the Type without using %TYPE
and just simply copying the parameter definition and it worked.
But I don't want to make any changes in Type when I make any changes in Table.
回答1:
The %TYPE
syntax is for use in PL/SQL declarations. Unfortunately we cannot use it when creating SQL objects. Same goes for %rowtype
.
It would be highly neat if we could, because one common use of create or replace type
would be to build table APIs as you want to do. However, it would be too complicated to manage referencing constructs in the data dictionary; bear in mind that Types can be used to define other objects including Table columns.
So alas, you need to declare the Type with explicit datatypes for its attributes:
create or replace type TYPE_EVOL_CONFIG_CHANGE_LOG as object
(
F_TABLE_MODIFIED VARCHAR2(40) ,
F_OPERATION_PERFORMED VARCHAR2(30),
F_ROWS_ALTERED INTEGER ,
F_LAST_UPDATED_BY VARCHAR2(20) ,
F_LAST_UPDATED_DATE DATE
);
Obviously you also need to sync it manually whenever the structure of any T_C_EVO_GAME_CONFIG_CHANGE_LOG column changes. But you would have to do this anyway if you added or dropped a column.
Alternatively you can define the type as a PL/SQL record in a package. That would allow you to use the referencing syntax.
create or replace package game_config as
TYPE_EVOL_CONFIG_CHANGE_LOG is record
(
F_TABLE_MODIFIED T_C_EVO_GAME_CONFIG_CHANGE_LOG.F_TABLE_MODIFIED%TYPE ,
F_OPERATION_PERFORMED T_C_EVO_GAME_CONFIG_CHANGE_LOG.F_OPERATION_PERFORMED%TYPE,
F_ROWS_ALTERED T_C_EVO_GAME_CONFIG_CHANGE_LOG.F_ROWS_ALTERED%TYPE ,
F_LAST_UPDATED_BY T_C_EVO_GAME_CONFIG_CHANGE_LOG.F_LAST_UPDATED_BY%TYPE ,
F_LAST_UPDATED_DATE T_C_EVO_GAME_CONFIG_CHANGE_LOG.F_LAST_UPDATED_DATE%TYPE
);
-- or even
TYPE TAB_EVOL_CONFIG_CHANGE_LOG is table of T_C_EVO_GAME_CONFIG_CHANGE_LOG%rowtype;
end;
It depends how you want to use the Type in your broader application.
来源:https://stackoverflow.com/questions/44276075/getting-pls-00201-error-while-creating-a-type-in-oracle