Skip to content
Advertisement

What characters are allowed in Oracle bind param placeholders?

Could anyone please point me to where the characters allowed for a bind variable name are listed? I’ve spent several hours digging through Oracle SQL docs to no avail.

I mean “:id” in the following:

SELECT * FROM mytable WHERE id = :id

E.g. can a dot be used there like “:some.id”? Will it function exactly like the version without the dot?

Advertisement

Answer

These pages both state bind variables must be “legal Oracle identifiers” The documentation I found doesn’t specifically say that a dot can be part of a legal identifer. I was able to use a dot in both a table name and as a bind variable name, but it looks like it is not recommended.

PAGES THAT HAVE BIND VARIABLE NAMING CONVENTIONS (These pages state a bind variable must be a legal identifier):

http://www.utoug.org/i/doc/concept_bind_var.htm

http://docs.oracle.com/cd/E23903_01/doc.41/e21674/concept_ses_val.htm#BEIEGCCC

PAGE THAT DESCRIBES LEGAL IDENTIFIERS: http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements008.htm

I could not find anything on this page that says that a dot is a legal part of an identifier (E.G. table or bind variable name) except in a DB link. Even though $ and # are legal, they are not even recommended, so “.” may work but is obviously not recommended (not even mentioned as legal on this page)

Bind variable names must correspond to an item name. Bind variable names are not case-sensitive. Bind variable names cannot be longer than 30 characters (that is, they must be a valid Oracle identifier).

I know that a valid ORACLE identifer (based on ORACLE’s definition of a legal identifier) cannot start with a number, and can have SOME special characters like $ and . but if there are special characters the identifier MUST be in double quotes.

I was able to get an identifier with a dot to work in a bind variable, but I had to put double quotes around the bind variable when the bind variable had a dot in it.

create or replace function F0416B
RETURN VARCHAR2
is
    V_STMT    VARCHAR2(1999);
    V_RESULT  VARCHAR2(1999);
BEGIN 
    V_STMT := 'INSERT INTO TEST0411(FIELD1, FIELD2) VALUES ( :"A.1" , :"A.2")';
    EXECUTE IMMEDIATE V_STMT USING  'AS201', 'AS202';
    RETURN 'INSERT-OK';
    COMMIT;
EXCEPTION
WHEN OTHERS THEN RETURN SQLERRM;
END;    

#This may work but according to the above documentation a period/dot in a bind variable or other object name is not legal/recommended…

#This is the sentence on the ORACLE schema object naming page that is telling me this:

Nonquoted identifiers can contain only alphanumeric characters from your database character set and the underscore (_), dollar sign ($), and pound sign (#). Database links can also contain periods (.) and “at” signs (@). Oracle strongly discourages you from using $ and # in nonquoted identifiers.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement