Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1016115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:30:05+00:00 2026-05-16T10:30:05+00:00

I have a table TableName: MACAddresses Columns: – Computer – MACAddress I would like

  • 0

I have a table

TableName: MACAddresses
Columns:
- Computer
- MACAddress

I would like to create a sql script that creates a new column and correctly formats the mac address with the colon (ie with Substring) – To create a new column called CorrectMAC

How would I do this with Oracle?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:30:06+00:00Added an answer on May 16, 2026 at 10:30 am

    Here is some test data:

    SQL> select * from MACAddresses
      2  /
    
      COMPUTER MACADDRESS
    ---------- ------------
           100 123456789abc
           200 acef35dd6ecc
    
    SQL>
    

    Adding the new column is quite straightforward:

    SQL> alter table MACAddresses
      2      add corrected_MACAddress varchar2(17)
      3  /
    
    Table altered.
    
    SQL>
    

    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.

    This is the simplest way of updating the new column.

    SQL> 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> 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>
    

    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.

    Finally, if you wanted to enforce a mandatory constraint you can:

    SQL> alter table MACAddresses
      2       modify corrected_MACAddress not null
      3  /
    
    Table altered.
    
    SQL>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script in T-SQL that goes like this: create table TableName (...)
I have a history table like below CREATE TABLE [dbo].[t_PettyCash_History] ( [TableName] [varchar] (500)
SQL 2008 - Simple Query logic. In my Table :TableName, i have 3 columns
I have a table that looks like this: table name: uno str_id | title
I have a table named Books which contains 3 columns. TableName: Books Columns: BookId
So I have a class that creates a table to be populated with data.
I have a table with some columns. For archive purposes I usually create second
I have some table 'TableName' like Id,Name: 1 | something 2 | _something 3
I have a table that contains a list of tasks; TableName: Tasks. Fields: (ID
Say we have a table like this: **tablename** ID Name Size Date AtStore1 AtStore2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.