How to call a procedure in Oracle from clojure - oracle

I want to be able to call a procedure in an Oracle database using Clojure.
I have a connection to an Oracle database and I can query the tables of the db using select queries with parameters.
E.g.: If I run "SELECT * FROM user_tables" I get the list of tables as the result. So the connection is working and I do have the correct credentials to make this connection.
I'm using the following dependencies:
[org.clojure/clojure "1.10.1"]
[org.clojure/java.jdbc "0.7.11"]
and as oracle driver I tried these
[oracle.jdbc/oracledriver "11.2.0.2"] (ojdbc6 driver I installed locally under this name)
[oracle.jdbc/ojdbc7 "12.1.0.2"]
[com.oracle/ojdbc8 "19.3.0.0"] or [oracle.jdbc/ojdbc8 "12.2.0.1"]
My java version is:
java version "1.8.0_271"
Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)
Using the ojdbc6 driver results in:
Execution error (SQLException) at oracle.jdbc.driver.T4CTTIoer/processError (T4CTTIoer.java:440).
ORA-29481: Implicit results cannot be returned to client.
ORA-06512: at "SYS.DBMS_SQL", line 2785
ORA-06512: at "SYS.DBMS_SQL", line 2779
ORA-06512: at "<My procedure name>", line 157
ORA-06512: at line 1
Using the version 7 or 8 result in:
#:next.jdbc{:update-count -1}
Can anyone help me to solve this in such a way that I can see the same result set as in SQL-Developer?
Clojure code used to make the connection:
(defstate ^:dynamic *oracle*
"This variable has the database connection to the Oracle Database"
:start
(if-let [jdbc-url (:oracle (env :database-url))]
(conman/connect! {:jdbc-url jdbc-url})
(do
(log/warn "database connection URL was not found, please set :database-url for oracle in your config, e.g: dev-config.edn")
*oracle*))
:stop
(conman/disconnect! *oracle*))
(conman/bind-connection *oracle* "sql/queries-oracle.sql")
In resources/sql there is the file queries-oracle.sql which contains the procedure to be called. I tried several ways to call it:
EXEC schema_name.procedure_name :param1, :param2, :param3;
EXEC schema_name.procedure_name(:param1, :param2, :param3);
BEGIN EXEC schema_name.procedure_name :param1, :param2, :param3; END;
BEGIN schema_name.procedure_name :param1, :param2, :param3; END;
All these have a :name through which they are called. Which I'm now trying from a REPL.
The result of these tries is:
Invalid SQL-Statement
Invalid SQL-Statement
Encountered the symbol "schema_name" when expecting one of the follwing:...
#:next.jdbc{:update-count -1}

Related

Can't enable JavaScript MLE on APEX

I am running Oracle APEX 21.1 (build 21.1.3.r1531102) on the 21c express database and for some reason I cannot execute server side code with the JavaScript MLE option.
In the develpment environment it does not show the option at all.
In the SQL commands screen I can only execute pure sql or PL/SQL. If I try to execute the following example
SET SERVEROUTPUT ON;
DECLARE
ctx dbms_mle.context_handle_t;
user_code clob := q'~
console.log('Hello World!');
~';
BEGIN
ctx := dbms_mle.create_context();
dbms_mle.eval(ctx, 'JAVASCRIPT', user_code);
dbms_mle.drop_context(ctx);
EXCEPTION
WHEN others THEN
dbms_mle.drop_context(ctx);
RAISE;
END;
I get the following message:
ORA-00922: missing or invalid option
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_210100", line 673
ORA-06512: at "SYS.DBMS_SYS_SQL", line 1703
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_210100", line 659
ORA-06512: at "APEX_210100.WWV_FLOW_DYNAMIC_EXEC", line 1854
A few weeks ago we solved this and I forgot to update this question.
After some work we found out that user needed to be granted access to MLE. I was not that one who fixed, but I've asked the code to post here, check below:
GRANT MLE JAVA
GRANT EXECUTE DYNAMIC MLE to XYZ;
GRANT EXECUTE ON JAVASCRIPT TO XYZ;
Remove the first line or comment this out, I suppose this is for on premise DB version support but not allowed in ADB.

Failed to parse target procedure - signature mismatch

I am using Oracle 19c database and I am currently getting this error:
Failed to parse target procedure
VMDB_OAS_Background.Status_Report: SIGNATURE (parameter names) MISMATCH
VARIABLES IN FORM NOT IN PROCEDURE:
NON-DEFAULT VARIABLES IN PROCEDURE NOT IN FORM: JOB_ID
I don't understand why because the Variable are in the procedure and nothing was changed. What does this mean?

Non useful ORA error when working with KafkaConnect JdbcDriver with Oracle 11g (Strimzi Operator)

I'm using strimzi Kafka operator to work with a Confluent Cluster to achieve an Oracle2Kafka type KafkaConnector with JdbcSourceConnector from confluent.
The KafkaConnector spec
# connector
connection.url: jdbc:oracle:thin:#HOST:PORT/SERVICE
connection.user: USER
connection.password: PASS
dialect.name: OracleDatabaseDialect
topic.prefix: test-topic-
mode: bulk
db.timezone: Europe/Madrid
table.whitelist: TEST_TABLE
But I get the following error in the strimzi-cluster-operator logs.
io.strimzi.operator.cluster.operator.assembly.ConnectRestException: PUT /connectors/confluent-cluster-int-20200706-02/config returned 400 (Bad Request): Connector configuration is invalid and contains the following 2 error(s):
Invalid value java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 43
for configuration Couldn't open connection to jdbc:oracle:thin:#***:1534/***
Invalid value java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 43
for configuration Couldn't open connection to jdbc:oracle:thin:#***:1534/***
You can also find the above list of errors at the endpoint `/connector-plugins/{connectorType}/config/validate`
at io.strimzi.operator.cluster.operator.assembly.KafkaConnectApiImpl.lambda$null$2(KafkaConnectApi.java:208) ~[io.strimzi.cluster-operator-0.18.0.jar:0.18.0]
If I modify the source I get a much specific stacktrace
2020-07-14 09:33:46,636 ERROR SQLException (io.confluent.connect.jdbc.source.JdbcSourceConnectorConfig) [qtp742672280-21]
java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 43
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:509)
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:456)
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:451)
at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:1123)
at oracle.jdbc.driver.T4CTTIoauthenticate.processError(T4CTTIoauthenticate.java:552)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:553)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:269)
at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:501)
at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:1292)
at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:1025)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:747)
at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:793)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:57)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:747)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:562)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at io.confluent.connect.jdbc.dialect.GenericDatabaseDialect.getConnection(GenericDatabaseDialect.java:223)
at io.confluent.connect.jdbc.source.JdbcSourceConnectorConfig$TableRecommender.validValues(JdbcSourceConnectorConfig.java:606)
at io.confluent.connect.jdbc.source.JdbcSourceConnectorConfig$CachingRecommender.validValues(JdbcSourceConnectorConfig.java:653)
at org.apache.kafka.common.config.ConfigDef.validate(ConfigDef.java:607)
at org.apache.kafka.common.config.ConfigDef.validate(ConfigDef.java:622)
at org.apache.kafka.common.config.ConfigDef.validate(ConfigDef.java:530)
at org.apache.kafka.common.config.ConfigDef.validateAll(ConfigDef.java:513)
at org.apache.kafka.common.config.ConfigDef.validate(ConfigDef.java:495)
at org.apache.kafka.connect.connector.Connector.validate(Connector.java:135)
Some things I already checked
KafkaConnect image is a self-made one with the required addons for the JdbcSourceConnector with an OracleDriver
Dockerfile
FROM strimzi/kafka:0.18.0-kafka-2.5.0
USER root:root
COPY ./kafka-connect-jdbc-5.4.0.jar /opt/kafka/plugins/
COPY ./ojdbc6.jar /opt/kafka/libs/
USER 1001
KafkaConnect resource is deployed successfully, as KafkaConnect topics are being populated on confluent cluster (connect-cluster-configs, connect-cluster-configs, ...)
Oracle driver seems to be successfully loaded. If I add a typo in the credentials or connection chain the error is self-explanatory and makes sense. I also tried other versions of oracle drivers.
Back in time (4 months ago), this same config was working (both on a local strimzi-deployed-cluster and confluent). Now the local cluster works fine, but confluent one fails with the described error.
Tried several upgraded latest versions of strimzi operator and kafka-jdbc-connector
(edit) As suggested in strimzi slack, tried the PUT /connector-plugins/JdbcSourceConnector/config/validate rest endpoint of KafkaConnect and got same 2 errors, in the whitelist and blacklist fields
result
"value": {
"name": "table.blacklist",
"value": "",
"recommended_values": [],
"errors": ["Invalid value java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1\nORA-06502: PL/SQL: numeric or value error: character string buffer too small\nORA-06512: at line 43\n for configuration Couldn't open connection to jdbc:oracle:thin:#***:1534/***"],
"visible": true
}
(edit) I've tried to leave whitelist field empty and error is the same. The database seems not have been changed and the connection chain works fine from source code spring-data access.
I'm out of ideas, any hint is welcome x)
I don't know tools you use, but - the error you got means this:
SQL> declare
2 l_var varchar2(1); -- note length, only 1 character
3 begin
4 l_var := 'Littlefoot'; -- I'm little, but can't fit
5 end;
6 /
declare
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 4
SQL>
What to do?
SQL> declare
2 l_var varchar2(20); -- is that enough?
3 begin
4 l_var := 'Littlefoot';
5 end;
6 /
PL/SQL procedure successfully completed. --> Yes, it is!
SQL>
Therefore, check the sizes in your code.

Datapump Import Fails With ORA-39006, ORA-39213: “Metadata processing is not available”

I am trying to import multiple dmp files using impdp command i got this error DataPump import (impdp) reports the errors:
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
ORA-39006: internal error
ORA-39213: Metadata processing is not available
Attempting to correct the error ORA-39213 via
dbms_metadata_util.load_stylesheets also reports errors similar to:
SQL> exec dbms_metadata_util.load_stylesheets;
BEGIN dbms_metadata_util.load_stylesheets; END;
* ERROR at line 1: ORA-22288: file or LOB operation FILEEXISTs failed
Permission denied
ORA-06512: at "SYS.DBMS_METADATA_UTIL", line 1807
ORA-06512: at line 1
login from sys and run below query worked for me oracle 11.2
exec dbms_metadata_util.load_stylesheets;

execute dbms_connection_pool.start_pool(); not able to execute

I am not able to execute this command, Even I am in system user. I tried with both that is in command prompt even in Oracle SQL developer tool.
When i am executing the below command in System user
execute dbms_connection_pool.start_pool();
I am getting error as
Error starting at line : 1 in command -
EXECUTE DBMS_CONNECTION_POOL.START_POOL()
Error report -
ORA-06550: line 1, column 7:
PLS-00201: identifier 'DBMS_CONNECTION_POOL.START_POOL' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
For your information I am user oracle express 12c
The database resident connection pool (DRCP) reduces the resource requirements of applications that currently don't support connection pooling, either because it is not supported by the application infrastructure, or it has not been implemented. DRCP is only supported for database connections using the OCI driver. The pool is managed using the dbms_connection_pool package. And the operation is started by start_pool procedure.
You can call this procedure in these two ways :
SQL> exec dbms_connection_pool.start_pool( pool_name => 'my_connection_pool');
or
SQL> exec dbms_connection_pool.start_pool;
but not like in the below way :
SQL> exec dbms_connection_pool.start_pool();
I had the same issue
conn / as sysdba
and
exec dbms_connection_pool.start_pool;
worked for me
and
SELECT connection_pool, maxsize
FROM dba_cpool_info;
to get the info about pool

Resources