java.sql.SQLException: ORA-01000: maximum open cursors exceeded. While generating jasper report - oracle

While generating report through jasper we are getting exception error as ...
Error filling print... net.sf.jasperreports.engine.JRException: Error executing SQL statement for : risk
net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Error executing SQL statement for : risk
at net.sf.jasperreports.engine.fill.JRFillSubreport.prepare(JRFillSubreport.java:729)
Caused by: java.sql.SQLException: ORA-01000: maximum open cursors exceeded
How to resolve this?

Сonnect to the database and check the open_cursors limits:
select value from v$parameter where name='open_cursors'
So we list the top 20 sessions which are currently opening most cursors:
select * from ( select ss.value, sn.name, ss.sid from v$sesstat ss, v$statname sn where ss.statistic# = sn.statistic# and sn.name like '%opened cursors current%' order by value desc) where rownum < 21;
The solution is to increase the no. of the open_cursors parameter as :
alter system set open_cursors=400 scope=both

Related

Limit select count subquery work in 21.4.5.46 version but can not work in 21.10.2.15

Limit select count subquery work in 21.4.5.46 version but can not work in 21.10.2.15
Sql is
select * from mytable order by sid limit (select toInt64(count(cid)*0.01) from mytable);
The sql can work very well in in 21.4.5.46 version but can not work in 21.10.2.15.
Exception is : [1002] ClickHouse exception, message: Code: 440. DB::Exception: Illegal type Nullable(Int32) of LIMIT expression, must be numeric type. (INVALID_LIMIT_EXPRESSION) (version 21.10.2.15 (official build))
How to reproduce
1 create table sql:
create table mytable(cid String,create_time String,sid String)engine = MergeTree PARTITION BY sid ORDER BY cid SETTINGS index_granularity = 8192;
2 execute sql
select * from mytable order by sid limit (select toInt64(count(cid)*0.01) from mytable);
ClickHouse release v21.9, 2021-09-09
Backward Incompatible Change
Now, scalar subquery always returns Nullable result if it's type can be Nullable. It is needed because in case of empty subquery it's result should be Null. Previously, it was possible to get error about incompatible types (type deduction does not execute scalar subquery, and it could use not-nullable type). Scalar subquery with empty result which can't be converted to Nullable (like Array or Tuple) now throws error. Fixes #25411. #26423 (Nikolai Kochetov).
Now you should use
SELECT *
FROM mytable
ORDER BY sid ASC
LIMIT assumeNotNull((
SELECT toUInt64(count(cid) * 0.01)
FROM mytable
))
Query id: e3ab56af-96e4-4e01-812d-39af945d7878
Ok.
0 rows in set. Elapsed: 0.004 sec.

Getting GC overhead limit exceeded with Hive query

I have a hive table tableA which is partitioned on adv_id and dt
col_name data_type
adv_id int
url string
dt int
I am firing a query.
SELECT adv_id, url FROM tableA
WHERE
dt = '20200510'
AND adv_id IN (5039) limit 100;
Why do i get a GC overhead limit exceeded error and how do I fix this?
Note that using adv_id = 5039 works here. But i need to check for multiple values and hence the IN clause.
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
at com.mysql.jdbc.SingleByteCharsetConverter.toString(SingleByteCharsetConverter.java:335)
at com.mysql.jdbc.ResultSetRow.getString(ResultSetRow.java:819)
at com.mysql.jdbc.ByteArrayRow.getString(ByteArrayRow.java:70)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5816)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5693)
at org.datanucleus.store.rdbms.mapping.datastore.CharRDBMSMapping.getObject(CharRDBMSMapping.java:473)
at org.datanucleus.store.rdbms.mapping.java.SingleFieldMapping.getObject(SingleFieldMapping.java:220)
at org.datanucleus.store.rdbms.query.ResultClassROF.getObject(ResultClassROF.java:267)
at org.datanucleus.store.rdbms.query.ForwardQueryResult.nextResultSetElement(ForwardQueryResult.java:181)
at

Is there any replacement for ROWNUM in Oracle?

I have JPA Native queries to an Oracle database. The only way I know to limit results is using 'rownum' in Oracle, but for some reason, query parser of a jar driver I have to use does not recognize it.
Caused by: java.sql.SQLException: An exception occurred when executing the following query: "/* dynamic native SQL query */ SELECT * from SFDC_ACCOUNT A where SBSC_TYP = ? and rownum <= ?". Cause: Invalid column name 'rownum'. On line 1, column 90. [parser-2900650]
com.compositesw.cdms.services.parser.ParserException: Invalid column name 'rownum'. On line 1, column 90. [parser-2900650]
How can I get rid of that?
ANSI Standard would be something like the following
SELECT *
FROM (
SELECT
T.*,
ROW_NUMBER() OVER (PARTITION BY T.COLUMN ORDER BY T.COLUMN) ROWNUM_REPLACE
FROM TABLE T
)
WHERE
1=1
AND ROWNUM_REPLACE < 100
or you could also use the following:
SELECT * FROM TABLE T
ORDER BY T.COLUMN
OFFSET 0 ROWS
FETCH NEXT 100 ROWS ONLY;

Why do I get error ORA-08002 when trying to get the currval of a sequence?

In TOAD I can execute this query:
select my_seq.currval from dual;
But when I try to execute it in my application I get this error:
java.sql.SQLException: ORA-08002: sequence MY_SEQ.CURRVAL is not yet defined in this session
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
The answer is very simple: you have to read nextval at least once before you can use currval.
A workaround for this is to execute this sql:
select LAST_NUMBER-1 currval from all_sequences t where t.sequence_name = 'put here your sequence_name';

oracle query timeout

simple query causes ora - 01013 error
select count (*) as counter, 'month_stat' as name
from s_contact_x
where created < last_upd
and (sysdate - last_upd) < 1
Message: Query failed ORA-01013: user
requested cancel of current operation
This select query is succesfully running in TOAD editor, but it takes 3-5 min get resultset.
As I understood, this problem corresponding with oracle query timeout, how we can set it in query?
As others have suggested, you should first look at changing settings and adding indexes. If that doesn't work then you may want to look into using parallelism to speed up the query:
select /*+ parallel(s_contact_x) */ count (*) as counter, 'month_stat' as name
from s_contact_x
where created < last_upd
and (sysdate - last_upd) < 1

Resources