Error ora 00900 invalid sql statement

check out this post for the various solutions for ORA-00900 invalid sql statement.Reasons for the error.How to debug and resolve it quickly,

ORA-00900 invalid SQL Statement is one of the common error
Here is what oracle documentation says about this error

ORA-00900

Reference: Oracle documentation

Checklist to solve the ORA-00900 invalid SQL Statement

(1) This error commonly occurs when you are trying to create an Oracle procedure and the Procedural Option is not installed. To determine if the Procedural Option has been installed, open an Oracle session using SQL*Plus. If the PL/SQL banner does not display, then you know that the Procedural Option has not been installed.

(2) ORA-00900 can occurs while attempting to use a database link. Many users find that they are encountering ORA-00900 as they attempt to query fields that may have worked before 2000. To resolve ORA-00900, on the local database, try altering your init.ora parameter NLS_DATE_FORMAT, then use double quotes (instead of single) around the value


alter session set NLS_DATE_FORMAT = "DD-MON-YYYY";

(3) Using execute statement on sql developer /JDBC connection

execute dbms_utility.analyze_schema('OKX','ESTIMATE',30);
ORA-00900: invalid SQL statement

execute is sqlplus option, we should use either of the below options in application/other language programs

begin
execute dbms_utility.analyze_schema('OKX','ESTIMATE',30);
end;
or
begin
execute dbms_utility.analyze_schema('OKX','ESTIMATE',30)
end;
/

(4) Many times developers do mistakes in the plsql block and write statements like

v_dynsql:='dbms_utility.analyze_schema('OKX','ESTIMATE',30)';
execute immediate v_dynsql;

The above code gives ORA-00900 as dbms_utility.analyze_schema(‘OKX’,’ESTIMATE’,30);
is not a valid statement

The fix is to use begin and end as given below

v_dynsql:=
q'[BEGIN
dbms_utility.analyze_schema('OKX','ESTIMATE',30);
END;]';
execute immediate v_dynsql;

(5) If you want to describe a table in PLSQL

SQL> begin execute immediate 'describe FND_USER';
2 end;
3 /
begin execute immediate 'describe FND_USER';
*
ERROR at line 1:
ORA-00900: invalid SQL statement
ORA-06512: at line 1

You cannot use desc here. we may want to select it based on query

begin
execute immediate q'[select COLUMN_NAME,DATA_TYPE
from all_tab_columns
where table_name = 'FND_USER'
order by column_id]';
end;
/

(6) If you are trying to explain plan on create view statement

SQL> explain plan for create view test as select * from dual;
explain plan for create view test as select * from dual
*
ERROR at line 1:
ORA-00900: invalid SQL statement

Hope you like the various ways to fix the  ORA errors. Please do provide feedback on it

Related articles
ORA-00911: invalid character
ORA-29913: error in executing ODCIEXTTABLEOPEN callout
ORA-27154: post/wait create failed during startup
ORA-01111
ORA-00257 : archiver error, connect internal only until freed
ora-29283: invalid file operation

oracle tutorial webinars

ORA-00900 Error Message “Invalid SQL Statement”

Error ORA-00900 occurs when the user tries to execute a statement that is not a valid SQL statement. This error occurs if the Procedural Option is not installed and a SQL statement is issued that requires this option.

Users have several options in resolving error ORA-00900. You may choose to install the Procedural Option or correct the actual syntax.

To determine if you have installed the Procedural Option, open a session in Oracle by typing SQL*Plus. If the PL/SQL banner does not display, this means that the Procedural Option has not been installed. Otherwise, the PL/SQL banner should appear in a display window and contain a message with the following information:

SQL*Plus: [Version of release] – [Date of production: Day of week, month, day]

Copyright © [Copyright date], Oracle Corporation. All Rights Reserved.

[Further information on the connection]

Users may see error ORA-00900 when attempting to use a database link or when querying fields that may have worked previously. If faced with this situation, users should take the following steps.

On the local database, change the init.ora parameter NLS _ DATE _ FORMAT and use double quotation marks for the value. Using single quotation marks will cause Oracle to throw error ORA-00900 as this is not properly read and will become invalid. Always use double quotation marks. The database should then be restarted. For example, the statement should read:

NLS _ DATE _ FORMAT = “Day – Month – Year”

Another method is to alter the parameter within the session. This is done by an “alter session set” statement. The following is an example of such a statement:

SQL> alter session set NLS _ DATE _ FORMAT = “Day – Month – Year”;

To avoid seeing error ORA-00900 in the future, double check the syntax and spelling of your PL/SQL statements. Look over your error statement to get more clues on how to solve your error. Minimize the possibility of errors by using indentations and a color-coded IDE. If you continue to see error ORA-00900, you may try posting your code to an Oracle help forum. Likely, another Oracle user has faced the same or similar problems and has already posted the question to a forum. You may consider consulting your database administrator for help or even an outside expert. With any outside Oracle expert, make sure to check their certifications and experience to ensure they are professionals. For reference, see the Online Oracle documentation.

May 10, 2021

I got ” ORA-00900: invalid SQL statement ”  error in Oracle database.

ORA-00900: invalid SQL statement

Details of error are as follows.

ORA-00900 invalid SQL statement
Cause: The statement is not recognized as a valid SQL statement. This error can occur if the
 Procedural Option is not installed and a SQL statement is issued that requires this option 
(for example, a CREATE PROCEDURE statement). You can determine if the Procedural Option is
 installed by starting SQL*Plus. If the PL/SQL banner is not displayed, then the option is not installed.

Action: Correct the syntax or install the Procedural Option.

invalid SQL statement

This ORA-00900 error is related with the statement is not recognized as a valid SQL statement. This error can occur if the Procedural Option is not installed and a SQL statement is issued that requires this option (for example, a CREATE PROCEDURE statement). You can determine if the Procedural Option is installed by starting SQL*Plus. If the PL/SQL banner is not displayed, then the option is not installed.

Correct the syntax or install the Procedural Option.

To solve this error, you need to use nls_date_format as follows.

alter session nls_date_format='DD/MM/YYYY HH:MM:SS AM';

Or use the TO_DATE function as follows.

insert into test values (TO_DATE('2008-12-23T17:28:44','YYYY-MM-DD"T"HH24:MI:SS'));

OR

EXECUTE IMMEDIATE failed when calling PL/SQL object:

SQL>  set serveroutput on
SQL>  declare
  2   v_sql_cmd varchar2(1100);
  3   v_userid varchar2(10):='scott';
  4    v_TEMP_PASSWORD varchar2(10):='testuser';
  5   begin
  6     v_sql_cmd := 'DBMS_UTILITY.EXEC_DDL_STATEMENT(''alter user '|| v_userid|| ' identified by '|| v_TEMP_PASSWORD|| ' password expire'')';
  7              DBMS_OUTPUT.put_line (v_sql_cmd);
  8             execute immediate v_sql_cmd;
  9  end;
 10  /
DBMS_UTILITY.EXEC_DDL_STATEMENT('alter user testuser identified by testuser
password expire')
 declare
*
ERROR at line 1:
ORA-00900: invalid SQL statement
ORA-06512: at line 8

When using EXECUTE IMMEDIATE to call PL/SQL objects without using BEGIN ..END

Put PL/SQL call inside BEGIN..END in EXECUTE IMMEDIATE.

SQL>  declare
  2   v_sql_cmd varchar2(1100);
  3   v_userid varchar2(10):='scott';
  4    v_TEMP_PASSWORD varchar2(10):='tiger';
  5   begin
  6     v_sql_cmd := 'BEGIN DBMS_UTILITY.EXEC_DDL_STATEMENT(''alter user '|| v_userid|| ' identified by '|| v_TEMP_PASSWORD|| ' password expire''); END;';
  7              DBMS_OUTPUT.put_line (v_sql_cmd);
  8             execute immediate v_sql_cmd;
  9  end;
 10  /
BEGIN DBMS_UTILITY.EXEC_DDL_STATEMENT('alter user testuser identified by tiger
password expire'); END;

PL/SQL procedure successfully completed.

If you want to learn more details , Read the following post.


Do you want to learn Oracle Database for Beginners, then read the following articles.

Oracle Tutorial | Oracle Database Tutorials for Beginners ( Junior Oracle DBA )

 1,168 views last month,  1 views today

About Mehmet Salih Deveci

I am Founder of SysDBASoft IT and IT Tutorial and Certified Expert about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 10+years experience.I have OCA, OCP, OCE RAC Expert Certificates I have worked 100+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.If you need Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS Consultancy and Training you can send my email adress [email protected].-                                                                                                                                                                                                                                                 -Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için  [email protected] a mail atabilirsiniz.

  1. What is your Node.js version: use console.log(process.version)? Is it 64-bit or 32-bit: use console.log(process.arch)?

node:10.15.1

  1. What is your node-oracledb version: use console.log(oracledb.versionString)?

^3.1.0

  1. What exact command caused the problem (e.g. what command did you try to install with)? Who were you logged in as?

  2. What error(s) you are seeing?

Unhandled rejection Error: ORA-00900: invalid SQL statement

  1. What OS (and version) is Node.js executing on: use console.log(process.platform)?

debian 9

  1. What is your Oracle client (e.g. Instant Client) version: use console.log(oracledb.oracleClientVersionString)? Is it 64-bit or 32-bit? How was it installed? Where is it installed?

instantclient-basic-linux.x64-18.3.0.0.0

  1. What is your Oracle Database version: use console.log(connection.oracleServerVersionString)?

12.1.0.2.0

  1. What is the PATH environment variable (on Windows) or LD_LIBRARY_PATH (on Linux) set to? On macOS, what is in ~/lib?

  2. What Oracle environment variables did you set? How exactly did you set them?

  3. Do you have a small, single Node.js script that immediately runs to show us the problem?

Doesn’t work

  const db = knex({
    client: 'oracledb',
    debug: true,
    connection: {
      user,
      password,
      connectString: "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" + host + ")(PORT=" + port + "))(CONNECT_DATA=(SID = " + sid + ")))"
    },
    pool: { 
      afterCreate: (conn:any, done:Function) => { 
        conn.execute('execute VECTORS.version_util.set_current_version(:tableName)',{
          tableName: 'VECTORS.Test'
        },(err:Error) => {
          done(err,conn);
        });
      } 
    },
    // @ts-ignore
    fetchAsString: ['clob']
  });

  db('STATES').first()
  .then((data:any) => (console.log(data)));

Works

  const db = knex({
    client: 'oracledb',
    debug: true,
    connection: {
      user,
      password,
      connectString: "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" + host + ")(PORT=" + port + "))(CONNECT_DATA=(SID = " + sid + ")))"
    },
    pool: { 
      afterCreate: (conn:any, done:Function) => { 
        conn.execute('SELECT * FROM COLUMN_REGISTRY WHERE ROWNUM = 1',(err:Error) => {
          done(err,conn);
        });
      } 
    },
    // @ts-ignore
    fetchAsString: ['clob']
  });

  db('STATES').first()
  .then((data:any) => (console.log(data)));

Also Works

From within Oracle SQL developer

execute vectors.version_util.set_current_version('VECTORS.Test');
SELECT * FROM STATES WHERE rownum = 1;

This is the versioning system I am using:

http://desktop.arcgis.com/en/arcmap/10.3/manage-data/using-sql-with-gdbs/read-oracle-versioned-data-using-sql.htm

================================
General
================================
A. When calling to a remote PL/SQL procedure from sqlplus — all works fine,
But when calling to the same remote PL/SQL procedure from PL/SQL code, an ORA-00900: invalid SQL statement error is thrown.


B. When calling a PL/SQL directly, all works fine, but when calling same procedure vi db link, it fails with ORA-02064 Distributed operation not supported


Why is that?


================================
ORA-00900 Example
================================

In this example, a DB_LINK named KUKU is created to the remote database.

CREATE DATABASE LINK KUKU CONNECT TO REMOTE_USER IDENTIFIED BY REMOTE_PASSWORD USING ‘REMOTE_HOST_NAME’;



In the remote database, a getDate Procedure in Package PKG_TEST should be activated.


In sqlplus
From sqlplus, any of these versions work:
EXEC PKG_TEST.getDate@KUKU;
EXEC REMOTE_USER.PKG_TEST.getDate@KUKU;


When creating a Synonym, it can be also used, to simplify code.


CREATE SYNONYM REMOTE_PKG FOR REMOTE_USER.PKG_TEST@KUKU


SELECT * FROM USER_SYNONYMS WHERE synonym_name = ‘KUKU’


SYNONYM_NAME        TABLE_OWNER      TABLE_NAME      DB_LINK
——————- —————- ————— —————
REMOTE_PKG          REMOTE_USER      PKG_TEST        KUKU

So in sqlplus, it would be:
EXEC REMOTE_PKG.getDate;


In PL/SQL
When activating the same code in PL/SQL it MUST be inside a BEGIN END block.
Any other syntax, such as EXECUTE IMMEDIATE <sql_string> would fail with «ORA-00900: invalid SQL statement».


This is the correct code:


BEGIN
  PKG_TEST.getDate;
  EXCEPTION
    WHEN OTHERS THEN
      WRITE_LOG(v_module_name,’Error Running: ‘||v_sql_str||’ ‘||SQLERRM);
      RAISE;
END;

================================
ORA-02064 Example
================================
In this example, same DB_LINK named KUKU is created to the remote database.
The procedure now is a DML Procedre, performing an update, and a commit.


The remote procedure has these API:

PKG_TEST.setDate(v_date    IN DATE,

                v_result  OUT NUMBER);


When calling the remote procedure in PL/SQL, it would be:



DECLARE
  v_date   DATE;
  v_result NUMBER;
BEGIN
  v_date := SYSDATE;
  PKG_TEST.setDate(v_date,v_result);
  EXCEPTION
    WHEN OTHERS THEN
      WRITE_LOG(v_module_name,’Error Running: ‘||v_sql_str||’ ‘||SQLERRM);
      RAISE;

END;



The returned error is:

ORA-02064: distributed operation not supported
ORA-06512: at «REMOTE_USER.PKG_TEST», line 491

Per Oracle documentation, 

Error Cause:
One of the following unsupported operations was attempted:


1. array execute of a remote update with a subquery that references a dblink, or


2. an update of a long column with bind variable and an update of a second column with a subquery that both references a dblink and a bind variable, or


3. a commit is issued in a coordinated session from an RPC procedure call with OUT parameters or function call.


Action:
Simplify remote update statement.

Per Oracle Metalink CALLING REMOTE PACKAGE RECEIVES ORA-2064 (Doc ID 1026597.6):

«This is Not A Bug. 

In the documentation for ORA-2064, it states that one of  the disallowed actions is «A commit is issued in a coordinated session from an RPC with OUT parameters.» 

It happens that the return value of a function call counts as an OUT parameter for purposes of this rule. 

As a workaround for some cases Pragma AUTONOMOUS_TRANSACTION can be used in the called function or procedure in the remote site package.»

So, a work around this problem would be to change the remote Procedure to be Autonomous Transaction.

PKG_TEST.setDate(v_date    IN DATE,
                v_result  OUT NUMBER) IS
PRAGMA AUTONOMOUS_TRANSACTION;

Понравилась статья? Поделить с друзьями:
  • Error option specified in xml does not exist name patchretries value 3
  • Error option single version externally managed not recognized
  • Error option dir is missing
  • Error operator not supported for strings operator not supported for strings joomla
  • Error operator is not overloaded real div real