{"id":9,"date":"2006-01-05T15:44:16","date_gmt":"2006-01-05T14:44:16","guid":{"rendered":"http:\/\/bar-solutions.com\/wordpress\/2006\/01\/05\/column-order\/"},"modified":"2006-01-05T15:44:16","modified_gmt":"2006-01-05T14:44:16","slug":"column-order","status":"publish","type":"post","link":"https:\/\/blog.bar-solutions.com\/?p=9","title":{"rendered":"Column order"},"content":{"rendered":"<p>Yesterday I came across a rather strange problem, which was luckily relatively easily solved. The problem is like this: I am using QDA (Qnxo Development Architecture) packages\u00a0to get to the data in my tables. In the Query Package there is a function to retrieve a row from the table. I had generated this code and it works correct for my situation and this will work on my development database. But, the order of the columns in the production database happened to be different. As different as just one column in another position.<\/p>\n<p>Consider the emp table on my development database:<\/p>\n<p><font color=\"#0000f0\" size=\"1\">SQL<\/font><font color=\"#ff0000\" size=\"1\">><\/font><font size=\"1\"> <\/font><font color=\"#0000f0\" size=\"1\">desc<\/font><font size=\"1\"> emp<br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">Name<\/font><font size=\"1\"> <\/font><font color=\"#0000f0\" size=\"1\">Type<\/font><font size=\"1\"><br \/>\n<\/font><em><font color=\"#339960\" size=\"1\">&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;<\/font><\/em><font size=\"1\"><br \/>\nEMPNO <\/font><font color=\"#0000f0\" size=\"1\">NUMBER<\/font><font color=\"#ff0000\" size=\"1\">(4)<\/font><font size=\"1\"><br \/>\nENAME <\/font><font color=\"#0000f0\" size=\"1\">VARCHAR2<\/font><font color=\"#ff0000\" size=\"1\">(10)<\/font><font size=\"1\"><br \/>\nJOB <\/font><font color=\"#0000f0\" size=\"1\">VARCHAR2<\/font><font color=\"#ff0000\" size=\"1\">(9)<\/font><font size=\"1\"><br \/>\nMGR <\/font><font color=\"#0000f0\" size=\"1\">NUMBER<\/font><font color=\"#ff0000\" size=\"1\">(4)<\/font><font size=\"1\"><br \/>\nHIREDATE <\/font><font color=\"#0000f0\" size=\"1\">DATE<\/font><font size=\"1\"><br \/>\nSAL <\/font><font color=\"#0000f0\" size=\"1\">NUMBER<\/font><font color=\"#ff0000\" size=\"1\">(7,2)<\/font><font size=\"1\"><br \/>\nCOMM <\/font><font color=\"#0000f0\" size=\"1\">NUMBER<\/font><font color=\"#ff0000\" size=\"1\">(7,2)<\/font><font size=\"1\"><br \/>\nDEPTNO <\/font><font color=\"#0000f0\" size=\"1\">NUMBER<\/font><font color=\"#ff0000\" size=\"1\">(2)<\/font><\/p>\n<p>The query code generated for this table is like this:<\/p>\n<p><font color=\"#0000f0\" size=\"1\">FUNCTION<\/font><font size=\"1\"> onerow <\/font><font color=\"#ff0000\" size=\"1\">(<\/font><font size=\"1\">empno_in <\/font><font color=\"#0000f0\" size=\"1\">IN<\/font><font size=\"1\"> EMP_TP.EMPNO_t<\/font><font color=\"#ff0000\" size=\"1\">)<\/font><font size=\"1\"><br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">RETURN<\/font><font size=\"1\"> EMP_TP.EMP_rt<br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">IS<\/font><font size=\"1\"><br \/>\n\u00a0 onerow_rec EMP_TP.EMP_rt<\/font><font color=\"#ff0000\" size=\"1\">;<\/font><font size=\"1\"><br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">BEGIN<\/font><font size=\"1\"><br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">\u00a0 SELECT <\/font><font size=\"1\">EMPNO<\/font><font color=\"#ff0000\" size=\"1\">, <\/font><font size=\"1\">ENAME<\/font><font color=\"#ff0000\" size=\"1\">, <\/font><font size=\"1\">JOB<\/font><font color=\"#ff0000\" size=\"1\">, <\/font><font size=\"1\">MGR<\/font><font color=\"#ff0000\" size=\"1\">, <\/font><font size=\"1\">HIREDATE<\/font><font color=\"#ff0000\" size=\"1\">, <\/font><font size=\"1\">SAL<\/font><font color=\"#ff0000\" size=\"1\">, <\/font><font size=\"1\">COMM<\/font><font color=\"#ff0000\" size=\"1\">, <\/font><font size=\"1\">DEPTNO<br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">\u00a0\u00a0\u00a0 INTO<\/font><font size=\"1\"> onerow_rec<br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">\u00a0 \u00a0 FROM<\/font><font size=\"1\"> EMP<br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">\u00a0 WHERE <\/font><font size=\"1\">EMPNO <\/font><font color=\"#ff0000\" size=\"1\">=<\/font><font size=\"1\"> empno_in<\/font><font color=\"#ff0000\" size=\"1\">;<\/font><font size=\"1\"><br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">\u00a0 RETURN<\/font><font size=\"1\"> onerow_rec<\/font><font color=\"#ff0000\" size=\"1\">;<\/font><font size=\"1\"><br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">EXCEPTION<\/font><font size=\"1\"><br \/>\n&#8230;<br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">END<\/font><font size=\"1\"> onerow<\/font><font color=\"#ff0000\" size=\"1\">;<\/font><font size=\"1\"><br \/>\n<\/font><\/p>\n<p>Now, on the production database, the table layout is a little bit different, for example, the hiredate was added to the table later, so the emp table has the following layout:<\/p>\n<p><font color=\"#0000f0\" size=\"1\">SQL<\/font><font color=\"#ff0000\" size=\"1\">><\/font><font size=\"1\"> <\/font><font color=\"#0000f0\" size=\"1\">desc<\/font><font size=\"1\"> emp<br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">Name<\/font><font size=\"1\"> <\/font><font color=\"#0000f0\" size=\"1\">Type<\/font><font size=\"1\"><br \/>\n<\/font><em><font color=\"#339960\" size=\"1\">&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;<\/font><\/em><font size=\"1\"><br \/>\nEMPNO <\/font><font color=\"#0000f0\" size=\"1\">NUMBER<\/font><font color=\"#ff0000\" size=\"1\">(4)<\/font><font size=\"1\"><br \/>\nENAME <\/font><font color=\"#0000f0\" size=\"1\">VARCHAR2<\/font><font color=\"#ff0000\" size=\"1\">(10)<\/font><font size=\"1\"><br \/>\nJOB <\/font><font color=\"#0000f0\" size=\"1\">VARCHAR2<\/font><font color=\"#ff0000\" size=\"1\">(9)<\/font><font size=\"1\"><br \/>\nMGR <\/font><font color=\"#0000f0\" size=\"1\">NUMBER<\/font><font color=\"#ff0000\" size=\"1\">(4)<\/font><font size=\"1\"><br \/>\nSAL <\/font><font color=\"#0000f0\" size=\"1\">NUMBER<\/font><font color=\"#ff0000\" size=\"1\">(7,2)<\/font><font size=\"1\"><br \/>\nCOMM <\/font><font color=\"#0000f0\" size=\"1\">NUMBER<\/font><font color=\"#ff0000\" size=\"1\">(7,2)<\/font><font size=\"1\"><br \/>\nDEPTNO <\/font><font color=\"#0000f0\" size=\"1\">NUMBER<\/font><font color=\"#ff0000\" size=\"1\">(2)<\/font><font size=\"1\"><br \/>\nHIREDATE <\/font><font color=\"#0000f0\" size=\"1\">DATE<\/font><font size=\"1\"><br \/>\n<\/font><\/p>\n<p>If we select the fields in the first order and then try to get them into a record, based on the %rowtype of the table, then this fails.<\/p>\n<p>The easy solution is, instead of using the column names in the select statement, use <strong>select *<\/strong> in the select statement. This results in a resultset where the columns have the same order as the order in the %rowtype based record.<\/p>\n<p><font color=\"#0000f0\" size=\"1\">FUNCTION<\/font><font size=\"1\"> onerow <\/font><font color=\"#ff0000\" size=\"1\">(<\/font><font size=\"1\">empno_in <\/font><font color=\"#0000f0\" size=\"1\">IN<\/font><font size=\"1\"> EMP_TP.EMPNO_t<\/font><font color=\"#ff0000\" size=\"1\">)<\/font><font size=\"1\"><br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">RETURN<\/font><font size=\"1\"> EMP_TP.EMP_rt<br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">IS<\/font><font size=\"1\"><br \/>\n\u00a0 onerow_rec EMP_TP.EMP_rt<\/font><font color=\"#ff0000\" size=\"1\">;<\/font><font size=\"1\"><br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">BEGIN<\/font><font size=\"1\"><br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">\u00a0 SELECT\u00a0<\/font><font size=\"1\">*<\/font><font size=\"1\"><br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">\u00a0\u00a0\u00a0 INTO<\/font><font size=\"1\"> onerow_rec<br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">\u00a0 \u00a0 FROM<\/font><font size=\"1\"> EMP<br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">\u00a0 WHERE <\/font><font size=\"1\">EMPNO <\/font><font color=\"#ff0000\" size=\"1\">=<\/font><font size=\"1\"> empno_in<\/font><font color=\"#ff0000\" size=\"1\">;<\/font><font size=\"1\"><br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">\u00a0 RETURN<\/font><font size=\"1\"> onerow_rec<\/font><font color=\"#ff0000\" size=\"1\">;<\/font><font size=\"1\"><br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">EXCEPTION<\/font><font size=\"1\"><br \/>\n&#8230;<br \/>\n<\/font><font color=\"#0000f0\" size=\"1\">END<\/font><font size=\"1\"> onerow<\/font><font color=\"#ff0000\" size=\"1\">;<\/font><\/p>\n<p>Luckily this is a parameter in <a title=\"Qnxo: Quality In, Excellence Out\" href=\"http:\/\/qnxo.com\" target=\"_blank\">Qnxo<\/a> which can easily be set to a different default value.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday I came across a rather strange problem, which was luckily relatively easily solved. The problem is like this: I am using QDA (Qnxo Development Architecture) packages\u00a0to get to the data in my tables. In the Query Package there is a function to retrieve a row from the table. I had generated this code and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5,8],"tags":[],"class_list":["post-9","post","type-post","status-publish","format-standard","hentry","category-oracle","category-plsql","category-qnxo"],"_links":{"self":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/posts\/9","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9"}],"version-history":[{"count":0,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/posts\/9\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}