Probably the easiest way to do this is with leSearchHierarchy and leReplace - these are like the layout editor's Find/Replace command. However, since leReplace only does it one cellVIew at a time, you may be better off doing a recursive hierarchy traversal, visiting each cellView master once, and then doing the leSearchHierarchy and leReplace one cellView at a time. There are numerous examples on this forum of doing a recursive hierarchy traversal.
Here's the commands to change it one one level:
; note that the via name is a regular expression, so I am anchoring it to ensure it doesn't match any
; partial names
vias=leSearchHierarchy(cvId cvId~>bBox 0 "via" list(list("via definition" "==" "^M6_M51$")))
leReplace(cvId vias list(list("via definition" "==" "M5M6")))
I suggested this because changing a via from one via to another with the db functions is not easy - you have to delete and re-add.