0

I was using the grammar from post: SQL lex yacc grammar

When i analyze the gammar I saw that every "select statement" has to preceed by a cursor.

I saw that oracle database puts a implicit cursor (in case that you dont declare it explicit).

EDIT:

Look ate this doc:

http://docs.oracle.com/cd/E11882_01/appdev.112/e17126/cursor_for_loop_statement.htm

select_statement

SQL SELECT statement (not PL/SQL SELECT INTO statement). For select_statement, PL/SQL declares, opens, fetches from, and closes an implicit cursor. However, because select_statement is not an independent statement, the implicit cursor is internal—you cannot reference it with the name SQL.

http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/sql_cursor.htm

SQL (Implicit) Cursor Attribute

A SQL (implicit) cursor is opened by the database to process each SQL statement that is not associated with an explicit cursor. Every SQL (implicit) cursor has six attributes, each of which returns useful information about the execution of a data manipulation statement.

Is it normal in other databases?

Thanks

Community
  • 1
  • 1
p.magalhaes
  • 7,595
  • 10
  • 53
  • 108
  • 1
    Please be careful of tagging. Flex is for the Adobe/Apache UI Framework and Flex-lexer is for the lexical analyzer. – JeffryHouser Sep 25 '13 at 16:27
  • It is a common mistake and I can understand why. If I Could figure out how to make that distinction show up in the 'roll over text' for Flex; I would. – JeffryHouser Sep 25 '13 at 16:37
  • @Reboog711: Edit the tag excerpt. The comment is in the tag info but it's way too far down for people to see. – rici Sep 25 '13 at 17:07
  • Why do you think that the select statement must be preceded by a cursor? You can derive `sql_list -> sql ';' -> manipulative_statement ';' -> select_statement ';'` without any cursor intervening. – rici Sep 25 '13 at 17:14
  • I think, you forgot to look at the definition of select_statement. select_statement: SELECT opt_all_distinct selection INTO target_commalist table_exp ; – p.magalhaes Sep 25 '13 at 17:43
  • @Rubber: where in that definition of select statement do you see a cursor? It starts with the word "SELECT", continues with ALL or DISTINCT (optionally) and then a selection... but no cursor that I can see. – rici Sep 25 '13 at 20:06
  • Following the rules: cursor_def -> query_exp -> query_term -> query_spec -> SELECT opt_all_distinct selection table_exp. Using this rule i can write a query like "DECLARE cursor_name CURSOR FOR SELECT * FROM TABLE_01" In the select_statement, we have the INTO and it is obligatory. We could not write a query like "select * from table_01" using the select_statement rule. – p.magalhaes Sep 26 '13 at 13:55
  • @Rubber. Ah, good point. But you can't write your select statement using the cursor declaration either, without leaving out the `DECLARE` part. Since the grammar you're using is intended as a demonstration of a parser technology and is not, afaik, used as an actual grammar file in any SQL implementation, I don't think you can draw many conclusions from it. I did find this site which claims to have extracted BNF directly from the SQL 2003 spec: http://savage.net.au/SQL/sql-2003-2.bnf.html#direct%20SQL%20statement – rici Sep 26 '13 at 16:40

1 Answers1

0

This is an Oracle semantic rule, not a grammar issue, and certainly not a lexical issue.

user207421
  • 305,947
  • 44
  • 307
  • 483