 |
|
| Computers Forum Index » Computer - Databases - Oracle (Misc) » Using a case within a simple update... |
|
Page 1 of 1 |
|
| Author |
Message |
| Sashi... |
Posted: Thu Oct 15, 2009 3:21 pm |
|
|
|
Guest
|
Hi all, I'm trying to do something like this.
update myTable
case length(duration)
when 8 then set hours = substr(duration,1,2)
else set hours = substr(duration,1, 1)
end case
Depending on the length of the 'duration' field, I'm trying to extract
either the first or the first two characters.
It ain't workin'.
Is such a construct possible withing pl/sql? The few examples that
I've googled around give easy options for using it within a select but
no examples within an update.
Thanks,
Sashi |
|
|
| Back to top |
|
|
|
| Maxim Demenko... |
Posted: Thu Oct 15, 2009 7:28 pm |
|
|
|
Guest
|
Sashi wrote:
Quote: Hi all, I'm trying to do something like this.
update myTable
case length(duration)
when 8 then set hours = substr(duration,1,2)
else set hours = substr(duration,1, 1)
end case
Depending on the length of the 'duration' field, I'm trying to extract
either the first or the first two characters.
It ain't workin'.
Is such a construct possible withing pl/sql? The few examples that
I've googled around give easy options for using it within a select but
no examples within an update.
Thanks,
Sashi
update mytable set hours=case when length(duration)=8 then
substr(duration,1,2) else substr(duration,1,1) end
or shorter
update mytable set
hours=decode(length(duration),8,substr(duration,1,2),substr(duration,1,1))
(assuming you wish update all rows in your table)
Best regards
Maxim |
|
|
| Back to top |
|
|
|
| Sasikanth Malladi... |
Posted: Fri Oct 16, 2009 2:48 am |
|
|
|
Guest
|
On Oct 15, 11:28 am, Maxim Demenko <mdeme... at (no spam) gmail.com> wrote:
Quote:
update mytable set hours=case when length(duration)=8 then
substr(duration,1,2) else substr(duration,1,1) end
or shorter
update mytable set
hours=decode(length(duration),8,substr(duration,1,2),substr(duration,1,1))
(assuming you wish update all rows in your table)
Best regards
Maxim
Great! Thank you!
Sashi
Sashi |
|
|
| Back to top |
|
|
|
|
|
All times are GMT
The time now is Fri Dec 04, 2009 7:47 am
|
|