Hello,
Shell programming is not really designed for the level of sophistication that is indicated in your post.
Awk and Gawk offer some database manipulation abilities from within the Unix shell, but for connectivity to ODBC compliant databases, I believe you are going to have to stay within the 3GL or 4GL programming language universe, e.g. BBx, Progress, Access, FoxPro, etc.