Difference between revisions of "Update Command"

From rbachwiki
Jump to navigation Jump to search
(Created page with "= Update Command = ''' Used to change the contents of existing rows ''' * The UPDATE clause identifies the table containing the records to be changed. * The SET clause ident...")
 
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:
''' Used to change the contents of existing rows  '''
''' Used to change the contents of existing rows  '''
* The UPDATE clause identifies the table containing the records to be changed.
* The UPDATE clause identifies the table containing the records to be changed.
* The SET clause identifies the columns to be changed and the new values to
* The SET clause identifies the columns to be changed and the new values to be assigned to these columns.
be assigned to these columns.
* The optional WHERE clause identifies the exact records to be changed by the UPDATE command. If the WHERE clause is omitted, the column specified in the SET clause is updated for all records in the table.
* The optional WHERE clause identifies the exact records to be changed by the
 
UPDATE command. If the WHERE clause is omitted, the column specified in
UPDATE acctmanager
the SET clause is updated for all records in the table.
SET amedate = '01-AUG-09'
WHERE amid = 'J500';
 
== Change multiple records that match a criteria ==
''' All records that have NE and NW will be changed to W'''
UPDATE acctmanager
SET region = 'W'
WHERE region IN ('NE', 'NW')
 
== Update Multiple Columns ===
UPDATE acctmanager
SET amedate = '10-OCT-09',
    region = 'S'
WHERE amid = 'J500'
 
== Using Substituion Variables ==
'''A substitution variable in an SQL command instructs Oracle 11g to substitute a value in place of the variable at the time the command is actually executed. To include a substitution variable in an SQL command, simply enter an ampersand (&) followed by the name used for the variable.'''
 
UPDATE customers
SET region = '&Region'
WHERE state ='&State';
 
''' This will pop up a dialog box prompting you to enter the Region and State'''


[[#Select Command|Back To Top]]-[[Main_Page| Home]] - [[Oracle_SQL|Category]]
[[#Select Command|Back To Top]]-[[Main_Page| Home]] - [[Oracle_SQL|Category]]

Latest revision as of 19:59, 18 October 2017

Update Command

Used to change the contents of existing rows

  • The UPDATE clause identifies the table containing the records to be changed.
  • The SET clause identifies the columns to be changed and the new values to be assigned to these columns.
  • The optional WHERE clause identifies the exact records to be changed by the UPDATE command. If the WHERE clause is omitted, the column specified in the SET clause is updated for all records in the table.
UPDATE acctmanager
SET amedate = '01-AUG-09'
WHERE amid = 'J500';

Change multiple records that match a criteria

All records that have NE and NW will be changed to W

UPDATE acctmanager 
SET region = 'W'
WHERE region IN ('NE', 'NW')

Update Multiple Columns =

UPDATE acctmanager
SET amedate = '10-OCT-09',
    region = 'S'
WHERE amid = 'J500'

Using Substituion Variables

A substitution variable in an SQL command instructs Oracle 11g to substitute a value in place of the variable at the time the command is actually executed. To include a substitution variable in an SQL command, simply enter an ampersand (&) followed by the name used for the variable.

UPDATE customers
SET region = '&Region'
WHERE state ='&State';

This will pop up a dialog box prompting you to enter the Region and State

Back To Top- Home - Category