{"id":74,"date":"2012-01-03T23:58:24","date_gmt":"2012-01-04T04:58:24","guid":{"rendered":"http:\/\/www.thefaberfamily.org\/search-smith\/?p=74"},"modified":"2012-01-03T23:58:24","modified_gmt":"2012-01-04T04:58:24","slug":"oracle-friendly-urls","status":"publish","type":"post","link":"http:\/\/www.thefaberfamily.org\/search-smith\/2012\/01\/oracle-friendly-urls\/","title":{"rendered":"Oracle: Friendly URLs"},"content":{"rendered":"<p>On the one hand, <a title=\"ColdFusion: Queries inside query loops\" href=\"http:\/\/www.thefaberfamily.org\/search-smith\/2012\/01\/coldfusion-queries-inside-query-loops\/\">we want to avoid hitting the database if we don&#8217;t have to<\/a>. On the other hand, if we can use built-in functions in our queries, this can be preferable to manipulating the data after it&#8217;s been returned from the database. For example, writing this:<\/p>\n<pre>SELECT emp_id, INITCAP(fname) AS fname, INITCAP(lname) AS lname\r\n  FROM emp<\/pre>\n<p>is certainly* better than writing this:<\/p>\n<pre>SELECT emp_id, fname, lname\r\n  FROM emp<\/pre>\n<p>and then using your development tool to capitalize the names after the data have already been returned (in CF it would look something like this: ucase(left(fname, 1)) &amp; lcase(mid(fname, 2, len(fname) &#8211; 1)) &#8211; clunky!!).<\/p>\n<p>*As long as your database queries need not be portable.<\/p>\n<p>A better example still would be the following:<\/p>\n<pre>SELECT emp_id, COALESCE(dept_id, 0) AS dept_id\r\n  FROM emp<\/pre>\n<p>instead of:<\/p>\n<pre>SELECT emp_id, dept_id\r\n  FROM emp<\/pre>\n<p>With the latter I have to check to see if dept_id is non-null before displaying, while with the former I can simply display as-is.<\/p>\n<p>What does this have to do with friendly URLs? Friendly as in SEO-friendly. The URL is very important in search engine optimization. Suppose we have a table of articles <a title=\"ColdFusion 9: Indexing custom fields in Solr\" href=\"http:\/\/www.thefaberfamily.org\/search-smith\/2011\/12\/coldfusion-9-indexing-custom-fields-in-solr\/\">as in a previous post<\/a>:<\/p>\n<pre>SELECT id, title, description, pubdate, journal_name, author_name, num_reads\r\n  FROM articles<\/pre>\n<p>We would like to have the article&#8217;s title in the URL. The conventional wisdom is to use hyphens (<code>-<\/code>) as word separators. We also don&#8217;t want any weird characters that are going to be url-encoded. The solution (or, at least, &#8220;a&#8221; solution) is to use regular expressions to get rid of unusual characters and replace spaces with hyphens. And here Oracle is truly our friend:<\/p>\n<pre>SELECT id, title, description, pubdate, journal_name, author_name, num_reads\r\n\u00a0\u00a0\u00a0\u00a0 , REGEXP_REPLACE(REGEXP_REPLACE(LOWER(title), '[^-a-z0-9\/ ]', ''), '[\/ ]', '-') AS url_keyword\r\n  FROM articles<\/pre>\n<p>The inner REGEXP_REPLACE replaces every character that is not (a) alphanumeric, (b) a space, or (c) a hyphen or forward slash with a null string. The outer one replaces forward slashes and spaces with hyphens. What is left over is bunches of alphanumeric characters (hopefully, <em>words<\/em>) separated by hyphens &#8211; in other words, an SEO-friendly URL string.<\/p>\n<div class=\"simple_likebuttons_container_small\">\r\n      <div class=\"simple_likebuttons_googleplus\">\r\n        <g:plusone size=\"medium\" count=\"false\" href=\"http:\/\/www.thefaberfamily.org\/search-smith\/2012\/01\/oracle-friendly-urls\/\"><\/g:plusone>\r\n      <\/div>\r\n    \r\n      <div class=\"simple_likebuttons_twitter simple_likebuttons_twitter_s\">\r\n        <a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-count=\"none\" data-url=\"http:\/\/www.thefaberfamily.org\/search-smith\/2012\/01\/oracle-friendly-urls\/\" data-lang=\"en\">Tweet<\/a>\r\n      <\/div>\r\n    \r\n      <div class=\"simple_likebuttons_facebook\">\r\n        <div id=\"fb-root\"><\/div>\r\n        <script>(function(d, s, id) {\r\n          var js, fjs = d.getElementsByTagName(s)[0];\r\n          if (d.getElementById(id)) {return;}\r\n          js = d.createElement(s); js.id = id;\r\n          js.src = \"\/\/connect.facebook.net\/en_US\/all.js#xfbml=1\";\r\n          fjs.parentNode.insertBefore(js, fjs);\r\n        }(document, \"script\", \"facebook-jssdk\"));<\/script>\r\n        <div class=\"fb-like\" data-href=\"http:\/\/www.thefaberfamily.org\/search-smith\/2012\/01\/oracle-friendly-urls\/\" data-send=\"false\" data-layout=\"button_count\" data-show-faces=\"false\" data-width=\"90\"><\/div>\r\n      <\/div>\r\n    <\/div>","protected":false},"excerpt":{"rendered":"<p>On the one hand, we want to avoid hitting the database if we don&#8217;t have to. On the other hand, if we can use built-in functions in our queries, this can be preferable to manipulating the data after it&#8217;s been returned from the database. For example, writing this: SELECT emp_id, INITCAP(fname) AS fname, INITCAP(lname) AS [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,10],"tags":[89,25,24,23,90],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-coldfusion","category-oracle","category-sql","tag-oracle","tag-regular-expressions","tag-search-engine-optimization","tag-seo","tag-sql"],"_links":{"self":[{"href":"http:\/\/www.thefaberfamily.org\/search-smith\/wp-json\/wp\/v2\/posts\/74","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.thefaberfamily.org\/search-smith\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.thefaberfamily.org\/search-smith\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.thefaberfamily.org\/search-smith\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.thefaberfamily.org\/search-smith\/wp-json\/wp\/v2\/comments?post=74"}],"version-history":[{"count":2,"href":"http:\/\/www.thefaberfamily.org\/search-smith\/wp-json\/wp\/v2\/posts\/74\/revisions"}],"predecessor-version":[{"id":76,"href":"http:\/\/www.thefaberfamily.org\/search-smith\/wp-json\/wp\/v2\/posts\/74\/revisions\/76"}],"wp:attachment":[{"href":"http:\/\/www.thefaberfamily.org\/search-smith\/wp-json\/wp\/v2\/media?parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.thefaberfamily.org\/search-smith\/wp-json\/wp\/v2\/categories?post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.thefaberfamily.org\/search-smith\/wp-json\/wp\/v2\/tags?post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}