extracted s:nextval_exec function

This makes nextval more testable