Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is some test data:</p> <pre><code>SQL&gt; select * from MACAddresses 2 / COMPUTER MACADDRESS ---------- ------------ 100 123456789abc 200 acef35dd6ecc SQL&gt; </code></pre> <p>Adding the new column is quite straightforward:</p> <pre><code>SQL&gt; alter table MACAddresses 2 add corrected_MACAddress varchar2(17) 3 / Table altered. SQL&gt; </code></pre> <p>Note that you cannot make it NOT NULL at this point, because you already have some records in the table. So if you want to apply such a constraint, you need to populate it first. </p> <p>This is the simplest way of updating the new column. </p> <pre><code>SQL&gt; update MACAddresses 2 set corrected_MACAddress = substr(macaddress, 1,2)||':'|| 3 substr(macaddress, 3,2)||':'|| 4 substr(macaddress, 5,2)||':'|| 5 substr(macaddress, 7,2)||':'|| 6 substr(macaddress, 9,2)||':'|| 7 substr(macaddress, 11,2) 8 / 2 rows updated. SQL&gt; select * from MACAddresses 2 / COMPUTER MACADDRESS CORRECTED_MACADDR ---------- ------------ ----------------- 100 123456789abc 12:34:56:78:9a:bc 200 acef35dd6ecc ac:ef:35:dd:6e:cc SQL&gt; </code></pre> <p>Now, if you had a more complicated pattern, or if you wanted to perform this operation on a regukar basis I suggest you expend the effort to turn it into a function, and perhaps remove that repetition at the same time.</p> <p>Finally, if you wanted to enforce a mandatory constraint you can:</p> <pre><code>SQL&gt; alter table MACAddresses 2 modify corrected_MACAddress not null 3 / Table altered. SQL&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload