Help me fix the code

When I execute teh code below, I get error listed below...


BEGIN
for i IN (SELECT owner, table_name, constraint_name
FROM dba_constraints
WHERE constraint_type <>'R'
AND OWNER IN ('BO','CCRC', 'IA', 'MOMENTUM', 'ODS', 'PB', 'UFMS','UF_ODS', 'VSS', 'VSWMAUDIT', 'WFWMAUDIT', 'WMAUDIT', 'WORKFLOW')
AND status = 'ENABLED')
loop
EXECUTE IMMEDIATE 'alter table ' || i.owner ||'.' ||i.table_name|| ' disable constraint ' ||i.constraint_name;
end loop i;
END;
/

BEGIN
*
ERROR at line 1:
ORA-00942: table or view does not exist
ORA-06512: at line 8

However, when I run the embeded SQL Statement it returns 744 rows.  


Kamal AgnihotriAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mohammadzahidCommented:
Checked your code and it works fine. Do you have DBA_xxx system views privileges granted to your account?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OP_ZaharinCommented:
hi Kamal,
- i'm suggesting another way by generating a list of 'Alter Table' script by running the following SQL statement.
- from the result it will format the whole command of alter table <owner.tablename> disable constraint <constraintname> and you can run it in any SQL Editor.

SELECT 'ALTER TABLE ' || owner ||'.'|| table_name || ' DISABLE CONSTRAINT ' || constraint_name 
FROM dba_constraints
WHERE constraint_type <>'R'
AND OWNER IN ('BO','CCRC', 'IA', 'MOMENTUM', 'ODS', 'PB', 'UFMS','UF_ODS', 'VSS', 'VSWMAUDIT', 'WFWMAUDIT', 'WMAUDIT', 'WORKFLOW')
AND status = 'ENABLED'

Open in new window

0
Kamal AgnihotriAuthor Commented:
Hi MohammadZaid,

I am running the code logged in as sys. The above code does not work for me. It gives yhe error listed above.

However, a similar code, listed below works.

BEGIN
for i IN (SELECT owner, table_name, constraint_name
FROM dba_constraints
WHERE constraint_type ='R'
AND OWNER IN ('BO','CCRC', 'IA', 'MOMENTUM', 'ODS', 'PB', 'UFMS','UF_ODS', 'VSS', 'VSWMAUDIT', 'WFWMAUDIT', 'WMAUDIT', 'WORKFLOW')
AND status = 'ENABLED')
loop
EXECUTE IMMEDIATE 'alter table ' || i.owner ||'.' ||i.table_name|| ' disable constraint ' ||i.constraint_name;
end loop i;
End;
/

The only difference between the two is the WHERE CONSTRAINT_TYPE <> 'R'
0
PilouteCommented:
Hi,

It is strange to see you can't modify an object as SYS.
In order to identify the 'bad' object for further investigation, just add an exception catching with display of the object that triggers the error :

DECLARE
   tab_owner varchar2(30);
   tab_name varchar2(30);
   tab_contraint varchar2(30);
BEGIN
for i IN (SELECT owner, table_name, constraint_name
FROM dba_constraints
WHERE constraint_type <>'R'
AND OWNER IN ('BO','CCRC', 'IA', 'MOMENTUM', 'ODS', 'PB', 'UFMS','UF_ODS', 'VSS', 'VSWMAUDIT', 'WFWMAUDIT', 'WMAUDIT', 'WORKFLOW')
AND status = 'ENABLED')
loop
tab_owner:=i.owner;
tab_name:=i.table_name;
tab_constraint:=i.constraint_name;
EXECUTE IMMEDIATE 'alter table ' || i.owner ||'.' ||i.table_name|| ' disable constraint ' ||i.constraint_name;
end loop i;
EXCEPTION
   WHEN OTHERS THEN
      dbms_output.put_line(tab_owner ||'.' ||tab_name||'.' ||tab_constraint)
END;

You should now know which object you can't modify... (like a missing object still referenced somewhere in the catalog)...

Cheers,
P
0
yuchingCommented:
pretty strange, do you have schema which are case sensitive.
Perhaps you can try this, add " " in the table name i.e
ALTER TABLE Owner."TableName" Enable Constraint "Constraint_Name"

BEGIN
for i IN (SELECT owner, table_name, constraint_name
FROM dba_constraints
WHERE constraint_type <>'R'
AND OWNER IN ('BO','CCRC', 'IA', 'MOMENTUM', 'ODS', 'PB', 'UFMS','UF_ODS', 'VSS', 'VSWMAUDIT', 'WFWMAUDIT', 'WMAUDIT', 'WORKFLOW')
AND status = 'ENABLED')
loop
EXECUTE IMMEDIATE 'alter table ' || i.owner ||'."' ||i.table_name|| '" disable constraint "' ||i.constraint_name || '"';
end loop i;
END;
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.