I would like to Substring a the first 4 characters of a varchar2 field


I'd like to create a new column in my database that consists of the first 4 characters of an existing varchar2 column.

The table looks like this
1                        12323455
2                         23465236
3                         24352345
4                         23453266
However, I'd like it to look like this:
1                        1232
2                         2346
3                         2435
4                         2345
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

select appcnum,substr(column1,1,4) column1 from your_table

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chakravarthi AyyalaDatabase AdministratorCommented:
Use this: substr(column1,1,4)
Please see below.
Hope this helps!
SQL> create table a(appcnum number, column1 varchar2(20));

Table created.

SQL> insert into a values(1,12323455);

1 row created.

SQL> create table b as select appcnum, substr(column1,1,4) column1 from a ;

Table created.

SQL> select * from a ;

---------- --------------------
         1 12323455

1 row selected.

SQL> select * from b ;

---------- ----------------
         1 1232

1 row selected.

Chakravarthi AyyalaDatabase AdministratorCommented:
I created another table in my example.
Hope you can move forward based on the example given.
awking00Information Technology SpecialistCommented:
Are you looking for an update?
update table set column1 = substr(column1,1,4);
danmcd0913Author Commented:
Thanks for your time.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.