"Commands out of sync" error when trying to execute a procedure in MySQL 8 - mysql-8.0

When executing below code in phpMyAdmin:
use db;
DELIMITER $$
DROP PROCEDURE IF EXISTS McaTest3$$
CREATE PROCEDURE McaTest3()
BEGIN
SELECT
cl.*
FROM `condition_library` cl
LEFT JOIN condition_custom cc on cl.condition_library_id = cc.condition_library_id
and cc.active = 1
AND (cc.permit_application_id = 20231 OR cc.permit_id = NULL)
WHERE FIND_IN_SET(cl.`condition_library_id`, '13070')
AND cl.active = 1
and cc.condition_library_id IS NULL;
END$$
DELIMITER ;
call McaTest3();
Getting error:
Error
Static analysis:
1 errors were found during analysis.
Missing expression. (near "ON" at position 25)
SQL query: Edit Edit
SET FOREIGN_KEY_CHECKS = ON;
MySQL said: Documentation
#2014 - Commands out of sync; you can't run this command now
This happens when there is no record found in the table which is at LEFT JOIN.
When the same is ran in MySQL Workbench: NO ERROR and return empty dataset.
Same procedure when executed from Application (Appian) is failing as well… Any clues?

Another question on Stackoverflow answered my issue:
link: MySQL error #2014 - Commands out of sync; you can't run this command now

Related

IIB v10: Passing local variable to ESQL select statement

I am new to IIB, trying to connect to Oracle DB using ESQL. Trying to pass a local param to where clause in simple SELECT statement. Getting below error while executing it. Can anyone help me out
ESQL:
BROKER SCHEMA com.project
CREATE COMPUTE MODULE MainFlow_Compute
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
DECLARE var REFERENCE TO Environment.Variables;
DECLARE username CHAR;
SET username = InputRoot.JSON.Data.userid;
--SET OutputRoot.XML.Invoice[] = SELECT E.EMPLOYEE_ID,E.FIRST_NAME FROM Database.HR.EMPLOYEES AS E WHERE E.EMPLOYEE_ID=username;
SET OutputRoot.XML.Invoice[] = PASSTHRU('SELECT E.EMPLOYEE_ID,E.FIRST_NAME FROM Database.HR.EMPLOYEES AS E WHERE E.EMPLOYEE_ID=?' VALUES(username));
SET OutputRoot.JSON.Data.user_id=username;
--SET OutputRoot.JSON.Data.user_name=var.profile.FIRST_NAME;
RETURN TRUE;
END;
END MODULE;
Log:
Error: BIP3113E: Exception detected in message flow com.project.MainFlow
http://localhost:7800/users/getUserDetails
Exception. BIP2230E: Error detected whilst processing a message in node 'com.project.MainFlow.Compute'. : F:\build\slot2\S1000_P\src\DataFlowEngine\SQLNodeLibrary\ImbComputeNode.cpp: 515: ImbComputeNode::evaluate: ComIbmComputeNode: com/project/MainFlow#FCMComposite_1_4
BIP2488E: ('com.project.MainFlow_Compute.Main', '14.4') Error detected while executing the SQL statement ''SET OutputRoot.XML.Invoice[] = DEFAULTPASSTHRU('SELECT E.EMPLOYEE_ID,E.FIRST_NAME FROM Database.HR.EMPLOYEES AS E WHERE E.EMPLOYEE_ID=?', username);''. : F:\build\slot2\S1000_P\src\DataFlowEngine\ImbRdl\ImbRdlStatementGroup.cpp: 767: SqlStatementGroup::execute: :
BIP2321E: Database error: ODBC return code '-1' using ODBC driver manager ''odbc32.dll''. : F:\build\slot2\S1000_P\src\DataFlowEngine\MessageServices\ImbOdbc.cpp: 3814: ImbOdbcStatement::checkRcInner: :
BIP2322E: Database error: SQL State ''IM001''; Native Error Code '0'; Error Text ''[Microsoft][ODBC Driver Manager] Driver does not support this function''. : F:\build\slot2\S1000_P\src\DataFlowEngine\MessageServices\ImbOdbc.cpp: 4035: ImbOdbcStatement::checkRcInner: :
Note: I have referred to below link already
IIB: Passing local variable to ESQL select statement

how to run 'EXEC dbms_stats.init_package()' using cx_Oracle

I tried :
code :
import cx_Oracle
conn = cx_Oracle.connect('xyz/xyz#xyz:1521/orcl')
cur = conn.cursor()
query = 'EXEC dbms_stats.init_package\(\)'
cur.execute(query)
also
query = 'EXEC dbms_stats.init_package()'
cur.execute(query)
for both try I get following error:
Error: cx_Oracle.DatabaseError: ORA-00900: invalid SQL statement
can you please tell the correct way to run this SQL command
EXEC is an sqlplus command, use BEGIN..END instead
proc='''BEGIN
dbms_stats.init_package();
END;'''
cur.execute(proc);
You can call a stored procedure with callproc.
cur.callproc("DBMS_STATS.INIT_PACKAGE")
Details are here

Flyway callbacks with Oracle compile

I try to add before migration and after migration scripts as callbacks to flyway for compiling my views, procedures, functions etc.
Is there a possibility to stop it before a migration process or have a rollback when before or after scripts fail (or rather return a warning)?
Cause the only thing I see right now is I receive warnings like this
[WARNING] DB: Warning: execution completed with warning (SQL State: 99999 - Error Code: 17110)
and it goes on, without stopping.
I thought about FlywayCallback interface and it's implementation but I'm not entirely sure how it should be done with compiling.
I'm using Spring Boot 1.2.5 with the newest Flyway.
I have also same error. SQL State: 99999 - Error Code: 17110. i found this solution.
check which version under this warning and that version under sql script check have Trigger or any procedure which not closed properly.
close trigger or any procedure if oracle DB / end of trigger.
ex:
CREATE OR REPLACE TRIGGER Print_salary_changes
BEFORE DELETE OR INSERT OR UPDATE ON Emp_tab
FOR EACH ROW
WHEN (new.Empno > 0)
DECLARE
sal_diff number;
BEGIN
sal_diff := :new.sal - :old.sal;
dbms_output.put('Old salary: ' || :old.sal);
dbms_output.put(' New salary: ' || :new.sal);
dbms_output.put_line(' Difference ' || sal_diff);
END;
/
Flyway 5.0 now comes with a feature called Error Handlers that lets you do exactly this. You can now create an error handler that turns that warning into an error as simply as
import org.flywaydb.core.api.FlywayException;
import org.flywaydb.core.api.errorhandler.Context;
import org.flywaydb.core.api.errorhandler.ErrorHandler;
import org.flywaydb.core.api.errorhandler.Warning;
public class OracleProcedureFailFastErrorHandler implements ErrorHandler {
#Override
public boolean handle(Context context) {
for (Warning warning : context.getWarnings()) {
if ("99999".equals(warning.getState()) && warning.getCode() == 17110) {
throw new FlywayException("Compilation failed");
}
}
return false;
}
}
More info in the docs: https://flywaydb.org/documentation/errorhandlers
I had the same error when my scripts had a "CREATE TABLE XXX AS SELECT..." statement.
I fixed it by splitting it into two separate statements:
CREATE TABLE XXX (columns def...);
INSERT INTO TABLE XXX (columns...)
SELECT...;

Test with Rails 4 and Oracle crash when generating the database

I develop with Ruby 2, Rails 4.0, and Oracle 11,
When starting with Tests, I couldn't purge neither load the Test Database, many errors appeared:
ActiveRecord::StatementInvalid: OCIError: ORA-00900: SQL sentence not valid
ActiveRecord::StatementInvalid: OCIError: ORA-00933: SQL command not properly ended:
Additional Warning appears:
DEPRECATION WARNING: This database tasks were deprecated,
because this tasks should be served by the 3rd party adapter.
(called from mon_synchronize at /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/monitor.rb:211)
I've modified the next files and now I can execute
rake db:test:load and rake test and database is correctly generated, but warning still appears.
I suppose someone should modify the gems in origin, but who? And if these changes are correct, how can I report this?
File:
usr/local/rvm/gems/ruby-2.0.0-p353#402/gems/activerecord-4.0.2/lib/active_record/tasks/oracle_database_tasks.rb
Added: if (ddl.size>2)
def purge
establish_connection(:test)
connection.structure_drop.split(";\n\n").each { |ddl|
connection.execute(ddl) if (ddl.size>2) }
end
File:
/usr/local/rvm/gems/ruby-2.0.0-p353#402/gems/activerecord-oracle_enhanced-adapter-1.5.5/lib/active_record/connection_adapters/oracle_enhanced_structure_dump.rb
1st Change: Remove / from STATEMENT_TOKEN
# STATEMENT_TOKEN = "\n\n/\n\n"
STATEMENT_TOKEN = "\n\n\n\n"
2nd Change: Add ; after "DROP SEQUENCE..." AND "DROP TABLE....."
# Albert
def structure_drop #:nodoc:
statements = select_values("SELECT sequence_name FROM user_sequences ORDER BY 1").map do |seq|
"DROP SEQUENCE \"#{seq}\";" #Added -->;
end
select_values("SELECT table_name from all_tables t
WHERE owner = SYS_CONTEXT('userenv', 'session_user') AND secondary = 'N'
AND NOT EXISTS (SELECT mv.mview_name FROM all_mviews mv WHERE mv.owner = t.owner AND mv.mview_name = t.table_name)
AND NOT EXISTS (SELECT mvl.log_table FROM all_mview_logs mvl WHERE mvl.log_owner = t.owner AND mvl.log_table = t.table_name)
ORDER BY 1").each do |table|
statements << "DROP TABLE \"#{table}\" CASCADE CONSTRAINTS;" # Added -->;
end
join_with_statement_token(statements)
end
File:
/usr/local/rvm/gems/ruby-2.0.0-p353#402/gems/activerecord-oracle_enhanced-adapter-1.5.5/lib/active_record/connection_adapters/oracle_enhanced_schema_statements
(I don't know if this was correct, or I broke this)
Remove: ;
execute "DROP SEQUENCE #{quote_table_name(seq_name)}" rescue nil
there was a ;--> "seq_name)};" recue nil
and in same folder
oracle_enhanced_adapter.rb
there was also a ";", in "...sequence_name)} ; "), that I removed:
execute ("DROP SEQUENCE #{quote_table_name(sequence_name)}")

Test the existence of a Teradata table and create the table if non-existent

Our Continuous Inegration server (Hudosn) is having a strange issue when attempting to run a simple create table statement in Teradata.
This statement tests the existence of the max_call table:
unless $teradata_connection.table_exists? :arm_custom_db__max_call_attempt_parameters
$teradata_connection.run('CREATE TABLE all_wkscratchpad_db.max_call_attempt_parameters AS (SELECT * FROM arm_custom_db.max_call_attempt_parameters ) WITH NO DATA')
end
The table_exists? method does the following:
def table_exists?(name)
v ||= false # only retry once
sch, table_name = schema_and_table(name)
name = SQL::QualifiedIdentifier.new(sch, table_name) if sch
from(name).first
true
rescue DatabaseError => e
if e.to_s =~ /Operation not allowed for reason code "7" on table/ && v == false
# table probably needs reorg
reorg(name)
v = true
retry
end
false
end
So as per the from(name).first line, the test which this method is performing is just a simple select statement, which, in SQL, looks like: SELECT TOP 1 MAX(CAST(MAX_CALL_ATTEMPT_CNT AS BIGINT)) FROM ALL_WKSCRATCHPAD_DB.MAX_CALL_ATTEMPT_PARAMETERS
The above SQL statement executes perfectly fine within Teradata SQL Assistant, so it's not a SQL syntax issue. The generic ID which our testing suite (Rubymine) uses is also not the issue; that ID has select access to the arm_custom_db.
The exeption which I can see is being thrown (within the builds console output on Hudson) is
Sequel::DatabaseError: Java::ComTeradataJdbcJdbc_4Util::JDBCException. Since this execption is a subclass of DatabaseError, the exception shouldn't be the problem either.
Also: We use unless statements like this every day for hundreds of different tables, and all except this one work correctly. This statement just seems to be a problem.
The complete error message which appears in the builds console output of Hudson is as follows:
[2015-01-07T13:56:37.947000 #16702] ERROR -- : Java::ComTeradataJdbcJdbc_4Util::JDBCException: [Teradata Database] [TeraJDBC 13.10.00.17] [Error 3807] [SQLState 42S02] Object 'ALL_WKSCRATCHPAD_DB.MAX_CALL_ATTEMPT_PARAMETERS' does not exist.: SELECT TOP 1 MAX(CAST(MAX_CALL_ATTEMPT_CNT AS BIGINT)) FROM ALL_WKSCRATCHPAD_DB.MAX_CALL_ATTEMPT_PARAMETERS
Sequel::DatabaseError: Java::ComTeradataJdbcJdbc_4Util::JDBCException: [Teradata Database] [TeraJDBC 13.10.00.17] [Error 3807] [SQLState 42S02] Object 'ALL_WKSCRATCHPAD_DB.MAX_CALL_ATTEMPT_PARAMETERS' does not exist.
I don't understand why this specific bit of code is giving me issues...there does not appear to be anything special about this table or database, and all SQL code executes perfectly fine in Teradata when I am signed in with the same exact user ID that is being used to execute the code from Hudson.

Resources