6

I find select statement with square brackets in it. Can anybody explain what does this brackets means?

e.g.

select a,b,[c] from table1;

Thanks.

Ishikawa Yoshi
  • 1,779
  • 8
  • 22
  • 43
  • At least post the statement so we can see as well please!! – El Ronnoco Jul 31 '12 at 14:37
  • 3
    That is not a valid statement in Oracle. It would hurl ORA-00936: missing expression. – APC Jul 31 '12 at 15:12
  • The problem that i have code (i know that this is Oracle code or pl/sql) and suddenly i see this symbols like in example, i never use this symbols before when i wrote my own Oracle code. I try to execute query like this but you right it return ORA-00936: missing exspression. That's why i asked this question. – Ishikawa Yoshi Jul 31 '12 at 15:20
  • Can you show some of the actual code that you found rather than dummy code that you know fails? Does the code work against an Oracle DB? – Alex Poole Jul 31 '12 at 15:28
  • sry, i can't publish any part of this code – Ishikawa Yoshi Jul 31 '12 at 15:38
  • Without being to see how and where the brackets are used, not sure how we can help. Can you adapt a query so it's against a system table - anything that gives a working example we can run ourselves. The only place I can think you'd legitimately see `[]`, apart maybe from Oracle Text as @sqrvf showed, is in a [regular expression](http://docs.oracle.com/cd/E11882_01/appdev.112/e25518/adfns_regexp.htm#CHDIEGEI), but that doesn't seem likely from your example code. – Alex Poole Jul 31 '12 at 15:46
  • 2Alex, i agree, without code is hard to understand what is it. But it seems that i understand strange logic in this code. This code (like code in example) is stored to table field, and after that pl/sql code work with this string and find word in it by using square bracket, and after that convert it dynamic string, it's amazing logic i think. It looks like that this string is like template. So i apologize that my question doesn't look like correct. i just only to say thanks everybody who spend time to trying understand my problem. – Ishikawa Yoshi Jul 31 '12 at 16:17

4 Answers4

3

This is not a valid Oracle SQL nor PL/SQL.

Dima Korobskiy
  • 1,479
  • 16
  • 26
2

According to oracle's documentation: http://docs.oracle.com/cd/B10500_01/text.920/a96518/cqspcl.htm

The bracket characters serve to group terms and operators found between the characters; however, they prevent penetrations for the expansion operators (fuzzy, soundex, stem).

Its a grouping character in the query.

Noah
  • 1,966
  • 1
  • 14
  • 29
  • 2
    I highly doubt that this is a correct answer. Oracle Text query syntax is used in `CONTAINS(column, query) > 0` or similar clauses only. – Dima Korobskiy May 26 '16 at 21:47
0

Square brackets in Oracle SQL are only used for cell referencing in the MODEL clause. For example:

select *
from dual
model
    dimension by (0 the_dimension)
    measures (0 the_measure)
    rules iterate(5)
    (
        the_measure[iteration_number] = iteration_number
    );

THE_DIMENSION   THE_MEASURE
-------------   -----------
0               0
1               1
2               2
3               3
4               4

Other databases may use square brackets the way Oracle uses double quotation marks - to enable identifiers to use reserved words or other weird names. But a query like this is invalid in Oracle:

select a,b,[c] from table1;

There are many cases where square brackets in a string may have special meaning to some Oracle features. But characters inside a string don't normally count as part of a language's syntax or the grammar would never end. JSON, Text, regular expressions, and XML are some popular Oracle features that use square brackets in strings, but anybody could create their own custom sub-language.

Jon Heller
  • 34,999
  • 6
  • 74
  • 132
-3

Square brackets in select statements are used when the table name contains a space for example

select * from [Department Managers]

Another time when [] are required is when a column or table name is the name of a built in SQL Server function or keyword for example, if a column is called from, this must be accessed like

Select [From],[To] from tbl

Good luck

Ramboslice
  • 60
  • 5