>>
You're reading...
Oracle

Create a table with only scale specification for a column

Hi All,

Just came across a peculiar way of specifying only the column scale and not its precision, so thought of sharing with all. It looks pretty simple but could be a handy tip for table designs.

Scenario: Create a table CONT_EMPS where Salary column must store values upto 2 places of decimals (i.e. scale is 2). Here, note that no precision has been specified for the Salary column. Lets see how to do it.

SQL> CREATE TABLE CONT_EMPS
2 (EMPID NUMBER,
3 EMPNAME VARCHAR2(256),
4 SAL NUMBER(*,2))
5 /
Table created.

SQL> DESC CONT_EMPS
Name         Null?    Type
------------ -------- ----------------------------
EMPID                 NUMBER
EMPNAME               VARCHAR2(256)
SAL                   NUMBER(38,2)

When I specify ‘*’ in place of precision, Oracle treats it as the maximum precision allowed for the column. Additionally, this convention doesn’t applies to PL/SQL data type declaration.
 
Bye for now.
Saurabh

Related articles

About these ads

About Saurabh K. Gupta

Product Manager at Oracle, Author and blogger

Discussion

6 thoughts on “Create a table with only scale specification for a column

  1. Good to know. Is it specific to oracle only or any database?

    Posted by Sivasankar | November 17, 2011, 3:17 pm
  2. Hi Siva

    SQL Server supports number datatype precision upto 38 digits. MySQL supports its till 65 digits.

    As per Oracle documentation, Oracle supports the portability of numbers with precision equal or less than 38 digits. Therefore, reg the mentioned feature, I believe it is supported by Oracle only.

    Posted by sbhoracle | November 18, 2011, 12:30 am
  3. hi i came to youre site, and I have read some good information on it.

    Posted by Gok kastle | November 25, 2011, 1:04 am
  4. This will be the right blog for everyone who wants to learn about this topic. You recognize so a lot its just about difficult to argue with you (not that I in fact would want…HaHa). You absolutely put a new spin on a topic thats been written about for years. Good things, just very good!

    Posted by Sammy | December 6, 2011, 3:55 am
  5. Appreciate it for helping out, great information.

    Posted by Rhett Natal | December 17, 2011, 6:21 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Saurabh K. Gupta

Saurabh K. Gupta

Product Manager at Oracle, Author and blogger

Personal Links

View Full Profile →

Twitter Profile

My Book

Oracle Advanced PL/SQL Developer Professional Guide

Disclaimer

SBHOracle is an independent blog and all the posts are based on my self experience and hands on with the technologies. It shares no relations with any of my current projects or from those in the past.

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 368 other followers

SbhOracle Blog stats

  • 42,401 hits
Aggregated by OraNA
Follow

Get every new post delivered to your Inbox.

Join 368 other followers

%d bloggers like this: