我有以下代码:
SET LINESIZE 2000;
SET PAGESIZE 20;
COL column_name FOR A40
col CONSTRAINT_NAME for a30;
COL CONSTRAINT_OWNER FOR A20;
col SEARCH_CONDITION for a35;
SELECT A.OWNER||'.'||A.TABLE_NAME||'.'||B.COLUMN_NAME "COLUMN_NAME",B.POSITION,A.OWNER "CONSTRAINT_OWNER",A.CONSTRAINT_NAME,CASE CONSTRAINT_TYPE
WHEN 'P' THEN 'PRIMARY KEY'
WHEN 'C' THEN 'CHECK CONSTRAINT'
WHEN 'U' THEN 'UNIQUE KEY'
WHEN 'R' THEN 'REFERENTIAL INTEGRITY'
WHEN 'V' THEN 'CHECK OPTION - VIEW'
WHEN 'O' THEN 'READ ONLY - VIEW'
END AS CONSTRAINT_TYPE,SEARCH_CONDITION
FROM DBA_CONSTRAINTS A left JOIN DBA_CONS_COLUMNS B
ON A.CONSTRAINT_NAME=B.CONSTRAINT_NAME
WHERE A.OWNER = 'SOE'
AND A.TABLE_NAME = 'INVENTORIES'
--AND A.CONSTRAINT_NAME = 'CCAR_01_UK'
ORDER BY POSITION
/
但是输出带来了重复的行:
COLUMN_NAME POSITION CONSTRAINT_OWNER CONSTRAINT_NAME CONSTRAINT_TYPE SEARCH_CONDITION
---------------------------------------- ---------- -------------------- ------------------------------ --------------------- -----------------------------------
SOE.INVENTORIES.PRODUCT_ID 1 SOE INVENTORY_PK PRIMARY KEY
SOE.INVENTORIES.WAREHOUSE_ID 1 SOE INVENTORIES_WAREHOUSES_FK REFERENTIAL INTEGRITY
SOE.INVENTORIES.PRODUCT_ID 1 SOE INVENTORIES_PRODUCT_ID_FK REFERENTIAL INTEGRITY
SOE.INVENTORIES.PRODUCT_ID 1 SOE INVENTORY_PK PRIMARY KEY
SOE.INVENTORIES.WAREHOUSE_ID 1 SOE INVENTORIES_WAREHOUSES_FK REFERENTIAL INTEGRITY
SOE.INVENTORIES.PRODUCT_ID 1 SOE INVENTORIES_PRODUCT_ID_FK REFERENTIAL INTEGRITY
SOE.INVENTORIES.WAREHOUSE_ID 2 SOE INVENTORY_PK PRIMARY KEY
SOE.INVENTORIES.WAREHOUSE_ID 2 SOE INVENTORY_PK PRIMARY KEY
SOE.INVENTORIES.WAREHOUSE_ID SOE INVENTORY_WAREHOUSE_ID_NN CHECK CONSTRAINT "WAREHOUSE_ID" IS NOT NULL
SOE.INVENTORIES.QUANTITY_ON_HAND SOE INVENTORY_QOH_NN CHECK CONSTRAINT "QUANTITY_ON_HAND" IS NOT NULL
SOE.INVENTORIES.QUANTITY_ON_HAND SOE INVENTORY_QOH_NN CHECK CONSTRAINT "QUANTITY_ON_HAND" IS NOT NULL
SOE.INVENTORIES.WAREHOUSE_ID SOE INVENTORY_WAREHOUSE_ID_NN CHECK CONSTRAINT "WAREHOUSE_ID" IS NOT NULL
有人可以帮助我吗?这些表是文档中的ALL_CONS_COLUMNS和ALL_CONSTRAINTS
答案 0 :(得分:0)
我假设这些是Oracle示例数据库/表?如果是这样,那么这些不是标准约束,那么我猜您/您已经在添加/修改它们了吗?如果是这样的话,看来好像做错了某件事,因此我将其删除并重新应用-必要时