Skip to Main Content

ORDS, SODA & JSON in the Database

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ORDS with TNS - error when trying to connect DB for APEX

alacourbOct 28 2021

Oracle 12.1.0.2 with APEX 21.1
ORDS 21.3 on Tomcat 9.0.54 - Windows Server 2019
I'm getting following error when starting Tomcat which prevents ORDS from connecting to the DB:
oracle.net.resolver.EZConnectResolver.parseExtendedProperties Extended settings parsing failed. java.lang.RuntimeException: Invalid character at 24 : \
oracle.dbtools.common.logging.JDKLogSink.record IO Error: Invalid connection string format, a valid format is: "host:port:sid" (CONNECTION_ID=X8ADepYuRpK1p8FSAKp41Q==),|apex||-2021-10-26T20-46-37.212127400Z,jdbc:oracle:thin:@myDB?TNS_ADMIN=D:\App\Oracle\tns
oracle.dbtools.common.logging.JDKLogSink.record The pool named: |apex|| is invalid and will be ignored: ORDS was unable to make a connection to the database. This can occur if the database is unavailable, the maximum number of sessions has been reached or the pool is not correctly configured. The connection pool named: |apex|| had the following error(s): IO Error: Invalid connection string format, a valid format is: "host:port:sid" (CONNECTION_ID=X8ADepYuRpK1p8FSAKp41Q==)
When I'm using Basic connection instead of TNS it works perfectly. The TNS file format is fine since it works with ORDS 21.1.
I have also tried ORDS 21.2: same issue as with 21.3.
ORDS seems to have an issue with tns connection starting from version 21.2.
Any idea?

This post has been answered by Gerardo Gomez-Oracle on Jan 12 2022
Jump to Answer

Comments

Paulzip
Answer
with sample_sales_table
as
  (
  select 2015 fy, 100 shoe, 50 shirt, 2 hat from dual
  union all
  select 2016, 120, 55, 4 from dual
  union all
  select 2017, 150, 80, 10 from dual
  )
select *
from sample_sales_table
unpivot (
  col_val
  for category in (
    shoe, shirt, hat
  )
)
pivot (
  max(col_val)
  for fy in (2015, 2016, 2017)
)
/


CATEGORY|      2015|      2016|      2017
--------|----------|----------|----------
SHOE    |       100|       120|       150
SHIRT   |        50|        55|        80
HAT     |         2|         4|        10


Marked as Answer by HayXing · Apr 20 2021
Frank Kulash

Hi, @hayxing
The number of columns in the output, and their names, must be hard-coded into the query. If you want the number of columns to depend on what data is actually found, then you need dynamic SQL.
If you know you have data for 2015-2017, but you're not sure about 2018-2019, you could simply write a query that pivots all five years, 2015-2019. If there doesn't happen to be any data for some of those years, that won't cause any error; the columns for the extra years will just have NULLs.
Instead of dynamic SQL, you could write a static query that produces a big VARCHAR2 column, formatted so it looks like a variable number of columns. For an example, see PIVOT SQL — oracle-tech

Frank Kulash

Hi,
I have tried with PIVOT / UNPIVOT and with the LISTAGG to for the FY just never get it right.
That should work. Post your code. It's hard to say what you did wrong without knowing what you did.

HayXing
with sample_sales_table
as
  (
  select 2015 fy, 100 shoe, 50 shirt, 2 hat from dual
  union all
  select 2016, 120, 55, 4 from dual
  union all
  select 2017, 150, 80, 10 from dual
  )
select *
from sample_sales_table
unpivot (
  col_val
  for category in (
  shoe, shirt, hat
  )
)
pivot (
  max(col_val)
  for fy in (LISTAGG(DISTINCT fy, ',')) -- this part return error ORA-00934: group function is not allowed here
)
/

HayXing

I am thinking of creating a view how you guys do that with dynamic sql ?

HayXing

Thank you

Frank Kulash

Hi, @hayxing
for fy in (LISTAGG(DISTINCT fy, ',')) -- this part return error ORA-00934: group function is not allowed here
Oh no, that won't work. Oracle needs to know hw many columns there will be when it compiles the query. You need to hard-code the list of values, unless you're getting XML output. (If you get XML output, then the query always produces 1 column, a big XML object, that has a variable number of td elements. Earlier, I posted a link to another thread, that shows how to use the same approach with a single big VARCHAR2 column.)
I am thinking of creating a view how you guys do that with dynamic sql ?
I don't do that. I use a VARCHAR2 column formatted to look like multiple columns.
Earlier today, @solomon-yakobson posted a dynamic pivot solution: Convert columns into row of a table — oracle-tech Maybe you could do something like that.

1 - 7

Post Details

Added on Oct 28 2021
43 comments
4,469 views