Unexpectedly got error while inserting data - oracle11g

when i executed the following statements i got some error.
CREATE TABLE TEST_TRG1(NAME VARCHAR2(50),DOB DATE);--table created successfully
CREATE TABLE TEST_TRG2(NAME VARCHAR2(50),DOB DATE);--table created successfully
CREATE OR REPLACE TRIGGER TR_TEST_TRG1
AFTER INSERT
ON
TEST_TRG1
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
BEGIN
INSERT INTO TEST_TRG2 (NAME,DOB) VALUES (:NEW.NAME,:NEW.DOB);
END TR_TEST_TRG1;
/--trigger created successfully
ALTER TRIGGER TR_TEST_TRG1 ENABLE;--trigger enabled successfully
INSERT INTO TEST_TRG1(NAME,DOB) VALUES('1',SYSDATE-4);--got error at this statement
INSERT INTO TEST_TRG1(NAME,DOB) VALUES('2',SYSDATE-3);
INSERT INTO TEST_TRG1(NAME,DOB) VALUES('3',SYSDATE-2);
/
error was
thanks in advance
edit:
table confirmation
executed show errors trigger

I do not know what the error is (I ran your script and got no errors) but to find out, in SQL Plus type this:
show error trigger TEST_TRG1

Related

How To Create a PL/SQL Trigger That Detects an Inserted or Updated Row and updates a Record in a Different Table?

I am creating a book tracking database for myself that holds information about my books and allows me to keep track of who is borrowing them. I am trying to create a trigger on my Checkouts table that runs if a record is added or updated that will determine if a checkout data has been entered or if a checkin date has been entered and change the "available" field in my Books table to "Y" or "N".
I have created a trigger called "update_book_availablility" on my Checkouts table but I keep getting this error:
"PLS-00103: Encountered the symbol 'end-of-file' when expecting one of the following: ( begin case declare and exception exit for goto if loop mod null pragma raise return select update while with <<continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge standard pipe purge json_object
Errors: check compiler log"
Here is my trigger code:
CREATE OR REPLACE NONEDITIONABLE TRIGGER "UPDATE_BOOK_AVAILABILITY"
AFTER INSERT OR UPDATE OF ISBN, PersonID, checkout_date, checkin_date
ON Checkouts
FOR EACH ROW
BEGIN
IF :NEW.checkout_date = NULL
THEN
UPDATE Book
SET available = 'N'
WHERE ISBN IN (SELECT :NEW.ISBN FROM Checkouts);
END IF;
END;
Here is an image of my ERD:
ERD
I have been looking into and double checking my trigger syntax, If condition syntax, subquery syntax, and googling this error but have found nothing that has helped. I am new to PL/SQL and would appreciate any help in understanding what I have done wrong or missed.
PLS-00103: Encountered the symbol end-of-file error is SYNTAX ERROR
Copied your trigger and adjusted it to one of my test tables - it works. I removed NONEDITIONABLE and changed trigger table name as well as column names and table/column beeing updated by trigger.
To Do:
Check your syntax again or write the trigger from scratch once more
"...WHERE ISBN IN (SELECT :NEW.ISBN FROM Checkouts)..." selects one fixed value (FOR EACH ROW) :NEW.ISBN of triggering table, better ->> "... WHERE ISBN = :NEW.ISBN ..."
Prety sure that you don't need NONEDITIONABLE trigger for your books tracking app...
Regards...

Whats the correct syntax for on conflict do update sqlyte?

I am trying to insert clients on a table(importing them from a csv), the email column needs to be unique(in the csv the a client can appear more than one time, the last instance has the correct info) and the ids are created with an autoincrementing value (this is why i cant use select or replace), im trying to use the syntax found in the sqlite guide(and in every question about ON CONFLICT DO UPDATE found here) but sqlite throws a
SQL logic error near "ON" :syntax error
the query goes like this(using VB)
sqlQuery = "INSERT INTO clients(name1,name2,address1,address2,plz,city,country,phoneNumber1,phoneNumber2,cellPhoneNumber,fax,email) VALUES (?,?,?,?,?,?,?,?,?,?,?,?) ON CONFLICT(email) DO UPDATE SET name1=excluded.name1,name2=excluded.name2,address1=excluded.address1,address2=excluded.address2,plz=excluded.plz,city=excluded.city,country=excluded.country,phoneNumber1=excluded.phoneNumber1,phoneNumber2=excluded.phoneNumber2,cellPhoneNumber=excluded.cellPhoneNumber,fax=excluded.fax,email=excluded.email;

plsql Trigger error ORA-00604

Following Trigger created in a user anu
create or replace trigger audit_creation1
before create
on schema
begin
insert into audit_creation
values(audit_creation_s1.nextval,
ora_dict_obj_owner,
ora_dict_obj_name,
sysdate);
end;
create table cc(cid number);
ORA-00604: error occurred at recursive SQL level 1
ORA-30511: invalid DDL operation in system triggers
This worked before many times. It was working successfully.
But now it's throwing error.
Throw a command
purge recyclebin;
as your trigger owner (anu in your case).

java.sql.SQLSyntaxErrorException: ORA-04098: trigger 'MYTABLE.MY_SEQUENCE_ID' is invalid and failed re-validation

I am creating this oracle 11g statement inside a java String and then executing it in sql developer. I tried running it on the database and got a warning when the trigger
is created. But, when run from the code, I get the error mentioned in my title.
Please tell me where is the mistake and how i can fix it ?
CREATE OR REPLACE TRIGGER myschema.my_sequence_id BEFORE INSERT ON myschema.mytable
FOR EACH ROW BEGIN SELECT my_sequence_id.nextval INTO :new.mycolumn FROM DUAL; end; /
Thanks in advance !
You can't have a trigger named my_sequence_id if you already have a sequence my_sequence_id. They share the same namespace. Your trigger would need to be named something other than the name of the sequence (or any other object in the schema).

No table found error in SQlite

I have a problem with SQlite. Whenever I execute Queries it goes fine but when I exit by .exit command and open again and execute Select * form emp statement, it renders no table even though I use begin transaction and commit .
Any help please. I'm new to SQLite.
Thanks
Bamadeva
I got the solution:-
Wherever our database is created, in my case it is :-
C:\Sites\databases>
Since my database is contactlist_development, I should have entered it with the following commands:-
C:\Sites\databases>sqlite3 contactlist_development
This takes me to :-
sqlite>.schema
Then i am able to view the table details which i just created:)

Resources