Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7617731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:13:17+00:00 2026-05-31T03:13:17+00:00

I have two tables– create table mobile ( id int, m_name varchar(20), purchase_date datetime

  • 0

I have two tables–

create table mobile
(
id int,
m_name  varchar(20),
purchase_date datetime
)


insert into mobile values('1','Samsung corby','12-JAN-12');
insert into mobile values('2','Nokia E5','15-MAR-12');
insert into mobile values('3','Sony Talk','10-FEB-12');



create table location
(
id int,
l_name varchar(20)
) 
insert into location values(1,'London');
insert into location values(2,'Washington');
insert into location values(3,'Mexico');

I want to create a trigger which will ensure that sony talk mobile which is in mexico can not be purchased on December.That means whenever I try to insert data in mobile table with ID as 3 and purchase_date as December, the trigger should stop it and give appropriate message.

My code for this is —

create  or replace  trigger trg1
before insert or update
on mobile
for each row
declare
var1 number(4);  
begin
select id into var1 from location where l_name='Mexico';
    IF (:new.id = var1 and to_char(:new.purchase_date, 'MONTH') = 'DECEMBER') THEN 
        raise_application_error( -20001, 'THIS mobile CAN NOT BE PURCHASED NOW.');
    END IF; 
end; 

The trigger was created, but when i try to insert this data using this code–

insert into mobile values('3','Sony Talk','10-JAN-11');

The trigger fires but gives an error —

ORA-04098: trigger 'OPS$0924769.TRG1' is invalid and failed re-validation 

and my if code is also not working properly–

    IF (:new.id = var1 and to_char(:new.purchase_date, 'MONTH') = 'DECEMBER') THEN 
        raise_application_error( -20001, 'THIS mobile CAN NOT BE PURCHASED NOW.');
    END IF; 

its not checking for both id and purchase_date.
I gave purchase_date as JAN , so in this case the trigger should not fire.
I am confused.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:13:18+00:00Added an answer on May 31, 2026 at 3:13 am
    1. Your trigger was created with compilation errors. If you type show errors after creating the trigger, SQL*Plus will display the syntax errors to you.
    2. Oracle does not have a DATETIME data type. The data type of the purchase_date column in mobile would need to be a DATE.
    3. The trigger you posted compiles and runs without error on my system once I correct the error in defining the mobile table
    4. When you use TO_CHAR with a format mask of MONTH, the results will be right-padded with spaces to the length of the longest month (9 characters). Since DECEMBER only has 8 characters, your condition is never going to evaluate to TRUE. You would need to either TRIM the output or to use the fmMONTH format mask which does not pad the output with spaces.

    Something like

    create  or replace  trigger trg1
    before insert or update
    on mobile
    for each row
    declare
    var1 number(4);  
    begin
    select id into var1 from location where l_name='Mexico';
        IF (:new.id = var1 and to_char(:new.purchase_date, 'fmMONTH') = 'DECEMBER') THEN 
            raise_application_error( -20001, 'THIS mobile CAN NOT BE PURCHASED NOW.');
        END IF; 
    end; 
    

    would be more likely what you’re looking for. But that doesn’t explain why your trigger is getting compilation errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables CREATE TABLE table1 (id int primary key auto_increment,....); CREATE TABLE
I have two tables, like these: Table People: VARCHAR Name INTEGER Age Table Message
I have two tables: Table 1: ID, PersonCode, Name, Table 2: ID, Table1ID, Location,
I have two tables with this structure: Table one: ID Description Table two: ID
I have two tables. Table Emp id name 1 Ajay 2 Amol 3 Sanjay
I have two tables. One table contains information about Assets, another Table about their
I have two tables. One is temp table and another is main table. In
I have two tables: one table (okay, it's a view), vComputer, lists many computers
I have two tables, orders and old_orders. Each table has some similar fields and
I have two tables in my database. A person and a coach table. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.