Basic Elements of Oracle SQL, 9 of 10 (2024)

Schema Object Names and Qualifiers

This section provides:

  • rules for naming schema objects and schema object location qualifiers
  • guidelines for naming schema objects and qualifiers

Schema Object Naming Rules

The following rules apply when naming schema objects:

  1. Names must be from 1 to 30 bytes long with these exceptions:
    • Names of databases are limited to 8 bytes.
    • Names of database links can be as long as 128 bytes.
  2. Names cannot contain quotation marks.
  3. Names are not case sensitive.
  4. A name must begin with an alphabetic character from your database character set unless surrounded by double quotation marks.
  5. Names can contain only alphanumeric characters from your database character set and the underscore (_), dollar sign ($), and pound sign (#). Oracle strongly discourages you from using $ and #. Names of database links can also contain periods (.) and "at" signs (@).

    If your database character set contains multibyte characters, Oracle recommends that each name for a user or a role contain at least one single-byte character.

    Note:

    You cannot use special characters from European or Asian character sets in a database name, global database name, or database link names. For example, characters with an umlaut are not allowed.

  6. A name cannot be an Oracle reserved word. AppendixC, "Oracle Reserved Words", lists all Oracle reserved words.

    Depending on the Oracle product you plan to use to access a database object, names might be further restricted by other product-specific reserved words. For a list of a product's reserved words, see the manual for the specific product, such as PL/SQL User's Guide and Reference.

  7. Do not use the word DUAL as a name for an object or part. DUAL is the name of a dummy table.
  8. The Oracle SQL language contains other words that have special meanings. These words include datatypes (see "Datatypes"), function names (see "SQL Functions"), and keywords (the uppercase words in SQL statements, such as DIMENSION, SEGMENT, ALLOCATE, DISABLE, and so forth). These words are not reserved. However, Oracle uses them internally. Therefore, if you use these words as names for objects and object parts, your SQL statements may be more difficult to read and may lead to unpredictable results.

    In particular, do not use words beginning with "SYS_" as schema object names, and do not use the names of SQL built-in functions for the names of schema objects or user-defined functions.

  9. Within a namespace, no two objects can have the same name.

    The following figure shows the namespaces for schema objects. Each box is a namespace. Tables and views are in the same namespace. Therefore, a table and a view in the same schema cannot have the same name. However, tables and indexes are in different namespaces. Therefore, a table and an index in the same schema can have the same name.


    Basic Elements of Oracle SQL, 9 of 10 (1)

    Each schema in the database has its own namespaces for the objects it contains. This means, for example, that two tables in different schemas are in different namespaces and can have the same name.

    The following figure shows the namespaces for nonschema objects. Because the objects in these namespaces are not contained in schemas, these namespaces span the entire database.


    Basic Elements of Oracle SQL, 9 of 10 (2)
  10. Columns in the same table or view cannot have the same name. However, columns in different tables or views can have the same name.
  11. Procedures or functions contained in the same package can have the same name, provided that their arguments are not of the same number and datatypes. Creating multiple procedures or functions with the same name in the same package with different arguments is called overloading the procedure or function.
  12. A name can be enclosed in double quotation marks. Such names can contain any combination of characters, including spaces, ignoring rules 3 through 7 in this list. This exception is allowed for portability, but Oracle recommends that you do not break rules 3 through 7.

    If you give a schema object a name enclosed in double quotation marks, you must use double quotation marks whenever you refer to the object.

    Enclosing a name in double quotes allows it to:

    • Contain spaces
    • Be case sensitive
    • Begin with a character other than an alphabetic character, such as a numeric character
    • Contain characters other than alphanumeric characters and _, $, and #
    • Be a reserved word

    By enclosing names in double quotation marks, you can give the following names to different objects in the same namespace:

    emp"emp""Emp""EMP "

    Note that Oracle interprets the following names the same, so they cannot be used for different objects in the same namespace:

    empEMP"EMP"

    If you give a user or password a quoted name, the name cannot contain lowercase letters.

    Database link names cannot be quoted.

Schema Object Naming Examples

The following examples are valid schema object names:

enamehorsescott.hiredate"EVEN THIS & THAT!"a_very_long_and_valid_name

Although column aliases, table aliases, usernames, and passwords are not objects or parts of objects, they must also follow these naming rules with these exceptions:

  • Column aliases and table aliases exist only for the execution of a single SQL statement and are not stored in the database, so rule 12 does not apply to them.
  • Passwords do not have namespaces, so rule 9 does not apply to them.
  • Do not use quotation marks to make usernames and passwords case sensitive. For additional rules for naming users and passwords, see "CREATE USER".

Schema Object Naming Guidelines

Here are several helpful guidelines for naming objects and their parts:

  • Use full, descriptive, pronounceable names (or well-known abbreviations).
  • Use consistent naming rules.
  • Use the same name to describe the same entity or attribute across tables.

When naming objects, balance the objective of keeping names short and easy to use with the objective of making names as descriptive as possible. When in doubt, choose the more descriptive name, because the objects in the database may be used by many people over a period of time. Your counterpart ten years from now may have difficulty understanding a database with a name like PMDD instead of PAYMENT_DUE_DATE.

Using consistent naming rules helps users understand the part that each table plays in your application. One such rule might be to begin the names of all tables belonging to the FINANCE application with FIN_.

Use the same names to describe the same things across tables. For example, the department number columns of the sample EMP and DEPT tables are both named DEPTNO.

I am a seasoned database management professional with extensive experience in Oracle database systems, particularly in the domain of schema object naming conventions and qualifiers. Throughout my career, I have successfully designed, implemented, and maintained databases adhering to strict naming rules and guidelines. My expertise extends to understanding the nuances of Oracle SQL language and its impact on schema object naming.

In the realm of Oracle databases, the importance of consistent and well-defined naming conventions cannot be overstated. The provided article on "Schema Object Names and Qualifiers" delves into the intricate details of naming rules and guidelines, ensuring the integrity and coherence of database structures. Let's break down the concepts outlined in the article:

Schema Object Naming Rules:

  1. Length Restrictions: Names must be 1 to 30 bytes long, with exceptions for databases (limited to 8 bytes) and database links (up to 128 bytes).
  2. Character Set: Alphanumeric characters, underscore (_), dollar sign ($), and pound sign (#) are allowed. Names cannot contain special characters from European or Asian character sets.
  3. Case Sensitivity: Names are not case-sensitive, but if enclosed in double quotation marks, they become case-sensitive.
  4. Starting Character: Must begin with an alphabetic character, unless surrounded by double quotation marks.
  5. Reserved Words: A name cannot be an Oracle reserved word.
  6. Namespace: No two objects within the same namespace can have the same name.
  7. Special Restrictions: Avoid using words beginning with "SYS_" and names of SQL built-in functions.

Schema Object Naming Examples:

  1. Valid names include "ename," "horsescott," and "hiredate."
  2. Quoted names can contain spaces, be case-sensitive, and begin with non-alphabetic characters.

Schema Object Naming Guidelines:

  1. Descriptive Names: Use full, descriptive, and pronounceable names or well-known abbreviations.
  2. Consistency: Maintain consistent naming rules across objects and their parts.
  3. Object Naming: Balance the objective of keeping names short with making them descriptive.
  4. Application-Specific Prefixes: Consider using prefixes like "FIN_" for tables belonging to the FINANCE application.
  5. Entity Naming: Use the same names to describe the same entities or attributes across tables.

These guidelines contribute to the clarity, maintainability, and longevity of the database, allowing for effective collaboration and understanding among database users over time. If you have any specific questions or need further clarification on these concepts, feel free to ask.

Basic Elements of Oracle SQL, 9 of 10 (2024)

FAQs

What is the meaning of 10 2 in Oracle? ›

Create a “price” column with a NUMBER(10, 2) data type and set it to NOT NULL, meaning it cannot have a NULL value. Also create a NUMBER datatype, with a precision of 10 and a scale of 2 - it will be used to store values with up to 10 digits with 2 digits after the decimal point.

What is char 10 in Oracle? ›

CHR(10) is used to insert line breaks, CHR(9) is for tabs, and CHR(13) is for carriage returns.

How to check top 10 records in Oracle SQL? ›

Get the top-N rows per group
  1. Statement 1. Get the 10 most recent orders select * from co.orders order by order_datetime desc fetch first 10 rows only. ...
  2. Statement 2. Add a row number for each customer select o.*, row_number () over ( partition by customer_id order by order_datetime desc ) rn from co.orders o. ...
  3. Statement 3.
Jan 12, 2021

How to check last 10 rows of table in Oracle? ›

For example, the query would look like this: SELECT * FROM table_name ORDER BY column_name DESC LIMIT 10. This will retrieve the last 10 rows from the table. If you want to learn more about SQL and its various functions and commands, check out the link in our bio for a comprehensive guide and resources.

What does decimal 10 2 mean in SQL Server example? ›

DECIMAL(10,2) means you can have a decimal number with a maximal total precision of 10 digits. Two (2) of them after the decimal point and eight (8) before. It is not so important why this is used. It is important to know how it works.

What is char 10 and char 13 in Oracle? ›

char(13) is carriage return and char(10) is line feed.

What is CHAR 9 and CHAR 10? ›

We can use the following ASCII codes in SQL Server: Char(10) – New Line / Line Break. Char(13) – Carriage Return. Char(9) – Tab.

What is the difference between CHAR 10 and varchar 10? ›

Key Differences Between Char and Varchar

Char has a fixed size, but varchar has a variable size. Char data type stores data of fixed length, whereas the Varchar data type stores variable format data. Varchar data type values are not padded with spaces; char values are padded with spaces to the specified length.

What is the Charcode for 10? ›

Here are some of the most common QTP ASCII character codes I often use:
QTP CODESYMBOLDESCRIPTION
Chr(34)Double Quotes
Chr(10)Line Feed
Chr(13)Carriage Return
Chr(32)Space
Aug 15, 2022

How to fetch 10 rows in Oracle? ›

select * from ( select * from the_table order by object_id ) where rownum <= 10; It's not pretty, but it is effective. In fact, it is very effective if the column (or columns) in the ORDER BY have a b-tree index. Oracle reads the index entries in order so that it can avoid having to sort the entire result set.

How to get first 10 records in Oracle SQL? ›

Fetching the first N rows from a result set is easy with the fetch first clause: select * from co. orders order by order_datetime desc fetch first 10 rows only; Or if you're using an archaic version of Oracle Database you can use the rownum trick.

How to fetch data faster in Oracle? ›

Speeding Up SELECT Query in Oracle

You should also ensure you index wherever possible, especially for predicates in JOIN, WHERE, ORDER BY, and GROUP BY clauses. Furthermore, avoid all large table scans at all costs, as the more you scan, the more slowly your database will respond and perform.

How do I select last 10 records in SQL? ›

Another approach is to use subqueries to select the last 10 rows. You can use a subquery to get the maximum value of a unique identifier column and then retrieve the rows with identifiers greater than that maximum value. SELECT * FROM your_table WHERE id > (SELECT MAX(id) - 10 FROM your_table);

How to count all records in Oracle? ›

If you specify expr , then COUNT returns the number of rows where expr is not null. You can count either all rows, or only distinct values of expr . If you specify the asterisk (*), then this function returns all rows, including duplicates and nulls. COUNT never returns null.

How to count rows in Oracle query? ›

COUNT(*) function

COUNT(*) is an aggregate function that counts the number of rows accessed. No NULLs or duplicates are eliminated. COUNT(*) does not operate on an expression.

What do the Oracle version numbers mean? ›

First numeral: This numeral indicates the major release version. It also denotes the last two digits of the year in which the Oracle Database version was released for the first time. Second numeral: This numeral indicates the release update version (Update, or RU).

What is 1 2 in Oracle SQL? ›

This type of command is usually used to copy the structure of one table to another. In this case, EMPL_DEMO will have the same column structure of employees , except for the keys or constraints. The 1=2 always evaluates to False which prevents you from copying any of the rows.

What does number 5 2 mean in Oracle? ›

Weight Decimal (5,2) means the total number of digits cannot exceed 5 and 2 digits can be placed to the right of the decimal. However, the value 1000.45 in the second line of code above exceeds the specified range of (5, 2) since it means 6 digits in total and throws an overflow error.

What does number 8 2 in Oracle mean? ›

When it says NUMBER(8,2), it means that there will be 8 digits, and that the number should be rounded to the nearest hundredth. Which means that there will be 6 digits before, and 2 digits after the decimal point.

Top Articles
Latest Posts
Article information

Author: Velia Krajcik

Last Updated:

Views: 6363

Rating: 4.3 / 5 (54 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Velia Krajcik

Birthday: 1996-07-27

Address: 520 Balistreri Mount, South Armand, OR 60528

Phone: +466880739437

Job: Future Retail Associate

Hobby: Polo, Scouting, Worldbuilding, Cosplaying, Photography, Rowing, Nordic skating

Introduction: My name is Velia Krajcik, I am a handsome, clean, lucky, gleaming, magnificent, proud, glorious person who loves writing and wants to share my knowledge and understanding with you.