oracle query question

DROP TABLE DSS.TAB1 CASCADE CONSTRAINTS;

CREATE TABLE DSS.TAB1
(
  ID                    NUMBER(38)              NOT NULL,
  REG_ID_FROM           NUMBER(38)              NOT NULL,
  REG_ID_TO             NUMBER(38)              NOT NULL,
  WEIGHT_MAXIMUM        NUMBER(6)               NOT NULL,
  ESTIMATED_FREIGHT     NUMBER(10,2),
  PER_POUND_MULTIPLIER  NUMBER(6,2),
  CARRMETH_ID           NUMBER(38),
  PROFS_ID_CMETHTYPE    NUMBER(38)
)
TABLESPACE MISC
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           )
LOGGING 
NOCOMPRESS 
NOCACHE
MONITORING;

SET DEFINE OFF;
Insert into DSS.TAB1
   (ID, REG_ID_FROM, REG_ID_TO, WEIGHT_MAXIMUM, ESTIMATED_FREIGHT, 
    PER_POUND_MULTIPLIER, CARRMETH_ID, PROFS_ID_CMETHTYPE)
 Values
   (13219125811, 13218967894, 13218967894, 100, NULL, 
    10, 1534, NULL);
Insert into DSS.TAB1
   (ID, REG_ID_FROM, REG_ID_TO, WEIGHT_MAXIMUM, ESTIMATED_FREIGHT, 
    PER_POUND_MULTIPLIER, CARRMETH_ID, PROFS_ID_CMETHTYPE)
 Values
   (13219112356, 13218967894, 13218967894, 100, 150, 
    NULL, NULL, 14258);
Insert into DSS.TAB1
   (ID, REG_ID_FROM, REG_ID_TO, WEIGHT_MAXIMUM, ESTIMATED_FREIGHT, 
    PER_POUND_MULTIPLIER, CARRMETH_ID, PROFS_ID_CMETHTYPE)
 Values
   (13219042831, 13219042603, 13218967894, 100, 900, 
    NULL, 1592, NULL);
Insert into DSS.TAB1
   (ID, REG_ID_FROM, REG_ID_TO, WEIGHT_MAXIMUM, ESTIMATED_FREIGHT, 
    PER_POUND_MULTIPLIER, CARRMETH_ID, PROFS_ID_CMETHTYPE)
 Values
   (13219042759, 13219042603, 13218967894, 100, 276, 
    NULL, NULL, 14264);
Insert into DSS.TAB1
   (ID, REG_ID_FROM, REG_ID_TO, WEIGHT_MAXIMUM, ESTIMATED_FREIGHT, 
    PER_POUND_MULTIPLIER, CARRMETH_ID, PROFS_ID_CMETHTYPE)
 Values
   (13218990529, 13218979268, 13218979264, 100, 276, 
    NULL, NULL, 14260);
COMMIT;

Open in new window


I have a code that check for few conditions in inserting data
	v_region_count number;
	v_region_count1 number;
Begin
	select count(*) into v_region_count
	  from dss.freight_estimates
	 where weight_maximum = :freight_estimates.weight_maximum
	   AND reg_id_from = :freight_estimates.reg_id_from 
	   and reg_id_to = :freight_estimates.reg_id_to
	   and carrmeth_id = :freight_estimates.carrmeth_id
	   and profs_id_cmethtype is null;
	   
	select count(*) into v_region_count1
	  from dss.freight_estimates
	 where weight_maximum = :freight_estimates.weight_maximum
	   AND reg_id_from = :freight_estimates.reg_id_from 
	   and reg_id_to = :freight_estimates.reg_id_to
	   and carrmeth_id is null
	   and profs_id_cmethtype = :freight_estimates.profs_id_cmethtype;

End;

Open in new window

	    
If v_region_count > 0 then
  	msg_alert('The combination of Maximum Weight,Region From, Region To and Carrier Method already exists','E',true);
ElsIf v_region_count1 > 0 then
  	msg_alert('The combination of Maximum Weight,Region From, Region To and Carrier Type already exists','E',true);
End if;

Open in new window


I want the same thing on update. How do I check?
LVL 6
anumosesAsked:
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.

slightwv (䄆 Netminder) Commented:
>>I have a code that check for few conditions in inserting data

Depending on how long that takes to execute, it can probably be combined into a single select.

This is untested but something like:
Begin
	select
		count(case when profs_id_cmethtype is null and carrmeth_id = :freight_estimates.carrmeth_id then 1 end),
		count(case when carrmeth_id is null and profs_id_cmethtype = :freight_estimates.profs_id_cmethtype then 1 end)
			into v_region_count, v_region_count1
	  from dss.freight_estimates
	 where weight_maximum = :freight_estimates.weight_maximum
	   AND reg_id_from = :freight_estimates.reg_id_from 
	   and reg_id_to = :freight_estimates.reg_id_to;
End;

Open in new window


>>I want the same thing on update. How do I check?

Based on your previous questions I assume that this is for Forms?

My guess is whatever trigger you have on insert should be the same for update but I'm not a Forms person.

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
anumosesAuthor Commented:
thanks
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.