Search code examples
oracle-databaseoracle11g

Is there issues with Oracle username starting with numbers? - username in quotes


Using Oracle 11gR2

You can't create a username starting with a number:

SQL> create user 123 identified by temp;
create user 123 identified by temp
            *
ERROR at line 1:
ORA-01935: missing user or role name

However, you can create it as:

SQL> create user "123" identified by temp;

User created.

Somebody knows possible problems with this kind of users?

Somebody knows oracle rules/reasons why you can't create it without quotes, ie, to have usernames starting with numbers?

Thanks in advance


Solution

  • Problems with quoted identifiers

    Quoted identifiers can be successfully used for almost any Oracle object, including users. In theory, they work everywhere. In practice, you will run into many inconveniences and problems with quoted identifiers.

    From the SQL Language Reference: "Note: Oracle does not recommend using quoted identifiers for database object names. These quoted identifiers are accepted by SQL*Plus, but they may not be valid when using other tools that manage database objects."

    Once you use double quotes, every reference to that object must use double quotes, and the correct case. You'll find lots of problems with tools that don't always use double quotes. And problems with scripts that look at metadata and don't always add double quotes. Quoted identifiers are just asking for trouble.

    Why does Oracle have quoted identifiers?

    This question is harder to answer, but I would guess limiting the types of characters used by objects makes parsing much easier. SQL already has a lot of keywords, and has many weird language ambiguities. If object names started with numbers it would make it difficult to differentiate between real numbers and objects.

    For example, without quoted identifiers, this simple statement could be a mess:

    select 1.1 + 2.2 from some_table;
    

    Without restricting object names, 1.1 could be a huge number of things, and the parser would have to look for objects named "1", and then dependent objects named "1", and then determine if that takes precedence over the number "1.1".

    Weird names are possible in languages, but I assume when someone wrote the first SQL compiler 40 years ago they decided not to make their lives so complicated just to accommodate a few weird names.