{"id":79,"date":"2007-07-17T12:39:01","date_gmt":"2007-07-17T19:39:01","guid":{"rendered":"http:\/\/jeffhobbs.net\/2007\/07\/17\/some-sql-for-the-day\/"},"modified":"2007-07-17T12:39:01","modified_gmt":"2007-07-17T19:39:01","slug":"some-sql-for-the-day","status":"publish","type":"post","link":"https:\/\/jeffhobbs.com\/?p=79","title":{"rendered":"Some SQL for the Day"},"content":{"rendered":"<p>Received a parcel attribute data dump for an outside party today. Needed to clean it up so it matched my internal data. There were a few issues: <\/p>\n<p>1) The parcels in the dump did not have dashes in the APN Number.<\/p>\n<p>2) The address number was padded with leading zeros.  <\/p>\n<p>Used some SQL to clean up both data differences. Thought I&#8217;d pass it long in case others run into similar problems or have similar requirements. I should note that all of the processing was done inside of the Oracle database via SQL*Plus.<\/p>\n<p>1) I figured instead of adding dashes to the dump, I write a view and in the view I&#8217;d remove the dashes from my data. Made life much easier. Instead of showing the view syntax, I&#8217;ll put the code into a simple update statement:<\/p>\n<p>UPDATE parcel<br \/>\nSET apn_number = REPLACE (apn_number, &#8216;-&#8216;, &#8221;);<\/p>\n<p>With the REPLACE function I&#8217;m telling Oracle to do the following:<\/p>\n<ul>\n<li>Look at my apn_number column<\/li>\n<li>Find all of the dashes in the column<\/li>\n<li>Replace the dashes with&#160; &quot;nothing&quot; or two single quotes (&#8221;)<\/li>\n<\/ul>\n<p>Fairly straightforward and very fast (and useful).<\/p>\n<p>2) To eliminate the leading zeros I used the TRIM function. Here&#8217;s the update syntax:<\/p>\n<p>UPDATE parcel<br \/>\nSET street_number = TRIM(LEADING 0 FROM my_street_number)<\/p>\n<p>With the TRIM function I&#8217;m telling Oracle to do the following:<\/p>\n<ul>\n<li>Look at the start (lead) of the my_street_number column<\/li>\n<li>Find all of the zeroes (0s) at the start of the column <\/li>\n<li>Remove all of the leading zeroes until you get to a non-zero number, then stop the process <\/li>\n<\/ul>\n<p>In the end, neither SQL statement is complex, but both are very useful. It&#8217;s also interesting to note that both statement took under 30 seconds to perform. Very nice considering that there were approximately 250,000 records in both tables. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Received a parcel attribute data dump for an outside party today. Needed to clean it up so it matched my&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[11],"tags":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Some SQL for the Day - jeffhobbs.com<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jeffhobbs.com\/?p=79\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Some SQL for the Day - jeffhobbs.com\" \/>\n<meta property=\"og:description\" content=\"Received a parcel attribute data dump for an outside party today. Needed to clean it up so it matched my...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jeffhobbs.com\/?p=79\" \/>\n<meta property=\"og:site_name\" content=\"jeffhobbs.com\" \/>\n<meta property=\"article:published_time\" content=\"2007-07-17T19:39:01+00:00\" \/>\n<meta name=\"author\" content=\"Jeff Hobbs\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeff Hobbs\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jeffhobbs.com\/?p=79\",\"url\":\"https:\/\/jeffhobbs.com\/?p=79\",\"name\":\"Some SQL for the Day - jeffhobbs.com\",\"isPartOf\":{\"@id\":\"https:\/\/jeffhobbs.com\/#website\"},\"datePublished\":\"2007-07-17T19:39:01+00:00\",\"dateModified\":\"2007-07-17T19:39:01+00:00\",\"author\":{\"@id\":\"https:\/\/jeffhobbs.com\/#\/schema\/person\/600c6cc6bd115876f071a9bfb5c934d7\"},\"breadcrumb\":{\"@id\":\"https:\/\/jeffhobbs.com\/?p=79#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jeffhobbs.com\/?p=79\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jeffhobbs.com\/?p=79#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jeffhobbs.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Some SQL for the Day\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jeffhobbs.com\/#website\",\"url\":\"https:\/\/jeffhobbs.com\/\",\"name\":\"jeffhobbs.com\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jeffhobbs.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/jeffhobbs.com\/#\/schema\/person\/600c6cc6bd115876f071a9bfb5c934d7\",\"name\":\"Jeff Hobbs\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jeffhobbs.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/bafb9a6abd79509b50a190d399dea779?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/bafb9a6abd79509b50a190d399dea779?s=96&d=mm&r=g\",\"caption\":\"Jeff Hobbs\"},\"sameAs\":[\"http:\/\/jeffhobbs.com\"],\"url\":\"https:\/\/jeffhobbs.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Some SQL for the Day - jeffhobbs.com","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jeffhobbs.com\/?p=79","og_locale":"en_US","og_type":"article","og_title":"Some SQL for the Day - jeffhobbs.com","og_description":"Received a parcel attribute data dump for an outside party today. Needed to clean it up so it matched my...","og_url":"https:\/\/jeffhobbs.com\/?p=79","og_site_name":"jeffhobbs.com","article_published_time":"2007-07-17T19:39:01+00:00","author":"Jeff Hobbs","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Jeff Hobbs","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/jeffhobbs.com\/?p=79","url":"https:\/\/jeffhobbs.com\/?p=79","name":"Some SQL for the Day - jeffhobbs.com","isPartOf":{"@id":"https:\/\/jeffhobbs.com\/#website"},"datePublished":"2007-07-17T19:39:01+00:00","dateModified":"2007-07-17T19:39:01+00:00","author":{"@id":"https:\/\/jeffhobbs.com\/#\/schema\/person\/600c6cc6bd115876f071a9bfb5c934d7"},"breadcrumb":{"@id":"https:\/\/jeffhobbs.com\/?p=79#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jeffhobbs.com\/?p=79"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jeffhobbs.com\/?p=79#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jeffhobbs.com\/"},{"@type":"ListItem","position":2,"name":"Some SQL for the Day"}]},{"@type":"WebSite","@id":"https:\/\/jeffhobbs.com\/#website","url":"https:\/\/jeffhobbs.com\/","name":"jeffhobbs.com","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jeffhobbs.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/jeffhobbs.com\/#\/schema\/person\/600c6cc6bd115876f071a9bfb5c934d7","name":"Jeff Hobbs","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jeffhobbs.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/bafb9a6abd79509b50a190d399dea779?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/bafb9a6abd79509b50a190d399dea779?s=96&d=mm&r=g","caption":"Jeff Hobbs"},"sameAs":["http:\/\/jeffhobbs.com"],"url":"https:\/\/jeffhobbs.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/jeffhobbs.com\/index.php?rest_route=\/wp\/v2\/posts\/79"}],"collection":[{"href":"https:\/\/jeffhobbs.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jeffhobbs.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jeffhobbs.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jeffhobbs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=79"}],"version-history":[{"count":0,"href":"https:\/\/jeffhobbs.com\/index.php?rest_route=\/wp\/v2\/posts\/79\/revisions"}],"wp:attachment":[{"href":"https:\/\/jeffhobbs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jeffhobbs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jeffhobbs.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}