473,767 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Required field for updates


It's easy to make a field required for inserts, just set it to not null
and don't give it a default.

But how does one make a field required for updates? For instance, we
have a table with a field that keeps track of which application last
updated the table

MYTABLE
------
ID PK
APPLICATION_ID
MORE_STUFF

I want to write a PL/SQL trigger that requires the application to
specify the appilication_id , and throw an error if the application fails
to provide a value. I.e. this SQL command should fail:

"UPDATE MYTABLE set MORE_STUFF = 'foo' WHERE ID = 123;"

IOW, how does one determine the update list in a PL/SQL trigger? I can
check to see if the value changed, but that won't do it.

--
//-Walt
//
//
Jul 19 '05 #1
6 4263
Why not try to check :new and :old values ?
Jul 19 '05 #2
philippe wrote:

Why not try to check :new and :old values ?


Because it doesn't tell me anything. If the application left the field
out of the update list, :old and :new will be the same. If the
application specified a value that's the same as the old value, :old and
:new will be the same.

How does one distinguish the two cases?

--
//-Walt
//
//
Jul 19 '05 #3

Try:
IF Updating('APPLI CATION_ID') Then
... Do something ...
Else
raise_applicati on_error(-200001,'No APPLICATION_ID found');
End If;

--
Posted via http://dbforums.com
Jul 19 '05 #4
Walt <wa**@boatnerd. com.invalid> wrote in message news:<3F******* ********@boatne rd.com.invalid> ...
It's easy to make a field required for inserts, just set it to not null
and don't give it a default.

But how does one make a field required for updates? For instance, we
have a table with a field that keeps track of which application last
updated the table

MYTABLE
------
ID PK
APPLICATION_ID
MORE_STUFF

I want to write a PL/SQL trigger that requires the application to
specify the appilication_id , and throw an error if the application fails
to provide a value. I.e. this SQL command should fail:

"UPDATE MYTABLE set MORE_STUFF = 'foo' WHERE ID = 123;"

IOW, how does one determine the update list in a PL/SQL trigger? I can
check to see if the value changed, but that won't do it.


Hi Walt,

Unless I've completely missed the intent of your post, just include
this type of logic in a BEFORE UPDATE trigger:

IF :NEW.APPLICATIO N_ID IS NULL THEN....

Steve
Jul 19 '05 #5
LKBrwn_DBA wrote:

Try:

IF Updating('APPLI CATION_ID') Then
.. Do something ...
Else
raise_applicati on_error(-200001,'No APPLICATION_ID found');
End If;


Thanks. That appears to do it. I've used the IF UPDATING construct
before, but I didn't know you could specify a column. Cool.

You wouldn't happen to have a pointer to some documentation to this
feature, would you? It's not covered in any of my Oracle Press or
O'reilly PL/SQL books.

--
//-Walt
//
//
Jul 19 '05 #6
Stephen_CA wrote:

Walt <wa**@boatnerd. com.invalid> wrote


... how does one make a field required for updates? For instance, we
have a table with a field that keeps track of which application last
updated the table

MYTABLE
------
ID PK
APPLICATION_ID
MORE_STUFF

I want to write a PL/SQL trigger that requires the application to
specify the appilication_id , and throw an error if the application fails
to provide a value. I.e. this SQL command should fail:

"UPDATE MYTABLE set MORE_STUFF = 'foo' WHERE ID = 123;"

IOW, how does one determine the update list in a PL/SQL trigger? I can
check to see if the value changed, but that won't do it.

Unless I've completely missed the intent of your post, just include
this type of logic in a BEFORE UPDATE trigger:

IF :NEW.APPLICATIO N_ID IS NULL THEN....


Thanks, but that won't do it. If the record already has a non-null
value for application_id, :new.applicatio n id will contain that value.
For instance,

INSERT into MYTABLE VALUES ( 123, 456, 'foo');

UPDATE MYTABLE set MORE_STUFF = 'bar' WHERE ID = 123;

when the trigger fires, :new.applicatio n_id is equal to 456, even though
the update statement didn't include a value for it.

LKBrwn has the right idea, using the IF UPDATING('appli cation_id')
construct.

--
//-Walt
//
//
Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3002
by: Lorenzo Bolognini | last post by:
Hi all, i need to detect whether a field is required or not. I'm using this code for building a string to convert later to an array (by Split) of which each element matches the field index (ex. Field(myArray(0)): For Each Field in rst.Fields If Field.Attributes And adFldIsNullable Then Required = 0 'field is NOT required Else
16
8491
by: Georges Heinesch | last post by:
Hi. My form contains a control (cboFooBar), which has an underlying field with the "Required" property set to "Yes". Now, while filling out all the controls of the form, I have to fill out this particular (required) control as well. However further down the form, there is another control, which has to (under certain conditions) to delete again the content of the (required) control just filled out before (cboFooBar). This is done by...
2
39115
by: bufbec1 | last post by:
I am pretty good with Access, but do not understand VBA. I have researched this topic and see only VBA answers, so I hope someone can help with my specific question. I have 2 fields for an end-user that must be filled in. I want an error message for each field. The forms are already partially filled in, and a user needs to select which record to go to. There are fields for them to fill in their initials and date , along with other...
3
2939
by: Orchid | last post by:
Hello All, Hope someone can help me on my required field problems. I have a form base on a table for users to input new Employees. There are 4 fields that cannot be Null when entering new records. (but on the table, I have these 4 field set up as "Required = No"). I want the codes to be able to check if the 4 fields are null, if is null, tell the user to input the null field(s), after the user input the required field, then ask if...
2
3112
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i havnt tested the index yet ) so you can use an .UPDATE( dataTable ) on the data adapter. Otherwise you will get an exception error. Is this statement true? ---- Now me fumbling thru
5
4100
by: rdemyan via AccessMonster.com | last post by:
I have a need to add another field to all of my tables (over 150). Not data, but an actual field. Can I code this somehow. So the code presumabley would loop through all the tables, open each table in design mode and then add the new field and set its properties. Thanks. --
6
265
by: Walt | last post by:
It's easy to make a field required for inserts, just set it to not null and don't give it a default. But how does one make a field required for updates? For instance, we have a table with a field that keeps track of which application last updated the table MYTABLE ------ ID PK
5
1637
by: Cubicle Intern | last post by:
Hi, I have a form with multiple fields that confirmed before the form is submitted (ex. email field needs to be completed before the form can be submitted). Once the required fields are completed, I want a final warning box to appear asking the user "are you sure you want to make these changes?" I'm having trouble getting the function to work correctly. Here's the problem I've encountered: First Script: this one lets me enter an...
4
3119
by: PW | last post by:
Hi, I set up a relationship between two tables with the itineraryid fields in both tables: tblDailyItinerary tblDailyMeals I have a form that writes a record to tblDailyItinerary that updates the autonumber field itineraryid. I then bring up a subform which
0
9575
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9407
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10014
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9960
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9841
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8840
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7384
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5280
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3931
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.