Am using SQL server 2012 and am looking for conversion of Oracle statement having substitution variable:
UPDATE customers
SET region = '®ion'
WHERE state = '&state'
Someone please help me on this.
Am using SQL server 2012 and am looking for conversion of Oracle statement having substitution variable:
UPDATE customers
SET region = '®ion'
WHERE state = '&state'
Someone please help me on this.
It will be something like
Declare @State varchar(100)
Declare @Region varchar(100)
UPDATE customers
SET region = @Region
WHERE state = @State
I am by no means an Oracle expert but I think that substition variables are specific to SQL*PLUS and not the Oracle database.
SQL*PLUS
define region=West
define state=California
UPDATE customers
SET region = '®ion'
WHERE state = '&state'
My understanding is that SQL*PLUS will execute the following SQL:
UPDATE customers
SET region = 'West'
WHERE state = 'California'
The equivalent in MS SQL Server 2012 would be:
Declare @Region varchar(100)
Declare @State varchar(100)
Set @Region = 'West'
Set @State = 'California'
Update Customers
Set region = @Region
Where State = @State
Or you could lose the variables all together and simply use:
Update Customers
Set Region = 'West'
Where State = 'California'
EDIT:
Update only affect data that is currently in the table. If you add more data to the table at a later date you would need to run the update again.
e.g.
Adding more rows with a State
of "California" will not automatically set the Region
column to "West" for the inserted rows.
Also ensure that you are using the same data types (and lengths) for your variables that you have declared in your table structure.