Column Restriction [message #608813] |
Tue, 25 February 2014 02:53 |
ORAGENASHOK
Messages: 240 Registered: June 2006 Location: Chennai
|
Senior Member |
|
|
Am trying to restrict/Alert user on CREATE TABLE if more than 50 columns.
Can anyone suggest on this
Version - Oracle 11g.
|
|
|
Re: Column Restriction [message #608816 is a reply to message #608813] |
Tue, 25 February 2014 03:37 |
|
dariyoosh
Messages: 538 Registered: March 2009 Location: France
|
Senior Member |
|
|
Here is an example that prevents you from creating a table with more than five columns
SQL> create or replace trigger test_trigger
2 after create on schema
3 begin
4 <<bk>>
5 declare
6 cnt pls_integer := 0;
7 begin
8 if sys.dictionary_obj_type = 'TABLE' then
9 select
10 count(*)
11 into
12 bk.cnt
13 from
14 user_tab_columns t1
15 where
16 t1.table_name = sys.dictionary_obj_name;
17 --
18 if bk.cnt > 5 then
19 raise_application_error(-20001, 'too many columns');
20 end if;
21 end if;
22 end;
23 end;
24 /
Trigger created.
SQL> show errors;
No errors.
SQL>
SQL> create table t1(n number);
Table created.
SQL> create table t2(n1 number, n2 number, n3 number, n4 number, n5 number, n6 number);
create table t2(n1 number, n2 number, n3 number, n4 number, n5 number, n6 number)
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-20001: too many columns
ORA-06512: at line 17
[Updated on: Tue, 25 February 2014 03:41] Report message to a moderator
|
|
|
|
|
Re: Column Restriction [message #608838 is a reply to message #608816] |
Tue, 25 February 2014 06:33 |
ORAGENASHOK
Messages: 240 Registered: June 2006 Location: Chennai
|
Senior Member |
|
|
Thanks dariyoosh , Exactly its related to performance of application.
Can i get the user action from SYS like CREATE or ALTER , because based on this i have another work around.
Is this SYS.dictionary_obj_type is table or views?
|
|
|
Re: Column Restriction [message #608841 is a reply to message #608816] |
Tue, 25 February 2014 07:00 |
Solomon Yakobson
Messages: 3273 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
dariyoosh wrote on Tue, 25 February 2014 04:37Here is an example that prevents you from creating a table with more than five columns
[code]
Yes, this is basic solution. But OP also needs to clarify what type of columns shoul be counted. Should virtual column be counted? Hidden column? Invisible column (12C)?
SY.
|
|
|
Re: Column Restriction [message #608856 is a reply to message #608841] |
Tue, 25 February 2014 09:33 |
|
BlackSwan
Messages: 26766 Registered: January 2009 Location: SoCal
|
Senior Member |
|
|
>Am trying to restrict/Alert user on CREATE TABLE if more than 50 columns.
why do folks have the necessary privileges if they can not be trusted to comply with policy?
why not terminate anyone who violates 50 column limit?
why does policy limit require a technical solution?
I suspect application does not comply with Third Normal Form.
|
|
|