今天是个好日子!我对我的 oracle db 程序有疑问:(我为我的英语和不清楚的演讲道歉)我写了简单的程序(但甚至不编译它,所以我不知道工作是不是),但我不知道不喜欢,因为循环中的选择。有时我用 group by 和 result 写了一些 sql 选择。所以这是可能的,我如何(在 pl/sql 中)使用结果。Ps 对不起,如果它是愚蠢的,但我不知道,我必须在谷歌写什么。
CREATE OR REPLACE PROCEDURE getDescription
(
columnName IN VARCHAR2
)
AS
CURSOR descriptionSelector IS
SELECT utc.table_name tableName, utc.data_type columnType, utc.DATA_LENGTH columnLenth
FROM user_tab_columns utc
WHERE utc.column_name = columnName;
fetched descriptionSelector%ROWTYPE;
index INTEGER;
BEGIN
index := 1;
DBMS_OUTPUT.PUT_LINE(rpad('No.',4)||rpad('Column',25)||rpad('Table',25)||rpad('Attribute',50));
FOR currentSelect IN descriptionSelector
LOOP
DBMS_OUTPUT.PUT_LINE(rpad(index ,4) || ' ' ||rpad(columnName, 25)||' ' ||rpad(currentSelect.tableName,25)||' '||rpad('TYPE: '||currentSelect.columnType,20)' '||lpad('('||currentSelect.columnLenth||')',3));
FOR secondSelection IN (
SELECT ref_ucc.table_name tableName, ref_ucc.column_name referenceColumnName, ref_ucc.constrain t_name
FROM user_cons_columns ucc
JOIN user_constraints uc
ON ucc.constraint_name = uc.constraint_name
JOIN user_cons_columns ref_ucc
ON uc.r_constraint_name = ref_ucc.constraint_name
WHERE uc.constraint_type = 'R'
AND ucc.table_name = currentSelect.tableName
AND ucc.column_name = columnName)
LOOP
DBMS_OUTPUT.PUT_LINE('Constr: '||secondSelection.constraint_name||' References '||secondSelection.tableName||'('||secondSelection.referenceColumnName||')');
END LOOP;
index := index + 1;
END LOOP;
END;
/