Задание
Таблица: н_характеристики_видов_работ  

 No. Имя столбца   Атрибуты
 --- -----------   ------------------------------------------------------
   1 свр_ид        Type   : NUMBER(9)
                   Constr : "хвр_свр_fk" References н_свойства_вр(ид)
  
   2 вр_ид         Type   : NUMBER(9)
                   Constr : "хвр_вр_fk"  References н_виды_работ(ид)
   
   2 кто_создал    Type   : Date
   3 когда_создал  Type   : Date
   4 кто_изменил   Type   : Date
   5 когда_изменил Type   : Date


SET SERVEROUTPUT ON FORMAT WRAPPED;

DECLARE
    tableName VARCHAR2(40) := 'Н_ХАРАКТЕРИСТИКИ_ВИДОВ_РАБОТ';	
    colNo VARCHAR2(128) := 'No.';
    colName VARCHAR2(128) := 'Имя столбца';
    colAttr VARCHAR2(128) := 'Атрибуты';
    noLen NUMBER := 3;
    colLen NUMBER := 15;
    attrLen NUMBER := 60;
    attrNameLen NUMBER := 15;
    dataType VARCHAR2(128);
    constr VARCHAR2(128);
    refName VARCHAR2(128);

    CURSOR RES IS
        SELECT ALL_TAB_COLUMNS.COLUMN_ID AS COLUMN_ID, ALL_TAB_COLUMNS.COLUMN_NAME AS COLUMN_NAME, ALL_TAB_COLUMNS.DATA_TYPE AS DATA_TYPE, 
        ALL_TAB_COLUMNS.DATA_PRECISION AS DATA_PRECISION, ALL_TAB_COLUMNS.CHAR_LENGTH AS CHAR_LENGTH 
        FROM ALL_TAB_COLUMNS 
        WHERE ALL_TAB_COLUMNS.TABLE_NAME = tableName 
        ORDER BY ALL_TAB_COLUMNS.COLUMN_ID;

    CURSOR RES_CONSTR IS
        SELECT ALL_CONS_COLUMNS.COLUMN_NAME, ALL_CONSTRAINTS.CONSTRAINT_NAME, ALL_CONSTRAINTS.CONSTRAINT_TYPE, ALL_CONSTRAINTS.R_CONSTRAINT_NAME 
        FROM ALL_CONS_COLUMNS, ALL_CONSTRAINTS
        WHERE ALL_CONS_COLUMNS.TABLE_NAME = tableName AND ALL_CONSTRAINTS.TABLE_NAME = tableName 
        AND ALL_CONS_COLUMNS.CONSTRAINT_NAME = ALL_CONSTRAINTS.CONSTRAINT_NAME;
		
BEGIN
    DBMS_OUTPUT.PUT_LINE('Таблица: ' || tableName);
    DBMS_OUTPUT.PUT_LINE('');
    DBMS_OUTPUT.PUT_LINE(RPAD(colNo, noLen) || ' ' || RPAD(colName, colLen) || ' ' || RPAD(colAttr, attrLen));
    DBMS_OUTPUT.PUT_LINE(RPAD('-', noLen, '-') || ' ' || RPAD('-', colLen, '-') || ' ' || RPAD('-', attrLen, '-'));

    FOR ROW IN RES LOOP
        colNo := TO_CHAR(ROW.COLUMN_ID);
        colName := ROW.COLUMN_NAME;
        dataType := RPAD('Type: ', attrNameLen) || ROW.DATA_TYPE;

        IF ROW.DATA_PRECISION IS NOT NULL THEN
            dataType := dataType || '(' || ROW.DATA_PRECISION || ')';
        END IF;
		
        IF ROW.CHAR_LENGTH > 0 THEN
            dataType := dataType || '(' || ROW.CHAR_LENGTH || ')';
        END IF;

        DBMS_OUTPUT.PUT_LINE(RPAD(colNo, noLen, ' ') || ' ' || RPAD(colName, colLen, ' ') || ' ' || RPAD(dataType, attrLen, ' '));

        FOR ROW_CONSTR IN RES_CONSTR LOOP
            IF ROW_CONSTR.COLUMN_NAME = ROW.COLUMN_NAME AND ROW_CONSTR.CONSTRAINT_TYPE = 'R' THEN
				constr := 'Constr: ';
				
				FOR refTable IN (SELECT TABLE_NAME FROM ALL_CONSTRAINTS WHERE CONSTRAINT_NAME = ROW_CONSTR.R_CONSTRAINT_NAME) LOOP
					refName := refTable.TABLE_NAME;
					
					FOR refColumns IN (SELECT COLUMN_NAME FROM ALL_CONS_COLUMNS 
                        WHERE TABLE_NAME = refTable.TABLE_NAME AND CONSTRAINT_NAME = ROW_CONSTR.R_CONSTRAINT_NAME) LOOP
						refName := refName || '(' || refColumns.COLUMN_NAME || ')';
						EXIT;
					END LOOP;
					EXIT;
				END LOOP;
						
				DBMS_OUTPUT.PUT_LINE(RPAD(' ', noLen + colLen + 2) || SUBSTR(RPAD(constr, attrNameLen) || '"' || ROW_CONSTR.CONSTRAINT_NAME 
                    || '" ' || 'References ' || refName || CHR(10), 0, attrLen));
                EXIT;
            END IF;
        END LOOP;
    END LOOP;
END;
