<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hassan Abd Elrahman</title>
    <description>The latest articles on DEV Community by Hassan Abd Elrahman (@hassanabdo).</description>
    <link>https://dev.to/hassanabdo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F892313%2F215a9e41-4e5e-489a-8847-8e1317a9fad6.png</url>
      <title>DEV Community: Hassan Abd Elrahman</title>
      <link>https://dev.to/hassanabdo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hassanabdo"/>
    <language>en</language>
    <item>
      <title>Oracle TO_DATE Function - Complete Guide</title>
      <dc:creator>Hassan Abd Elrahman</dc:creator>
      <pubDate>Sat, 16 Jul 2022 00:03:52 +0000</pubDate>
      <link>https://dev.to/hassanabdo/oracle-todate-function-complete-guide-36b4</link>
      <guid>https://dev.to/hassanabdo/oracle-todate-function-complete-guide-36b4</guid>
      <description>&lt;p&gt;In this tutorial, we are going to explain how to use Oracle TO_DATE function with basic syntax and many examples for better understanding.&lt;/p&gt;

&lt;p&gt;How to convert varchar to date in oracle? Oracle TO_DATE function is used to convert a character string that is one of the data types (CHAR, VARCHAR2, NCHAR, and NVARCHAR2) into a date format.&lt;br&gt;
Syntax:&lt;/p&gt;

&lt;p&gt;In this tutorial, we are going to explain how to use Oracle TO_DATE function with basic syntax and many examples for better understanding.&lt;/p&gt;

&lt;p&gt;How to convert varchar to date in oracle? Oracle TO_DATE function is used to convert a character string that is one of the data types (CHAR, VARCHAR2, NCHAR, and NVARCHAR2) into a date format.&lt;br&gt;
Syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TO_DATE(char, 'format_model', nls_language)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;char: The character that will be converted to a date&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;‘format_model’: a format that will be used to convert char to a date. If format_model is not specified, the format is DD-MON-YY., and It can be one or a combination of the following values: &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Oracle Date Format&lt;/p&gt;

&lt;p&gt;Using a date format mask, we can convert a character string to a particular date format if we use one or a combination of different masks like ‘DD/MM’ or ‘DD/MM/YYYY’ or ‘DD-MON’.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameter&lt;/th&gt;
&lt;th&gt;Explanation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;SCC or CC&lt;/td&gt;
&lt;td&gt;Century; server prefixes B.C. date with –&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Years in dates YYYY or SYYYY&lt;/td&gt;
&lt;td&gt;Year; server prefixes B.C. date              with –&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;YYY or YY or Y&lt;/td&gt;
&lt;td&gt;Last three, two, or one digit of the year&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Y,YYY&lt;/td&gt;
&lt;td&gt;The year with a comma in this position&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;IYYY, IYY, IY, I&lt;/td&gt;
&lt;td&gt;Four-, three-, two-, or one-digit years based on the ISO standard&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SYEAR or YEAR&lt;/td&gt;
&lt;td&gt;Year spelled out; server prefixes B.C. date with –&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Q&lt;/td&gt;
&lt;td&gt;Quarter of year&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MM&lt;/td&gt;
&lt;td&gt;Month: two-digit value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MONTH&lt;/td&gt;
&lt;td&gt;Name of month padded with blanks to length of nine characters&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MON&lt;/td&gt;
&lt;td&gt;Name of month, three-letter abbreviation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RM&lt;/td&gt;
&lt;td&gt;Roman numeral month&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WW or W&lt;/td&gt;
&lt;td&gt;Week of year or month&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DDD or DD or D&lt;/td&gt;
&lt;td&gt;Day of the year, month, or week&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DAY&lt;/td&gt;
&lt;td&gt;Name of day padded with blanks to a length of nine characters&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DY&lt;/td&gt;
&lt;td&gt;Name of the day; three-letter abbreviation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;J&lt;/td&gt;
&lt;td&gt;Julian day; the number of days since December 31, 4713 B.C.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RRRR&lt;/td&gt;
&lt;td&gt;Accepts a 2-digit year and returns a 4-digit year.A value between 0-49 will return a 20xx year. A value between 50-99 will return a 19xx year.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;HH&lt;/td&gt;
&lt;td&gt;Hour of day (1-12).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;HH12&lt;/td&gt;
&lt;td&gt;Hour of day (1-12).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;HH24&lt;/td&gt;
&lt;td&gt;Hour of day (0-23).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MI&lt;/td&gt;
&lt;td&gt;Minute (0-59).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SS&lt;/td&gt;
&lt;td&gt;Second (0-59).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SSSSS&lt;/td&gt;
&lt;td&gt;Seconds past midnight (0-86399).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AM, A.M., PM, or P.M.&lt;/td&gt;
&lt;td&gt;Meridian indicator&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;nls_language: it’s an expression that specifies the name of the day and month and what it looks like. it’s an optional parameter; Oracle TO_DATE function will use the default language for your session.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'NLS_DATE_LANGUAGE = American'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Oracle TO_DATE function with NLS_DATE_FORMAT :&lt;/p&gt;

&lt;p&gt;If the client sets the NLS_* parameters — they override the server in all cases. In fact, if the client sets the NLS_LANG parameter — that causes all&lt;br&gt;
NLS_* settings on the server to be ignored and the defaults for that NLS_LANG specified on the client on use. Source: Oracle&lt;/p&gt;

&lt;p&gt;If we need to show the date in a specific format like “yyyymmdd”, we have to set NLS_DATE_FORMAT on the session level after connecting.&lt;/p&gt;

&lt;p&gt;First, we can query the current value of NLS_DATE_FORMAT by executing this select statement :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT *
FROM   V$NLS_PARAMETERS
WHERE  PARAMETER = 'NLS_DATE_FORMAT';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result&lt;br&gt;
oracle to_date NLS_DATE_FORMAT-min&lt;/p&gt;

&lt;p&gt;After that, we need to set NLS_DATE_FORMAT by :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER SESSION SET NLS_DATE_FORMAT='DD-MM-YYYY';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Examples:
&lt;/h3&gt;

&lt;p&gt;Let’s take some examples about TO_DATE and how to use it:&lt;/p&gt;

&lt;h3&gt;
  
  
  Example (1):
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT to_date ('2019/03/01', 'yyyy/mm/dd')
FROM   dual;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DhyrKTUU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.oraask.com/wp-content/uploads/2019/03/Oracle-to_date-function-example-1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DhyrKTUU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.oraask.com/wp-content/uploads/2019/03/Oracle-to_date-function-example-1.jpg" alt="alt text" title="Example (1)" width="513" height="75"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Example (2):
&lt;/h3&gt;

&lt;p&gt;SELECT TO_DATE('030119', 'MMDDYY')&lt;br&gt;
FROM   dual;&lt;/p&gt;

&lt;p&gt;Result&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ao1RgDY7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.oraask.com/wp-content/uploads/2019/03/Oracle-to_date-function-example-2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ao1RgDY7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.oraask.com/wp-content/uploads/2019/03/Oracle-to_date-function-example-2.jpg" alt="alt text" title="Example (2)" width="410" height="76"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Similar oracle functions Like Oracle TO_DATE&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://www.oraask.com/wiki/oracle-to-char"&gt;TO_CHAR&lt;/a&gt; : Convert number and date to string.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://www.oraask.com/wiki/oracle-to-number"&gt;TO_NUMBER&lt;/a&gt; : Converts a value to a NUMBER type&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;In this tutorial, you have learned how to use the Oracle TO_DATE function to convert a character string to a date format by giving 4+ different examples for better understanding.
Hopefully, it was clear and concise. 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>sql</category>
      <category>database</category>
      <category>oracle</category>
      <category>programming</category>
    </item>
    <item>
      <title>Run Oracle SQL Script From Command Line in Windows</title>
      <dc:creator>Hassan Abd Elrahman</dc:creator>
      <pubDate>Fri, 15 Jul 2022 06:57:52 +0000</pubDate>
      <link>https://dev.to/hassanabdo/run-oracle-sql-script-from-command-line-in-windows-4369</link>
      <guid>https://dev.to/hassanabdo/run-oracle-sql-script-from-command-line-in-windows-4369</guid>
      <description>&lt;p&gt;Sometimes we need to run a particular SQL script from the Windows command line “CMD” with or without parameters.&lt;/p&gt;

&lt;p&gt;This article will guide you through the steps required to perform&lt;br&gt;
this task to get an employee’s information — both with and without&lt;br&gt;
parameters.&lt;br&gt;
To Run SQL Scripts from Windows Command Line CMD &lt;/p&gt;

&lt;p&gt;Press Windows + R from your keyboard, then type cmd and press enter.&lt;/p&gt;

&lt;p&gt;Change the current directory to the directory where your script is available.&lt;/p&gt;

&lt;p&gt;To run SQL Script without parameters, we need to type this command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sqlplus hr/hr @ScriptWithoutParameter.sql&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To run SQL Script with parameters, we need to type this command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sqlplus hr/hr @ScriptWithoutParameter.sql 101&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It is important that when running SQL script with parameters from CMD:&lt;/p&gt;

&lt;p&gt;In our script, the WHERE condition should be typed in the substitution variable as follows&lt;/p&gt;

&lt;p&gt;&lt;code&gt;select * from EMPLOYEES where employee_id = &amp;amp;1;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For the script above, we passed &amp;amp;1 to be replaced with 101 to bring employee number 101's data.&lt;/p&gt;

&lt;p&gt;To Run SQL Script from SQL PLUS&lt;/p&gt;

&lt;p&gt;Open SQL PLUS and then connect to the database.&lt;br&gt;
In SQL Command, type the following command and press enter&lt;/p&gt;

&lt;p&gt;&lt;code&gt;:\MyScript\ScriptWithoutParameter.sql&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This Article created initially on &lt;a href="https://www.oraask.com/2021/03/run-oracle-sql-script-from-windows-command-line.html"&gt;Oraask.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>sql</category>
    </item>
  </channel>
</rss>
