Home » SQL & PL/SQL » SQL & PL/SQL » Cannot create a trigger
Cannot create a trigger [message #526233] Mon, 10 October 2011 05:03 Go to next message
zabltn
Messages: 45
Registered: September 2011
Member
Okay now i can log in but here i faced with another erorr, while i am creating a trigger it gives the following erorr:
SQL> ed
Wrote file afiedt.buf

  1  create or replace trigger trgr
  2  before insert on myTable
  3  for each row
  4  begin
  5  select mySequence.nextval into :new.ID from dual;
  6* end;
SQL> /
create or replace trigger trgr
                          *
ERROR at line 1:
ORA-04089: cannot create triggers on objects owned by SYS


note: i tried and gave different names for the trigger, still it is the same.
Re: User login fails [message #526240 is a reply to message #526233] Mon, 10 October 2011 05:15 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Create a new topic in "SQL & PL/SQL forum".

NEVER EVER use SYS to store your objects.
Create your own schemas, do not use Oracle ones.

Regards
Michel
Re: User login fails [message #526248 is a reply to message #526240] Mon, 10 October 2011 05:47 Go to previous messageGo to next message
zabltn
Messages: 45
Registered: September 2011
Member
Okay thanks i will, but what do you mean by dont use SYS objects, i have not used any SYS object i just tried to create a trigger in my own user and it fails, gives the above erorr.
Re: User login fails [message #526264 is a reply to message #526248] Mon, 10 October 2011 06:34 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I believe that Michel's objection refers this line:
ORA-04089: cannot create triggers on objects owned by SYS

As you said
create or replace trigger trgr
  before insert on myTable
and Oracle replied that it can not create trigger on an object owned by SYS, it means that myTable is owned by SYS. It doesn't matter that it was you (zabltn) who created a table (typing CREATE TABLE myTable ...) - it is still owned by SYS, as you were logged in as SYS.

You should create your own user (or, if you don't want to bother, SCOTT's schema would be OK) and practice your skills there.

[Updated on: Mon, 10 October 2011 06:35]

Report message to a moderator

Re: User login fails [message #526295 is a reply to message #526264] Mon, 10 October 2011 08:12 Go to previous messageGo to next message
saipradyumn
Messages: 419
Registered: October 2011
Location: Hyderabad
Senior Member

Hi Zabltn ,

I am able to create trigger successfully. I think the problem is with the Permission of that object not with actual code . Check the owner of the table in all_objects data dictionary .

My code was


   create table mytable(id number); 
    
   create sequence mySequence  start with 1 increment by 1 ; 

    create or replace trigger trgr
        before insert on myTable
        for each row
    begin
          select
                       mySequence.nextval 
           into        :new.ID 
           from         dual;
        dbms_output.put_line(' sequence vqalue ' || :new.ID);
   end;

   insert into mytable values (12367);
   insert into mytable values (8596); 
   insert into mytable values (989); 

  But the out put 
  
   Select  *  from mytable; 
    
   Id 
   1
   2
   3




In this case owner of the object DBO(MY schema name) not the SYS.

Is this your requirement ?

Please let me know that status also

Thanks
Sai Pradyumn

Re: User login fails [message #526301 is a reply to message #526295] Mon, 10 October 2011 08:21 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
In this case owner of the object DBO(MY schema name) not the SYS.

Is this your requirement ?

Yes.

Regards
Michel
Re: User login fails [message #526398 is a reply to message #526264] Mon, 10 October 2011 23:26 Go to previous messageGo to next message
zabltn
Messages: 45
Registered: September 2011
Member
Dear Littlefoot,

Thanks but i have created either the table and tha trigger by the same newly created user <user1>, the table and sequence was created successfuly but it gives the erorr by creating the trigger.

[Updated on: Mon, 10 October 2011 23:30]

Report message to a moderator

Re: User login fails [message #526399 is a reply to message #526398] Mon, 10 October 2011 23:35 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>the table and sequence was created successfuly but it gives the erorr by creating the trigger.
how can we reproduce what you report?

It would be helpful if you followed Posting Guidelines - http://www.orafaq.com/forum/t/88153/0/
Re: User login fails [message #526400 is a reply to message #526398] Mon, 10 October 2011 23:55 Go to previous messageGo to next message
zabltn
Messages: 45
Registered: September 2011
Member
Dear Sai Pradyumn,
Here is what i have done:

SQL> conn user1/user1 @myNSN as sysdba
Connected.
SQL> create table myTable (ID number);

Table created.

SQL> select owner from all_tables where table_name= 'MYTABLE';

OWNER
------------------------------
SYS


SQL> ed
Wrote file afiedt.buf

  1  create or replace trigger trgr
  2  before insert on myTable
  3  for each row
  4  begin
  5  select mySequence.nextval into :new.ID from dual;
  6* end;
SQL> /
create or replace trigger trgr
                          *
ERROR at line 1:
ORA-04089: cannot create triggers on objects owned by SYS



I have created with the user <user1> now please let me know where is my misstake, or if it is okay then why still it says SYS.

Dear BlackSwan you can see it in the above example.

[Updated on: Tue, 11 October 2011 00:07]

Report message to a moderator

Re: User login fails [message #526410 is a reply to message #526400] Tue, 11 October 2011 00:43 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
conn user1/user1 @myNSN as sysdba

So now you are SYS.
Just execute "show user" and you will see.

- Never ever use SYS (or SYSDBA) but for maintenance purpose (startup, shutdown, backup, recover)
- SYS/SYSDBA is special
- SYS/SYSDBA is Oracle proprietary (try to open a SR/TAR starting with "i did that with SYS/SYSDBA" and you'll see the immediate answer)
- SYS/SYSDBA does not act like any other user
- When you use SYS/SYSDBA Oracle deactivates some code path and activates others
- Whatever you do with SYS/SYSDBA will neither validate nor invalidate the same thing with any other user.

NEVER EVER use SYS/SYSDBA for anything that can be done by another user.
Use SYS/SYSDBA ONLY for something that can't be done by someone else.


Regards
Michel
Re: User login fails [message #526411 is a reply to message #526410] Tue, 11 October 2011 00:47 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Why do you connect as SYSDBA?

Try to connect simply as "user1/user1@mynsn" and create a table & its trigger once again.
Re: User login fails [message #526417 is a reply to message #526411] Tue, 11 October 2011 01:00 Go to previous messageGo to next message
zabltn
Messages: 45
Registered: September 2011
Member
Michel, Thank you very much for always giving the neccessary information.
But friends, i had tried to login without the sysdba rule but then it would give erorr for the privilege.
SQL> conn user1/user1 @myNSN
Connected.
SQL> create table tbl (ID number);
create table tbl (ID number)
*
ERROR at line 1:
ORA-01031: insufficient privileges

[Updated on: Tue, 11 October 2011 01:02]

Report message to a moderator

Re: User login fails [message #526418 is a reply to message #526400] Tue, 11 October 2011 01:01 Go to previous messageGo to next message
saipradyumn
Messages: 419
Registered: October 2011
Location: Hyderabad
Senior Member

Dear Zabltn

Why you are connecting as SYSDBA.Is there any specific reason ?
Try with out using "as sysdba" Key word .
if you select user from dual it must be equal to the actual user(In your case user1). But If you are connecting as 'SYSDBA', it will give the "SYSDBA" only .

Thanks
Sai Pradyumn

Re: User login fails [message #526419 is a reply to message #526418] Tue, 11 October 2011 01:02 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
If you can't create a table, you don't have the CREATE TABLE privilege - as you seem to be powerful enough, grant it to USER1.
Re: User login fails [message #526422 is a reply to message #526419] Tue, 11 October 2011 01:14 Go to previous messageGo to next message
zabltn
Messages: 45
Registered: September 2011
Member
Exactly, i had tried to grant some privileges but then it gives error that you have to be SYS to grant a privilege, but i dont know the password for the SYS user i am not able to login as a SYS.
Therefor can you please tell me how to grant a powerfull privilege for the user user1 like the SYSDBA power to be able to do create, drop... objects, while i dont know the SYS user password.
Re: User login fails [message #526424 is a reply to message #526417] Tue, 11 October 2011 01:20 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
But friends, i had tried to login without the sysdba rule but then it would give erorr for the privilege

To be able to create a table your ser must have 2 things:
1/ CREATE TABLE privilege
2/ Quota on the tablespace he wants to create the table (as you don't specify any, it is his default tablespace which is the database default tablespace because you don't specify any default on the CREATE USER statement).
You can get the default tablespace of your user using:
select default_tablespace from dba_users where username='<your user (in upper case)>';


Regards
Michel
Re: User login fails [message #526425 is a reply to message #526424] Tue, 11 October 2011 01:24 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
Exactly, i had tried to grant some privileges but then it gives error that you have to be SYS to grant a privilege,

This is not true, you have to be a DBA (or something like that) but surely NOT SYS/SYSDBA.

Quote:
but i dont know the password for the SYS user i am not able to login as a SYS.

As you previously saw when you connect AS SYSDBA then you are SYS, you don't need SYS password.
Connecting AS SYSDBA is like "su" in Unix, you connect from your user to SYS.

I advise you to:
1/ As SYS, create a new account, say "userdba", that you will give it DBA role.
2/ From this new account, make the account management like granting CREATE TABLE to your previous user (user1).
3/ Play with "user1" to make your tests.

Regards
Michel
Re: User login fails [message #526442 is a reply to message #526425] Tue, 11 October 2011 02:26 Go to previous messageGo to next message
zabltn
Messages: 45
Registered: September 2011
Member
Thanks, i did the following steps, now please tell me should i give the default tablespace which is in my case SYSTEM or i have to create a new tablespace.

SQL> create user user2 identified by user2;

User created.

SQL> conn user2/user2 @myNSn as sysdba
Connected.
SQL> grant create any table to user1;

Grant succeeded.

SQL> conn user1/user1 @myNSN
Connected.
SQL> create table tbl(ID number);
create table tbl(ID number)
*
ERROR at line 1:
ORA-01950: no privileges on tablespace 'SYSTEM'
Re: User login fails [message #526448 is a reply to message #526442] Tue, 11 October 2011 02:47 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
now please tell me should i give the default tablespace which is in my case SYSTEM or i have to create a new tablespace.

You MUST create a new tablespace, SYSTEM is only for Oracle objects.

The error you get is expected: you do not satisfy the 2 conditions I mentioned.

Regards
Michel
Re: User login fails [message #526585 is a reply to message #526448] Tue, 11 October 2011 14:33 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
See if you can follow the steps below. Each block is logged in as a separate user.

Connect sys as sysdba using anything in place of the password that you do not know. Then use show user to confirm that you are connected as sys. Then create a user with dba privileges.
SQL> CONNECT sys/anythingr@myNSN AS SYSDBA
Connected.
SQL> SHOW USER
USER is "SYS"
SQL> CREATE USER userdba IDENTIFIED BY userdba
  2  /

User created.

SQL> GRANT DBA TO userdba
  2  /

Grant succeeded.


Connect to the user with dba privileges. Then use show user to confirm that you are connected as that user. Then create a non-dba user specifying tablespaces. Then grant the necessary privileges to the non-dba user.
SQL> CONNECT userdba/userdba@myNSN
Connected.
SQL> SHOW USER
USER is "USERDBA"
SQL> CREATE USER user1 IDENTIFIED BY user1
  2  DEFAULT TABLESPACE users QUOTA 10M ON users
  3  TEMPORARY TABLESPACE temp
  4  /

User created.

SQL> GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER TO user1
  2  /

Grant succeeded.


Connect as the non-dba user. Then user show user to confirm that you are connected as that user. Then create a table, sequence, and trigger, and test inserts.
SQL> CONNECT user1/user1@myNSN
Connected.
SQL> SHOW USER
USER is "USER1"
SQL> CREATE TABLE myTable
  2    (seq  NUMBER,
  3  	id   NUMBER)
  4  /

Table created.

SQL> CREATE SEQUENCE mySequence
  2  /

Sequence created.

SQL> CREATE OR REPLACE TRIGGER myTrigger
  2    BEFORE INSERT ON myTable
  3    FOR EACH ROW
  4  BEGIN
  5    SELECT mySequence.NEXTVAL INTO :NEW.seq FROM DUAL;
  6  END myTrigger;
  7  /

Trigger created.

SQL> SHOW ERRORS
No errors.
SQL> INSERT INTO myTable (id) VALUES (12367);

1 row created.

SQL> INSERT INTO myTable (id) VALUES (8596);

1 row created.

SQL> INSERT INTO myTable (id) VALUES (989);

1 row created.

SQL> SELECT * FROM myTable
  2  /

       SEQ         ID
---------- ----------
         1      12367
         2       8596
         3        989

3 rows selected.

SQL>

Re: User login fails [message #526635 is a reply to message #526585] Wed, 12 October 2011 02:31 Go to previous messageGo to next message
Roachcoach
Messages: 1576
Registered: May 2010
Location: UK
Senior Member
I thought DBA was being/is depreciated?

Obviously it's just an example but if my memory serves it's worth mentioning.
Re: User login fails [message #526639 is a reply to message #526635] Wed, 12 October 2011 02:48 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
I had not heard that, but I looked it up in the documentation and your are right:

http://download.oracle.com/docs/cd/E11882_01/network.112/e16543/authorization.htm#DBSEG4414

Apparently it has been that way for some time.

The below query results in 202 privileges that would have to be granted to provide the same privileges as the DBA role.

select privilege from dba_sys_privs where grantee = 'DBA';

Re: User login fails [message #526640 is a reply to message #526639] Wed, 12 October 2011 02:51 Go to previous message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
It is better to create your own "DBA" role or roles with the necessary privileges to allow the dbas to make their tasks (which can be different depending on the dba, for instance depending on his/her level or skills).

Regards
Michel
Previous Topic: Query
Next Topic: Double Right Outer Join
Goto Forum:
  


Current Time: Fri Apr 26 09:54:19 CDT 2024