{"id":865,"date":"2014-10-01T13:01:43","date_gmt":"2014-10-01T16:01:43","guid":{"rendered":"http:\/\/www.dbarj.com.br\/?p=865"},"modified":"2014-10-01T13:01:43","modified_gmt":"2014-10-01T16:01:43","slug":"restricting-oracle-username-pattern-using-trigger","status":"publish","type":"post","link":"https:\/\/www.dbarj.com.br\/en\/2014\/10\/restricting-oracle-username-pattern-using-trigger\/","title":{"rendered":"Restricting oracle Username using Trigger"},"content":{"rendered":"<p>One of the important tasks that the DBA has is to keep organized and controlled the schemas that exist in the database. Some companies have a standard nomenclature for its employees and service providers usernames and to avoid the creation of wrong logins, you can make a process to force an username pattern.<\/p>\n<p>To accomplish this, the DBA can create a system trigger that will check if the username follows the naming rule. See the Example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"oracledb\">CREATE OR REPLACE TRIGGER TRG_FILTRA_USER\r\n  BEFORE CREATE ON DATABASE\r\nBEGIN\r\n  IF ORA_DICT_OBJ_TYPE = 'USER' AND ORA_LOGIN_USER &lt;&gt; 'SYS'\r\n  THEN\r\n    IF NOT REGEXP_LIKE(ORA_DICT_OBJ_NAME, '^(T|F)\\d{7}?$')\r\n    THEN\r\n      RAISE_APPLICATION_ERROR(-20999, 'User must be on \"FNNNNNNN\" or \"TNNNNNNN\" format.');\r\n    END IF;\r\n  END IF;\r\nEND TRG_FILTRA_USER;\r\n\/<\/pre>\n<p>In this scenario, we are creating a trigger that all logged users (except SYS) can only create usernames starting with &#8220;<strong>T<\/strong>&#8221; or &#8220;<strong>F<\/strong>&#8221; followed by <strong>7 digits<\/strong>.<\/p>\n<p>It is always triggered before a &#8220;<strong>create<\/strong>&#8221; command, but in conjunction with the filter &#8220;ora_dict_obj_type&#8221; we restrict to the specific creation of users. There are other variables that we can use inside a DDL trigger to further reduce the scope of execution, such as:<\/p>\n<ul>\n<li><strong>ora_sysevent<\/strong> &#8211; The system event that was fired. In the example, the value is &#8220;CREATE&#8221;. Is usually what comes after the &#8220;AFTER&#8221; or &#8220;BEFORE&#8221; clause at the beginning of the trigger.<\/li>\n<li><strong>ora_login_user<\/strong> &#8211; The logged-in user who executed the command.<\/li>\n<li><strong>ora_instance_num<\/strong> &#8211; In case of a RAC environment, the number of the instance where the command is being executed.<\/li>\n<li><strong>ora_database_name<\/strong> &#8211; The name says.<\/li>\n<li><strong>ora_dict_obj_type<\/strong> &#8211; The type of object that is being changed by the system event. May be, for example, a table, role, procedure or, as above, a user.<\/li>\n<li><strong>ora_dict_obj_name<\/strong> &#8211; The name of the object being changed by the DDL.<\/li>\n<li><strong>ora_dict_obj_owner<\/strong> &#8211; The owner of the object being changed by the DDL. It does not apply for &#8220;<span style=\"color: #3366ff;\"><strong>ora_sysevent=USER<\/strong><\/span>&#8220;, as the example trigger event demonstrated above.<\/li>\n<\/ul>\n<p>For more information about functions that can be used in DDL triggers, <a href=\"http:\/\/psoug.org\/reference\/system_events.html\">PSOUG<\/a> has a good listing.<\/p>\n<b>Have you enjoyed? Please leave a comment or give a \ud83d\udc4d!<\/b>\n<div class='watch-action'><div class='watch-position align-left'><div class='action-like'><a class='lbg-style2 like-865 jlk' href='javascript:void(0)' data-task='like' data-post_id='865' data-nonce='de4404f630' rel='nofollow'><img class='wti-pixel' src='https:\/\/www.dbarj.com.br\/wp-content\/plugins\/wti-like-post\/images\/pixel.gif' title='Like' \/><span class='lc-865 lc'>+7<\/span><\/a><\/div><\/div> <div class='status-865 status align-left'><\/div><\/div><div class='wti-clear'><\/div>","protected":false},"excerpt":{"rendered":"<p>One of the important tasks that the DBA has is to keep organized and controlled the schemas that exist in the database. Some companies have a standard nomenclature for its employees and service providers usernames and to avoid the creation of wrong logins, you can make a process to force an username pattern. To accomplish &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"https:\/\/www.dbarj.com.br\/en\/2014\/10\/restricting-oracle-username-pattern-using-trigger\/\">Continue reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-865","post","type-post","status-publish","format-standard","hentry","category-database-en","item-wrap"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Restricting oracle Username using Trigger - DBA - Rodrigo Jorge - Oracle Tips and Guides<\/title>\n<meta name=\"description\" content=\"How to define a pattern or the way that a user is created via triggers.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbarj.com.br\/en\/2014\/10\/restricting-oracle-username-pattern-using-trigger\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DBA RJ\" \/>\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\":\"Article\",\"@id\":\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/2014\\\/10\\\/restricting-oracle-username-pattern-using-trigger\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/2014\\\/10\\\/restricting-oracle-username-pattern-using-trigger\\\/\"},\"author\":{\"name\":\"DBA RJ\",\"@id\":\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/#\\\/schema\\\/person\\\/28a44ca3a6633fe4156ad1ea209d40a9\"},\"headline\":\"Restricting oracle Username using Trigger\",\"datePublished\":\"2014-10-01T16:01:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/2014\\\/10\\\/restricting-oracle-username-pattern-using-trigger\\\/\"},\"wordCount\":321,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/#\\\/schema\\\/person\\\/28a44ca3a6633fe4156ad1ea209d40a9\"},\"articleSection\":[\"Oracle Database General\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/2014\\\/10\\\/restricting-oracle-username-pattern-using-trigger\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/2014\\\/10\\\/restricting-oracle-username-pattern-using-trigger\\\/\",\"url\":\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/2014\\\/10\\\/restricting-oracle-username-pattern-using-trigger\\\/\",\"name\":\"Restricting oracle Username using Trigger - DBA - Rodrigo Jorge - Oracle Tips and Guides\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/#website\"},\"datePublished\":\"2014-10-01T16:01:43+00:00\",\"description\":\"How to define a pattern or the way that a user is created via triggers.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/2014\\\/10\\\/restricting-oracle-username-pattern-using-trigger\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/2014\\\/10\\\/restricting-oracle-username-pattern-using-trigger\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/2014\\\/10\\\/restricting-oracle-username-pattern-using-trigger\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Restricting oracle Username using Trigger\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/\",\"name\":\"DBA - Rodrigo Jorge - Oracle Tips and Guides\",\"description\":\"Blog about Databases, Security and High Availability\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/#\\\/schema\\\/person\\\/28a44ca3a6633fe4156ad1ea209d40a9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.dbarj.com.br\\\/en\\\/#\\\/schema\\\/person\\\/28a44ca3a6633fe4156ad1ea209d40a9\",\"name\":\"DBA RJ\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.dbarj.com.br\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/RodrigoJorgePOUG19.png\",\"url\":\"https:\\\/\\\/www.dbarj.com.br\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/RodrigoJorgePOUG19.png\",\"contentUrl\":\"https:\\\/\\\/www.dbarj.com.br\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/RodrigoJorgePOUG19.png\",\"width\":712,\"height\":712,\"caption\":\"DBA RJ\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.dbarj.com.br\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/RodrigoJorgePOUG19.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Restricting oracle Username using Trigger - DBA - Rodrigo Jorge - Oracle Tips and Guides","description":"How to define a pattern or the way that a user is created via triggers.","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:\/\/www.dbarj.com.br\/en\/2014\/10\/restricting-oracle-username-pattern-using-trigger\/","twitter_misc":{"Written by":"DBA RJ","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbarj.com.br\/en\/2014\/10\/restricting-oracle-username-pattern-using-trigger\/#article","isPartOf":{"@id":"https:\/\/www.dbarj.com.br\/en\/2014\/10\/restricting-oracle-username-pattern-using-trigger\/"},"author":{"name":"DBA RJ","@id":"https:\/\/www.dbarj.com.br\/en\/#\/schema\/person\/28a44ca3a6633fe4156ad1ea209d40a9"},"headline":"Restricting oracle Username using Trigger","datePublished":"2014-10-01T16:01:43+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbarj.com.br\/en\/2014\/10\/restricting-oracle-username-pattern-using-trigger\/"},"wordCount":321,"commentCount":0,"publisher":{"@id":"https:\/\/www.dbarj.com.br\/en\/#\/schema\/person\/28a44ca3a6633fe4156ad1ea209d40a9"},"articleSection":["Oracle Database General"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbarj.com.br\/en\/2014\/10\/restricting-oracle-username-pattern-using-trigger\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbarj.com.br\/en\/2014\/10\/restricting-oracle-username-pattern-using-trigger\/","url":"https:\/\/www.dbarj.com.br\/en\/2014\/10\/restricting-oracle-username-pattern-using-trigger\/","name":"Restricting oracle Username using Trigger - DBA - Rodrigo Jorge - Oracle Tips and Guides","isPartOf":{"@id":"https:\/\/www.dbarj.com.br\/en\/#website"},"datePublished":"2014-10-01T16:01:43+00:00","description":"How to define a pattern or the way that a user is created via triggers.","breadcrumb":{"@id":"https:\/\/www.dbarj.com.br\/en\/2014\/10\/restricting-oracle-username-pattern-using-trigger\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbarj.com.br\/en\/2014\/10\/restricting-oracle-username-pattern-using-trigger\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbarj.com.br\/en\/2014\/10\/restricting-oracle-username-pattern-using-trigger\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.dbarj.com.br\/en\/"},{"@type":"ListItem","position":2,"name":"Restricting oracle Username using Trigger"}]},{"@type":"WebSite","@id":"https:\/\/www.dbarj.com.br\/en\/#website","url":"https:\/\/www.dbarj.com.br\/en\/","name":"DBA - Rodrigo Jorge - Oracle Tips and Guides","description":"Blog about Databases, Security and High Availability","publisher":{"@id":"https:\/\/www.dbarj.com.br\/en\/#\/schema\/person\/28a44ca3a6633fe4156ad1ea209d40a9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbarj.com.br\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.dbarj.com.br\/en\/#\/schema\/person\/28a44ca3a6633fe4156ad1ea209d40a9","name":"DBA RJ","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbarj.com.br\/wp-content\/uploads\/2019\/09\/RodrigoJorgePOUG19.png","url":"https:\/\/www.dbarj.com.br\/wp-content\/uploads\/2019\/09\/RodrigoJorgePOUG19.png","contentUrl":"https:\/\/www.dbarj.com.br\/wp-content\/uploads\/2019\/09\/RodrigoJorgePOUG19.png","width":712,"height":712,"caption":"DBA RJ"},"logo":{"@id":"https:\/\/www.dbarj.com.br\/wp-content\/uploads\/2019\/09\/RodrigoJorgePOUG19.png"}}]}},"_links":{"self":[{"href":"https:\/\/www.dbarj.com.br\/en\/wp-json\/wp\/v2\/posts\/865","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbarj.com.br\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbarj.com.br\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbarj.com.br\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbarj.com.br\/en\/wp-json\/wp\/v2\/comments?post=865"}],"version-history":[{"count":0,"href":"https:\/\/www.dbarj.com.br\/en\/wp-json\/wp\/v2\/posts\/865\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbarj.com.br\/en\/wp-json\/wp\/v2\/media?parent=865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbarj.com.br\/en\/wp-json\/wp\/v2\/categories?post=865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbarj.com.br\/en\/wp-json\/wp\/v2\/tags?post=865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}