script to update row with condition


I need a sciprt for oracle to update a column. The single entry only should updated if a condition is met.

A little bit more detailed:
If the last char is a ", the script should do nothing. If not " is the last char, it should add a " at the end of the text string. Then commit the changes and go to the next entry...

It would be nice if anybody can help me :)

Greets and best regards,

Who is Participating?
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.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
update yourtable
set yourcolumn = concat ( youcolumn , '"' )
where substr ( yourcolumn , length( yourcolumn) 1 ) <> '"'
There should be a comma between length and 1 and you may want to add is not null:

update yourtable
set yourcolumn = concat ( yourcolumn , '"' )
where yourcolumn IS NOT NULL
  AND substr ( yourcolumn , length( yourcolumn) ,1 ) <> '"'

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
johnsoneSenior Oracle DBACommented:
If the requirement is actually that each row must be committed individually, then a single statement will not suffice.  It would have to be PL/SQL, something like this:

  for c1rec in (select rowid from <tab> where <col> is not null and substr(<col>, length(<col>)) <> '"' ) loop
    update <tab>
      set <col> = <col> ||  '"'
      where rowid = c1rec.rowid;
  end loop;

Depending on the size of the table, you may run into ORA-01555.  If you do, you will have to code around it by closing and reopening the cursor every few thousand records.
SnodyAuthor Commented:
Thx @ both of you. I used the solution of geotiger but johnsone gave me an exact answer for my question. But i din't have to commit every row. I did it only once. But I'm sure johnsone's way would work too...

Greets and best Regards,
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.