{"id":1023,"date":"2021-10-05T23:32:12","date_gmt":"2021-10-05T18:02:12","guid":{"rendered":"https:\/\/techieshouts.com\/home\/?p=1023"},"modified":"2022-08-09T19:02:55","modified_gmt":"2022-08-09T13:32:55","slug":"index-function-in-teradata","status":"publish","type":"post","link":"https:\/\/techieshouts.com\/home\/index-function-in-teradata\/","title":{"rendered":"INDEX function in Teradata"},"content":{"rendered":"\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Teradata\" target=\"_blank\" rel=\"noopener\">Teradata<\/a> has a variety of inbuilt functions to work with Strings. The INDEX function is one of the most commonly used functions in Teradata. It helps to identify the position of a character or string in the values.<\/p>\n\n\n\n<p>The INDEX function accepts two arguments. The first one is the string expression and the second one is the char or string for which you want to find the position. The output of the index function is an integer that gives the position of the string.<\/p>\n\n\n\n<h2>Syntax<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"classic\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">INDEX(string expression, string inside to find inside)<\/pre>\n\n\n\n<p>Let us understand this better with an example. <\/p>\n\n\n\n<p>Imagine a weblogs table that has the URL of the websites that are browsed from a user machine. In that, let&#8217;s say you want to find the position of the word &#8216;google&#8217; to know whether the URL is a google search.<\/p>\n\n\n\n<p>URL &#8211; &#8216;https:\/\/www.google.com&#8217;<\/p>\n\n\n\n<p>The following query will give you the position of the word &#8216;google&#8217;. And if the position is greater than zero, you can say that the word google is present in the string.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"classic\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT INDEX('https:\/\/www.google.com', 'google') as pos;<\/pre>\n\n\n\n<h3>Output<\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"398\" src=\"https:\/\/techieshouts.com\/wp-content\/uploads\/2021\/10\/image-7-1024x398.png\" alt=\"\" class=\"wp-image-1024\" srcset=\"https:\/\/techieshouts.com\/wp-content\/uploads\/2021\/10\/image-7-1024x398.png 1024w, https:\/\/techieshouts.com\/wp-content\/uploads\/2021\/10\/image-7-300x117.png 300w, https:\/\/techieshouts.com\/wp-content\/uploads\/2021\/10\/image-7-768x299.png 768w, https:\/\/techieshouts.com\/wp-content\/uploads\/2021\/10\/image-7-660x257.png 660w, https:\/\/techieshouts.com\/wp-content\/uploads\/2021\/10\/image-7.png 1034w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Let us see another example in which the index function returns zero<\/p>\n\n\n\n<p>URL &#8211; &#8216;https:\/\/www.gmail.com&#8217;<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"classic\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT INDEX('https:\/\/www.gmail.com', 'google') as pos;<\/pre>\n\n\n\n<h3>Output<\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"398\" src=\"https:\/\/techieshouts.com\/wp-content\/uploads\/2021\/10\/image-8-1024x398.png\" alt=\"\" class=\"wp-image-1025\" srcset=\"https:\/\/techieshouts.com\/wp-content\/uploads\/2021\/10\/image-8-1024x398.png 1024w, https:\/\/techieshouts.com\/wp-content\/uploads\/2021\/10\/image-8-300x117.png 300w, https:\/\/techieshouts.com\/wp-content\/uploads\/2021\/10\/image-8-768x299.png 768w, https:\/\/techieshouts.com\/wp-content\/uploads\/2021\/10\/image-8-660x257.png 660w, https:\/\/techieshouts.com\/wp-content\/uploads\/2021\/10\/image-8.png 1034w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>In the above example, you can see that the word google is not present in the string expression. As a result, the INDEX function returned zero as the position of the word google. This confirms that the word google is not there in the input string.<\/p>\n\n\n\n<p>Also read,<\/p>\n\n\n\n<ol><li><a href=\"https:\/\/techieshouts.com\/home\/concatenation-of-columns-values-in-teradata\/\">Concatenation of values in Teradata<\/a><\/li><li><a href=\"https:\/\/techieshouts.com\/home\/substring-in-teradata\/\">Substring function in Teradata<\/a><\/li><li><a href=\"https:\/\/techieshouts.com\/home\/teradata-get-current-date-and-time\/\">Get Current Date and Time in Teradata<\/a><\/li><li><a href=\"https:\/\/techieshouts.com\/home\/teradata-get-logged-in-user-details\/\">Fetching logged in user details<\/a><\/li><\/ol>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Teradata has a variety of inbuilt functions to work with Strings. The INDEX function is one of the most commonly used functions in Teradata. It helps to identify the position of a character or string in the values. The INDEX function accepts two arguments. The first one is the string expression and the second one\u2026 <span class=\"read-more\"><a href=\"https:\/\/techieshouts.com\/home\/index-function-in-teradata\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[184,183,212,182,213],"_links":{"self":[{"href":"https:\/\/techieshouts.com\/home\/wp-json\/wp\/v2\/posts\/1023"}],"collection":[{"href":"https:\/\/techieshouts.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techieshouts.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techieshouts.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techieshouts.com\/home\/wp-json\/wp\/v2\/comments?post=1023"}],"version-history":[{"count":2,"href":"https:\/\/techieshouts.com\/home\/wp-json\/wp\/v2\/posts\/1023\/revisions"}],"predecessor-version":[{"id":1028,"href":"https:\/\/techieshouts.com\/home\/wp-json\/wp\/v2\/posts\/1023\/revisions\/1028"}],"wp:attachment":[{"href":"https:\/\/techieshouts.com\/home\/wp-json\/wp\/v2\/media?parent=1023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techieshouts.com\/home\/wp-json\/wp\/v2\/categories?post=1023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techieshouts.com\/home\/wp-json\/wp\/v2\/tags?post=1023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}