因此,我返回了在原理图中搜索键/标识符的过程。
这是准备好的过程:
CREATE OR REPLACE PROCEDURE SIEROT(i_table_name VARCHAR2) IS
strSelect VARCHAR2(32767);
c SYS_REFCURSOR;
vTYPEPKSTRING PRODUCTS.TYPEPKSTRING%TYPE;
TYPE c_list IS TABLE of PRODUCTS.TYPEPKSTRING%type INDEX BY binary_integer;
TYPEPK_list c_list;
counter integer := 0;
BEGIN
strSelect := 'SELECT DISTINCT i.TYPEPKSTRING ' ||
' FROM ' || i_table_name || ' i ' ||
' LEFT OUTER JOIN COMPOSEDTYPES c ' ||
' ON i.TYPEPKSTRING = c.PK ' ||
' WHERE c.PK IS NULL';
OPEN c FOR strSelect;
FETCH c INTO vTYPEPKSTRING;
WHILE c%FOUND LOOP
counter := counter + 1;
TYPEPK_list(counter) := vTYPEPKSTRING;
dbms_output.put_line('TABLE: '||i_table_name||'('||counter||'):'||TYPEPK_list(counter));
FETCH c INTO vTYPEPKSTRING;
END LOOP;
CLOSE c;
EXCEPTION
WHEN OTHERS THEN
IF c%ISOPEN THEN
CLOSE c;
END IF;
END SIEROT;
这是电话:
set serveroutput on
DECLARE
ind integer := 0;
BEGIN
FOR ind IN (select table_name from all_tab_columns where column_name='TYPEPKSTRING' AND table_name!='COMPOSEDTYPES')
LOOP
BEGIN
SIEROT(ind.table_name);
EXCEPTION
WHEN NO_DATA_FOUND THEN
null;
END;
END LOOP;
END;
此过程在模式上查找“ typepkstring”的所有值。这些是键的值,可以在PK列的“ compositetypes”表中找到。更具体地说,在此过程的框架中,我们在pk列中找到出现在模式上但未包括在该集合视图中的标识符。在我的特定瓶子中,有三个。该过程会通知我在哪个表中找到了密钥。 一切正常。但是,我必须为此功能添加另一个。 在此模式中,我大约有132个表,其中包含“ sourcepk”和“ targetpk”列。这些列还包含数字键。 现在,我要确定一件事: 对于找到的我的“ typepkstrings”,这两个列,即“ sourcepk”和“ targetpk”都应该为空。
我知道如何查找带有有趣列的表:
select distinct table_name from all_tab_columns where column_name='SOURCEPK' OR column_name ='TARGETPK';
通常,我想转换过程的这一部分:
FETCH c INTO vTYPEPKSTRING;
WHILE c%FOUND LOOP
counter := counter + 1;
TYPEPK_list(counter) := vTYPEPKSTRING;
dbms_output.put_line('TABLE: '||i_table_name||'('||counter||'):'||TYPEPK_list(counter));
FETCH c INTO vTYPEPKSTRING;
END LOOP;
我尝试在for循环中将上述选择添加到包含sourcepk和targetpk的表中,然后将vTYPEPKSTRING变量的if条件添加到表中。在给定遍中执行提取操作后,是否发现“ typepkstring”具有这些列的某些值。然而,什么也没有 通常,我会不断遇到新问题。我确实需要帮助,至少在定位方面需要帮助,尽管我不会鄙视代码。 预先感谢您的任何提示。:)
答案 0 :(得分:0)
我已经合并,合并并确定了。我放弃了以前的程序构造,并决定重新做一次。
我使用了4个嵌套游标,其中2个是引用游标。一切都根据假设进行。感谢您对上一篇文章的建议。
CREATE OR REPLACE PROCEDURE SIEROTKA
IS
t_name VARCHAR2(30);
od_typePK PRODUCTS.TYPEPKSTRING%TYPE;
t_nameST VARCHAR(30);
od_Source cat2prodrel.SOURCEPK%TYPE;
od_Target cat2prodrel.TARGETPK%TYPE;
sv_tname VARCHAR2(32767);
Get_typePK SYS_REFCURSOR;
sv_tnameST VARCHAR2(32767);
Get_Sierotki SYS_REFCURSOR;
CURSOR Get_PK_TN
IS
SELECT table_name FROM all_tab_columns
WHERE column_name='TYPEPKSTRING' AND
table_name!='COMPOSEDTYPES';
CURSOR Get_ST_TN
IS
SELECT DISTINCT table_name from all_tab_columns
WHERE column_name='SOURCEPK' OR
column_name='TARGETPK';
BEGIN
OPEN Get_PK_TN;
LOOP
FETCH Get_PK_TN INTO t_name;
EXIT WHEN Get_PK_TN%NOTFOUND;
sv_tname := 'SELECT DISTINCT i.TYPEPKSTRING FROM ' || t_name || ' i LEFT OUTER JOIN COMPOSEDTYPES c ON i.TYPEPKSTRING=c.PK WHERE c.PK IS NULL';
OPEN Get_typePK FOR sv_tname;
LOOP
FETCH Get_typePK INTO od_typePK;
IF Get_typePK%FOUND THEN
dbms_output.put_line('Znalezione Sirotka to: ' || t_name || ' --------- ' || od_typePK);
ELSE
EXIT WHEN Get_typePK%NOTFOUND;
END IF;
OPEN Get_ST_TN;
LOOP
FETCH Get_ST_TN INTO t_nameST;
EXIT WHEN Get_ST_TN%NOTFOUND;
sv_tnameST := 'SELECT SOURCEPK, TARGETPK FROM ' || t_nameST || ' WHERE PK=' || od_typePK || '';
OPEN Get_Sierotki FOR sv_tnameST;
LOOP
FETCH Get_Sierotki INTO od_Source, od_Target;
IF Get_Sierotki%FOUND THEN
dbms_output.put_line('Jednak to nie sierotka, bo posiada wpis: ' || t_name || ' --------- ' || od_typePK || ' ____________ ' || t_namest || ' --------- ' || od_Source || ' --------- ' || od_Target);
ELSE
EXIT WHEN Get_Sierotki%NOTFOUND;
END IF;
END LOOP;
CLOSE Get_Sierotki;
END LOOP;
CLOSE Get_ST_TN;
END LOOP;
CLOSE Get_typePK;
END LOOP;
CLOSE Get_PK_TN;
END;
为此,在begin end块中进行简单的单行调用:
set serveroutput on
BEGIN
SIEROTKA;
END;
/
直到下一个,很快见。