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
- PL/SQL Part-1 (oramasters.com)
- SQL SERVER - How to work with Row Constructors , inserted and deleted tables and Handle Result Set (sqlexplore.wordpress.com)
- jOOQ-meta. A "hard-core SQL" proof of concept (lukaseder.wordpress.com)
- BISQL # 34 :What is Identity IN SQL {Identity Part - I} (sqlmentalist.wordpress.com)
- SQL Tuning or SQL Optimization (premaseem.wordpress.com)
- Pivot Data in SQL and Display in a Flex Advanced Data Grid Part One (boozydoo.wordpress.com)
- SQL injection (nuzhatg.wordpress.com)
Good to know. Is it specific to oracle only or any database?
ReplyDeleteHI Saurabh,
ReplyDeleteThanks for the post......
well @siva, just tested Saurabh post on 10g.It worked fine
Hi Siva
ReplyDeleteSQL 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.
hi i came to youre site, and I have read some good information on it.
ReplyDeleteThis 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!
ReplyDeleteAppreciate it for helping out, great information.
ReplyDelete