Oracle ORA-01704: the string longer than 4000 chars [duplicate] - oracle
This question already has answers here:
Error : ORA-01704: string literal too long
(8 answers)
Closed 1 year ago.
I have a subquery as follows:
SELECT
'ZBTJ/2021-05-15 22:52:00,ZSAM/2021-05-15 23:19:00,ZSAM/2021-05-15 16:02:00,ZGHA/2021-05-15 18:37:00,ZGGG/2021-05-15 09:58:00,EHAM/2021-05-15 19:21:16,ZSAM/2021-05-15 17:18:00,ZJHK/2021-05-15 16:15:00,ZSAM/2021-05-15 06:51:00,ZSHC/2021-05-15 09:37:00,ZHCC/2021-05-15 16:43:26,ZSAM/2021-05-15 09:02:00,ZSAM/2021-05-15 06:57:00,ZSLG/2021-05-15 14:22:00,ZGHY/2021-05-15 20:26:00,ZLIC/2021-05-15 11:23:00,ZSAM/2021-05-15 07:27:00,ZSSH/2021-05-15 17:37:00,ZGBH/2021-05-15 09:51:00,KLAX/2021-05-16 12:27:19,ZSAM/2021-05-15 22:32:00,ZSAM/2021-05-15 12:17:00,ZSAM/2021-05-15 20:23:00,ZSAM/2021-05-15 12:30:00,ZSAM/2021-05-15 10:59:00,ZSAM/2021-05-15 18:06:00,ZSAM/2021-05-15 23:42:00,ZSAM/2021-05-16 05:56:00,ZSAM/2021-05-15 22:20:00,WSSS/2021-05-15 13:18:43,ZSAM/2021-05-16 03:12:00,ZSAM/2021-05-15 23:36:00,WSSS/2021-05-15 15:31:07,ZBAD/2021-05-15 17:35:00,ZSAM/2021-05-15 08:38:00,ZBYN/2021-05-15 11:14:00,ZUUU/2021-05-15 14:53:00,ZSAM/2021-05-15 20:10:00,ZUUU/2021-05-15 07:01:00,ZGHA/2021-05-15 14:54:00,ZSAM/2021-05-15 08:13:00,ZSAM/2021-05-15 12:00:00,ZSAM/2021-05-15 17:48:00,ZUCK/2021-05-15 14:55:00,ZSOF/2021-05-15 11:50:00,ZHCC/2021-05-15 09:30:55,ZSHC/2021-05-15 12:36:00,ZJHK/2021-05-15 09:33:00,KLAX/2021-05-15 15:59:43,ZSAM/2021-05-15 20:29:00,ZSAM/2021-05-15 18:56:00,ZUGY/2021-05-15 11:30:00,ZSAM/2021-05-15 12:22:00,ZLXY/2021-05-15 13:56:00,ZSAM/2021-05-15 18:36:00,ZSAM/2021-05-15 06:55:00,ZBYN/2021-05-15 14:16:00,ZGGG/2021-05-15 14:07:00,ZYHB/2021-05-15 07:51:00,ZSNB/2021-05-15 08:38:00,ZLXY/2021-05-16 02:14:00,ZSAM/2021-05-15 13:03:00,ZSAM/2021-05-16 00:09:00,ZSAM/2021-05-15 13:49:00,ZSAM/2021-05-15 19:35:00,ZSNJ/2021-05-15 10:36:00,ZSAM/2021-05-15 07:20:00,ZLXY/2021-05-16 04:47:00,ZPPP/2021-05-15 11:02:00,ZBTJ/2021-05-15 13:06:00,ZSAM/2021-05-15 09:43:00,ZGHY/2021-05-15 21:47:00,YSSY/2021-05-16 07:13:37,ZSOF/2021-05-15 10:46:00,ZGHA/2021-05-15 08:16:00,ZUCK/2021-05-15 20:17:00,ZJHK/2021-05-15 14:34:00,ZSAM/2021-05-15 10:22:00,ZSAM/2021-05-15 11:44:00,EGLL/2021-05-15 22:16:30,ZSAM/2021-05-15 15:31:00,ZSAM/2021-05-15 11:21:00,ZSAM/2021-05-15 23:13:00,ZSAM/2021-05-16 07:05:00,ZLIC/2021-05-15 15:47:00,ZSAM/2021-05-15 17:52:00,ZGZH/2021-05-15 22:49:38,ZSAM/2021-05-15 08:26:00,ZUGY/2021-05-15 19:43:00,ZSAM/2021-05-15 07:04:00,ZUCK/2021-05-15 09:17:00,ZSAM/2021-05-15 06:49:00,ZSHC/2021-05-15 23:10:00,ZHLY/2021-05-15 16:36:00,ZSAM/2021-05-15 12:32:00,ZSSS/2021-05-15 12:40:00,ZSSS/2021-05-15 22:20:00,ZBAD/2021-05-15 14:36:00,ZSAM/2021-05-15 13:25:00,ZSAM/2021-05-15 07:47:00,ZBAD/2021-05-15 18:26:00,ZSAM/2021-05-15 16:51:00,ZBAD/2021-05-15 19:48:00,ZSAM/2021-05-15 17:50:00,ZSAM/2021-05-15 10:28:00,ZSAM/2021-05-16 02:38:00,ZSSS/2021-05-15 19:56:00,ZSSS/2021-05-15 14:38:00,ZSAM/2021-05-15 21:59:00,ZSAM/2021-05-15 07:41:00,ZSAM/2021-05-15 14:36:00,ZSJN/2021-05-15 13:20:00,ZSAM/2021-05-15 13:14:00,ZGZH/2021-05-15 22:01:31,ZSAM/2021-05-15 11:16:00,ZSZS/2021-05-15 09:10:00,ZSAM/2021-05-15 18:25:00,ZSAM/2021-05-15 18:50:00,ZGSD/2021-05-15 18:30:00,ZUUU/2021-05-15 23:35:00,ZHCC/2021-05-16 00:31:00,ZSAM/2021-05-15 07:42:00,ZSAM/2021-05-15 20:55:00,ZUCK/2021-05-15 19:11:00,ZSAM/2021-05-15 15:57:00,ZHLY/2021-05-15 22:46:00,ZSYN/2021-05-15 09:42:00,ZSAM/2021-05-15 07:00:00,ZSJN/2021-05-15 14:20:00,ZSAM/2021-05-15 19:08:00,ZSAM/2021-05-15 16:57:00,ZSAM/2021-05-15 06:42:00,ZSAM/2021-05-15 21:01:00,ZSAM/2021-05-15 23:28:00,ZLXY/2021-05-15 09:17:00,ZUCK/2021-05-16 00:38:00,ZGHA/2021-05-15 09:06:00,ZGGG/2021-05-15 07:56:00,EGLL/2021-05-16 00:24:25,ZSYN/2021-05-15 18:21:00,ZSAM/2021-05-16 04:08:00,ZSAM/2021-05-15 07:53:00,ZUGY/2021-05-15 21:26:00,ZSAM/2021-05-16 01:15:00,ZGKL/2021-05-15 09:51:17,ZUGY/2021-05-15 09:42:00,ZSAM/2021-05-15 23:50:00,ZBYN/2021-05-15 21:25:00,ZSAM/2021-05-15 12:39:00,ZSAM/2021-05-16 01:12:00,ZSQD/2021-05-15 18:52:00,ZBAD/2021-05-15 09:21:00,ZSAM/2021-05-15 18:59:00,ZSAM/2021-05-15 09:23:00,ZSAM/2021-05-15 16:38:00,ZSAM/2021-05-16 05:59:00,ZUCK/2021-05-15 16:13:00,ZSAM/2021-05-15 08:18:00,ZSAM/2021-05-15 22:11:00,ZSAM/2021-05-16 11:32:00,ZGBH/2021-05-15 10:54:00,ZYHB/2021-05-15 22:40:00,ZUWX/2021-05-15 16:41:00,ZHCC/2021-05-15 20:07:00,ZSAM/2021-05-16 04:15:00,ZJHK/2021-05-15 11:05:00,ZSSS/2021-05-15 08:42:00,ZSAM/2021-05-15 20:17:00,ZSNJ/2021-05-15 09:09:00,ZSAM/2021-05-15 14:06:00,ZSAM/2021-05-15 07:23:00,ZSHC/2021-05-15 22:35:00,ZSAM/2021-05-15 16:27:00,ZSNB/2021-05-15 17:50:00,ZSAM/2021-05-15 13:17:00,ZSAM/2021-05-15 07:35:00,ZSHC/2021-05-15 17:18:00,ZSAM/2021-05-15 16:11:00,ZSAM/2021-05-15 15:39:00,ZSAM/2021-05-15 08:51:00,ZSAM/2021-05-15 16:05:00,ZSAM/2021-05-15 18:32:00,ZSAM/2021-05-15 19:15:00,ZSLG/2021-05-16 02:27:00,ZBHH/2021-05-15 12:49:00,ZSAM/2021-05-15 09:17:00,ZSZS/2021-05-15 07:59:00,ZGSD/2021-05-15 17:32:00,ZSAM/2021-05-15 11:18:00,ZSAM/2021-05-15 16:22:00,ZBHH/2021-05-15 10:22:00,ZUWX/2021-05-15 22:18:00,ZSAM/2021-05-15 21:22:00,ZBTJ/2021-05-15 11:50:00,ZGHA/2021-05-16 01:29:00,ZSAM/2021-05-15 12:57:00,ZSAM/2021-05-15 08:23:00,ZSQD/2021-05-16 02:01:00,ZBAD/2021-05-15 11:45:00'
FROM
dual
I exec the SQL Segment on PL/SQL,it throw exception. >ORA-01704: the string literal is too long.
I want to get the subquery as next query condition,how can I do?
the complete SQL segmen as follows:
with params as
(
select to_date(regexp_substr(str, '[^/]+', 1, 2), 'yyyy-mm-dd hh24:mi:ss') flightDate,
regexp_substr(str, '[^/]+', 1, 1) airportCode
from (SELECT REGEXP_SUBSTR('YSSY/2021-05-16 07:13:37,ZSAM/2021-05-15 18:06:00,ZHCC/2021-05-15 20:07:00,ZBAD/2021-05-15 14:36:00,ZSOF/2021-05-15 10:46:00,ZSAM/2021-05-16 05:56:00,ZHCC/2021-05-16 00:31:00,WSSS/2021-05-15 13:18:43,ZSAM/2021-05-15 12:22:00,ZSAM/2021-05-15 20:17:00,EHAM/2021-05-15 19:21:16,ZSAM/2021-05-15 10:22:00,ZSAM/2021-05-15 14:06:00,ZSAM/2021-05-16 01:12:00,ZHLY/2021-05-15 22:46:00,ZSAM/2021-05-15 23:36:00,ZBAD/2021-05-15 18:26:00,WSSS/2021-05-15 15:31:07,ZBAD/2021-05-15 17:35:00,EGLL/2021-05-15 22:16:30,ZBAD/2021-05-15 19:48:00,ZBAD/2021-05-15 09:21:00,ZSAM/2021-05-15 13:17:00,ZSAM/2021-05-16 02:38:00,ZUUU/2021-05-15 14:53:00,ZSAM/2021-05-15 09:02:00,ZSAM/2021-05-16 05:59:00,ZSAM/2021-05-15 16:05:00,ZSAM/2021-05-15 07:04:00,ZSAM/2021-05-15 19:15:00,KLAX/2021-05-16 12:27:19,ZSOF/2021-05-15 11:50:00,EGLL/2021-05-16 00:24:25,KLAX/2021-05-15 15:59:43,ZSAM/2021-05-15 22:32:00,ZSAM/2021-05-15 22:11:00,ZSAM/2021-05-15 12:17:00,ZSAM/2021-05-16 11:32:00,ZBAD/2021-05-15 11:45:00,ZSAM/2021-05-15 09:43:00',
'[^,]+',
1,
LEVEL) str
FROM DUAL
CONNECT BY REGEXP_SUBSTR('YSSY/2021-05-16 07:13:37,ZSAM/2021-05-15 18:06:00,ZHCC/2021-05-15 20:07:00,ZBAD/2021-05-15 14:36:00,ZSOF/2021-05-15 10:46:00,ZSAM/2021-05-16 05:56:00,ZHCC/2021-05-16 00:31:00,WSSS/2021-05-15 13:18:43,ZSAM/2021-05-15 12:22:00,ZSAM/2021-05-15 20:17:00,EHAM/2021-05-15 19:21:16,ZSAM/2021-05-15 10:22:00,ZSAM/2021-05-15 14:06:00,ZSAM/2021-05-16 01:12:00,ZHLY/2021-05-15 22:46:00,ZSAM/2021-05-15 23:36:00,ZBAD/2021-05-15 18:26:00,WSSS/2021-05-15 15:31:07,ZBAD/2021-05-15 17:35:00,EGLL/2021-05-15 22:16:30,ZBAD/2021-05-15 19:48:00,ZBAD/2021-05-15 09:21:00,ZSAM/2021-05-15 13:17:00,ZSAM/2021-05-16 02:38:00,ZUUU/2021-05-15 14:53:00,ZSAM/2021-05-15 09:02:00,ZSAM/2021-05-16 05:59:00,ZSAM/2021-05-15 16:05:00,ZSAM/2021-05-15 07:04:00,ZSAM/2021-05-15 19:15:00,KLAX/2021-05-16 12:27:19,ZSOF/2021-05-15 11:50:00,EGLL/2021-05-16 00:24:25,KLAX/2021-05-15 15:59:43,ZSAM/2021-05-15 22:32:00,ZSAM/2021-05-15 22:11:00,ZSAM/2021-05-15 12:17:00,ZSAM/2021-05-16 11:32:00,ZBAD/2021-05-15 11:45:00,ZSAM/2021-05-15 09:43:00',
'[^,]+',
1,
LEVEL) IS NOT NULL))
SELECT params.flightDate,
t.datatime,
t.airport4code,
trunc(t.fcsttime) AS fcstday,
t.fcsttime,
t.warningtype,
t.warningvalue,
t.warningnote,
to_number(trunc(t.fcsttime) - trunc(t.datatime)) AS dayNums
FROM tb_weather_forecast t, params
where params.airportCode = t.airport4code
The main problem here is limit buffer inside a line in sqlplus, which is not going to allow you to work with it as you are intending to.
For more information, check this article about limits in sqlplus:
Oracle Sqlplus Limits
Having said that, one possible approach is to split the string before enters in sqlplus ( you can use python or bash for that, is not difficult ), but as I don't know how this data is inserted in the query -you did not explain it-, I can't give you clues here.
Once the data is split, let's say by the comma, you can work with it as you want to.
The clob variable contains the whole string, as I split it on lines
using CRLF using the comma as separator.
Then I split the records by the comma using regexp_substr
But as I used CRLF to split the records, I have to remove it.
Demo
SQL> select version from v$instance ;
VERSION
-----------------
19.0.0.0.0
SQL> select sysdate from dual ;
SYSDATE
---------
31-AUG-21
SQL> host ls -l t.sql
-rw-r--r-- 1 ftpcpl dms 5786 Aug 31 09:37 t.sql
SQL> host cat t.sql
set serveroutput on size unlimited
declare
vstring clob := 'ZBTJ/2021-05-15 22:52:00,ZSAM/2021-05-15 23:19:00,ZSAM/2021-05-15 16:02:00,ZGHA/2021-05-15 18:37:00,
ZGGG/2021-05-15 09:58:00,
EHAM/2021-05-15 19:21:16,
ZSAM/2021-05-15 17:18:00,
ZJHK/2021-05-15 16:15:00,
ZSAM/2021-05-15 06:51:00,
ZSHC/2021-05-15 09:37:00,
ZHCC/2021-05-15 16:43:26,
ZSAM/2021-05-15 09:02:00,
ZSAM/2021-05-15 06:57:00,
ZSLG/2021-05-15 14:22:00,
ZGHY/2021-05-15 20:26:00,
ZLIC/2021-05-15 11:23:00,
ZSAM/2021-05-15 07:27:00,
ZSSH/2021-05-15 17:37:00,
ZGBH/2021-05-15 09:51:00,
KLAX/2021-05-16 12:27:19,
ZSAM/2021-05-15 22:32:00,
ZSAM/2021-05-15 12:17:00,
ZSAM/2021-05-15 20:23:00,
ZSAM/2021-05-15 12:30:00,
ZSAM/2021-05-15 10:59:00,
ZSAM/2021-05-15 18:06:00,
ZSAM/2021-05-15 23:42:00,
ZSAM/2021-05-16 05:56:00,
ZSAM/2021-05-15 22:20:00,
WSSS/2021-05-15 13:18:43,
ZSAM/2021-05-16 03:12:00,
ZSAM/2021-05-15 23:36:00,
WSSS/2021-05-15 15:31:07,
ZBAD/2021-05-15 17:35:00,
ZSAM/2021-05-15 08:38:00,
ZBYN/2021-05-15 11:14:00,
ZUUU/2021-05-15 14:53:00,
ZSAM/2021-05-15 20:10:00,
ZUUU/2021-05-15 07:01:00,
ZGHA/2021-05-15 14:54:00,
ZSAM/2021-05-15 08:13:00,
ZSAM/2021-05-15 12:00:00,
ZSAM/2021-05-15 17:48:00,
ZUCK/2021-05-15 14:55:00,
ZSOF/2021-05-15 11:50:00,
ZHCC/2021-05-15 09:30:55,
ZSHC/2021-05-15 12:36:00,
ZJHK/2021-05-15 09:33:00,
KLAX/2021-05-15 15:59:43,
ZSAM/2021-05-15 20:29:00,
ZSAM/2021-05-15 18:56:00,
ZUGY/2021-05-15 11:30:00,
ZSAM/2021-05-15 12:22:00,
ZLXY/2021-05-15 13:56:00,
ZSAM/2021-05-15 18:36:00,
ZSAM/2021-05-15 06:55:00,
ZBYN/2021-05-15 14:16:00,
ZGGG/2021-05-15 14:07:00,
ZYHB/2021-05-15 07:51:00,
ZSNB/2021-05-15 08:38:00,
ZLXY/2021-05-16 02:14:00,
ZSAM/2021-05-15 13:03:00,
ZSAM/2021-05-16 00:09:00,
ZSAM/2021-05-15 13:49:00,
ZSAM/2021-05-15 19:35:00,
ZSNJ/2021-05-15 10:36:00,
ZSAM/2021-05-15 07:20:00,
ZLXY/2021-05-16 04:47:00,
ZPPP/2021-05-15 11:02:00,
ZBTJ/2021-05-15 13:06:00,
ZSAM/2021-05-15 09:43:00,
ZGHY/2021-05-15 21:47:00,
YSSY/2021-05-16 07:13:37,
ZSOF/2021-05-15 10:46:00,
ZGHA/2021-05-15 08:16:00,
ZUCK/2021-05-15 20:17:00,
ZJHK/2021-05-15 14:34:00,
ZSAM/2021-05-15 10:22:00,
ZSAM/2021-05-15 11:44:00,
EGLL/2021-05-15 22:16:30,
ZSAM/2021-05-15 15:31:00,
ZSAM/2021-05-15 11:21:00,
ZSAM/2021-05-15 23:13:00,
ZSAM/2021-05-16 07:05:00,
ZLIC/2021-05-15 15:47:00,
ZSAM/2021-05-15 17:52:00,
ZGZH/2021-05-15 22:49:38,
ZSAM/2021-05-15 08:26:00,
ZUGY/2021-05-15 19:43:00,
ZSAM/2021-05-15 07:04:00,
ZUCK/2021-05-15 09:17:00,
ZSAM/2021-05-15 06:49:00,
ZSHC/2021-05-15 23:10:00,
ZHLY/2021-05-15 16:36:00,
ZSAM/2021-05-15 12:32:00,
ZSSS/2021-05-15 12:40:00,
ZSSS/2021-05-15 22:20:00,
ZBAD/2021-05-15 14:36:00,
ZSAM/2021-05-15 13:25:00,
ZSAM/2021-05-15 07:47:00,
ZBAD/2021-05-15 18:26:00,
ZSAM/2021-05-15 16:51:00,
ZBAD/2021-05-15 19:48:00,
ZSAM/2021-05-15 17:50:00,
ZSAM/2021-05-15 10:28:00,
ZSAM/2021-05-16 02:38:00,
ZSSS/2021-05-15 19:56:00,
ZSSS/2021-05-15 14:38:00,
ZSAM/2021-05-15 21:59:00,
ZSAM/2021-05-15 07:41:00,
ZSAM/2021-05-15 14:36:00,
ZSJN/2021-05-15 13:20:00,
ZSAM/2021-05-15 13:14:00,
ZGZH/2021-05-15 22:01:31,
ZSAM/2021-05-15 11:16:00,
ZSZS/2021-05-15 09:10:00,
ZSAM/2021-05-15 18:25:00,
ZSAM/2021-05-15 18:50:00,
ZGSD/2021-05-15 18:30:00,
ZUUU/2021-05-15 23:35:00,
ZHCC/2021-05-16 00:31:00,
ZSAM/2021-05-15 07:42:00,
ZSAM/2021-05-15 20:55:00,
ZUCK/2021-05-15 19:11:00,
ZSAM/2021-05-15 15:57:00,
ZHLY/2021-05-15 22:46:00,
ZSYN/2021-05-15 09:42:00,
ZSAM/2021-05-15 07:00:00,
ZSJN/2021-05-15 14:20:00,
ZSAM/2021-05-15 19:08:00,
ZSAM/2021-05-15 16:57:00,
ZSAM/2021-05-15 06:42:00,
ZSAM/2021-05-15 21:01:00,
ZSAM/2021-05-15 23:28:00,
ZLXY/2021-05-15 09:17:00,
ZUCK/2021-05-16 00:38:00,
ZGHA/2021-05-15 09:06:00,
ZGGG/2021-05-15 07:56:00,
EGLL/2021-05-16 00:24:25,
ZSYN/2021-05-15 18:21:00,
ZSAM/2021-05-16 04:08:00,
ZSAM/2021-05-15 07:53:00,
ZUGY/2021-05-15 21:26:00,
ZSAM/2021-05-16 01:15:00,
ZGKL/2021-05-15 09:51:17,
ZUGY/2021-05-15 09:42:00,
ZSAM/2021-05-15 23:50:00,
ZBYN/2021-05-15 21:25:00,
ZSAM/2021-05-15 12:39:00,
ZSAM/2021-05-16 01:12:00,
ZSQD/2021-05-15 18:52:00,
ZBAD/2021-05-15 09:21:00,
ZSAM/2021-05-15 18:59:00,
ZSAM/2021-05-15 09:23:00,
ZSAM/2021-05-15 16:38:00,
ZSAM/2021-05-16 05:59:00,
ZUCK/2021-05-15 16:13:00,
ZSAM/2021-05-15 08:18:00,
ZSAM/2021-05-15 22:11:00,
ZSAM/2021-05-16 11:32:00,
ZGBH/2021-05-15 10:54:00,
ZYHB/2021-05-15 22:40:00,
ZUWX/2021-05-15 16:41:00,
ZHCC/2021-05-15 20:07:00,
ZSAM/2021-05-16 04:15:00,
ZJHK/2021-05-15 11:05:00,
ZSSS/2021-05-15 08:42:00,
ZSAM/2021-05-15 20:17:00,
ZSNJ/2021-05-15 09:09:00,
ZSAM/2021-05-15 14:06:00,
ZSAM/2021-05-15 07:23:00,
ZSHC/2021-05-15 22:35:00,
ZSAM/2021-05-15 16:27:00,
ZSNB/2021-05-15 17:50:00,
ZSAM/2021-05-15 13:17:00,
ZSAM/2021-05-15 07:35:00,
ZSHC/2021-05-15 17:18:00,
ZSAM/2021-05-15 16:11:00,
ZSAM/2021-05-15 15:39:00,
ZSAM/2021-05-15 08:51:00,
ZSAM/2021-05-15 16:05:00,
ZSAM/2021-05-15 18:32:00,
ZSAM/2021-05-15 19:15:00,
ZSLG/2021-05-16 02:27:00,
ZBHH/2021-05-15 12:49:00,
ZSAM/2021-05-15 09:17:00,
ZSZS/2021-05-15 07:59:00,
ZGSD/2021-05-15 17:32:00,
ZSAM/2021-05-15 11:18:00,
ZSAM/2021-05-15 16:22:00,
ZBHH/2021-05-15 10:22:00,
ZUWX/2021-05-15 22:18:00,
ZSAM/2021-05-15 21:22:00,
ZBTJ/2021-05-15 11:50:00,
ZGHA/2021-05-16 01:29:00,
ZSAM/2021-05-15 12:57:00,
ZSAM/2021-05-15 08:23:00,
ZSQD/2021-05-16 02:01:00,
ZBAD/2021-05-15 11:45:00';
vcounter pls_integer;
vrecord varchar2(100);
begin
vcounter := regexp_count( vstring , ',') + 1;
for var in 1..vcounter
loop
if var=1
then
vrecord := regexp_substr( vstring, '[^,]+', 1 , 1 );
vrecord := replace( replace( vrecord , CHR(10) ) , CHR(13) );
dbms_output.put_line(vrecord);
elsif var > 1 and var <= vcounter
then
vrecord := regexp_substr( vstring, '[^,]+', 1 , var );
vrecord := replace( replace( vrecord , CHR(10) ) , CHR(13) );
dbms_output.put_line(vrecord);
end if;
end loop;
end;
/
SQL> #t.sql
ZBTJ/2021-05-15 22:52:00
ZSAM/2021-05-15 23:19:00
ZSAM/2021-05-15 16:02:00
ZGHA/2021-05-15 18:37:00
ZGGG/2021-05-15 09:58:00
EHAM/2021-05-15 19:21:16
ZSAM/2021-05-15 17:18:00
ZJHK/2021-05-15 16:15:00
ZSAM/2021-05-15 06:51:00
ZSHC/2021-05-15 09:37:00
ZHCC/2021-05-15 16:43:26
ZSAM/2021-05-15 09:02:00
ZSAM/2021-05-15 06:57:00
ZSLG/2021-05-15 14:22:00
ZGHY/2021-05-15 20:26:00
ZLIC/2021-05-15 11:23:00
ZSAM/2021-05-15 07:27:00
ZSSH/2021-05-15 17:37:00
ZGBH/2021-05-15 09:51:00
KLAX/2021-05-16 12:27:19
ZSAM/2021-05-15 22:32:00
ZSAM/2021-05-15 12:17:00
ZSAM/2021-05-15 20:23:00
ZSAM/2021-05-15 12:30:00
ZSAM/2021-05-15 10:59:00
ZSAM/2021-05-15 18:06:00
ZSAM/2021-05-15 23:42:00
ZSAM/2021-05-16 05:56:00
ZSAM/2021-05-15 22:20:00
WSSS/2021-05-15 13:18:43
ZSAM/2021-05-16 03:12:00
ZSAM/2021-05-15 23:36:00
WSSS/2021-05-15 15:31:07
ZBAD/2021-05-15 17:35:00
ZSAM/2021-05-15 08:38:00
ZBYN/2021-05-15 11:14:00
ZUUU/2021-05-15 14:53:00
ZSAM/2021-05-15 20:10:00
ZUUU/2021-05-15 07:01:00
ZGHA/2021-05-15 14:54:00
ZSAM/2021-05-15 08:13:00
ZSAM/2021-05-15 12:00:00
ZSAM/2021-05-15 17:48:00
ZUCK/2021-05-15 14:55:00
ZSOF/2021-05-15 11:50:00
ZHCC/2021-05-15 09:30:55
ZSHC/2021-05-15 12:36:00
ZJHK/2021-05-15 09:33:00
KLAX/2021-05-15 15:59:43
ZSAM/2021-05-15 20:29:00
ZSAM/2021-05-15 18:56:00
ZUGY/2021-05-15 11:30:00
ZSAM/2021-05-15 12:22:00
ZLXY/2021-05-15 13:56:00
ZSAM/2021-05-15 18:36:00
ZSAM/2021-05-15 06:55:00
ZBYN/2021-05-15 14:16:00
ZGGG/2021-05-15 14:07:00
ZYHB/2021-05-15 07:51:00
ZSNB/2021-05-15 08:38:00
ZLXY/2021-05-16 02:14:00
ZSAM/2021-05-15 13:03:00
ZSAM/2021-05-16 00:09:00
ZSAM/2021-05-15 13:49:00
ZSAM/2021-05-15 19:35:00
ZSNJ/2021-05-15 10:36:00
ZSAM/2021-05-15 07:20:00
ZLXY/2021-05-16 04:47:00
ZPPP/2021-05-15 11:02:00
ZBTJ/2021-05-15 13:06:00
ZSAM/2021-05-15 09:43:00
ZGHY/2021-05-15 21:47:00
YSSY/2021-05-16 07:13:37
ZSOF/2021-05-15 10:46:00
ZGHA/2021-05-15 08:16:00
ZUCK/2021-05-15 20:17:00
ZJHK/2021-05-15 14:34:00
ZSAM/2021-05-15 10:22:00
ZSAM/2021-05-15 11:44:00
EGLL/2021-05-15 22:16:30
ZSAM/2021-05-15 15:31:00
ZSAM/2021-05-15 11:21:00
ZSAM/2021-05-15 23:13:00
ZSAM/2021-05-16 07:05:00
ZLIC/2021-05-15 15:47:00
ZSAM/2021-05-15 17:52:00
ZGZH/2021-05-15 22:49:38
ZSAM/2021-05-15 08:26:00
ZUGY/2021-05-15 19:43:00
ZSAM/2021-05-15 07:04:00
ZUCK/2021-05-15 09:17:00
ZSAM/2021-05-15 06:49:00
ZSHC/2021-05-15 23:10:00
ZHLY/2021-05-15 16:36:00
ZSAM/2021-05-15 12:32:00
ZSSS/2021-05-15 12:40:00
ZSSS/2021-05-15 22:20:00
ZBAD/2021-05-15 14:36:00
ZSAM/2021-05-15 13:25:00
ZSAM/2021-05-15 07:47:00
ZBAD/2021-05-15 18:26:00
ZSAM/2021-05-15 16:51:00
ZBAD/2021-05-15 19:48:00
ZSAM/2021-05-15 17:50:00
ZSAM/2021-05-15 10:28:00
ZSAM/2021-05-16 02:38:00
ZSSS/2021-05-15 19:56:00
ZSSS/2021-05-15 14:38:00
ZSAM/2021-05-15 21:59:00
ZSAM/2021-05-15 07:41:00
ZSAM/2021-05-15 14:36:00
ZSJN/2021-05-15 13:20:00
ZSAM/2021-05-15 13:14:00
ZGZH/2021-05-15 22:01:31
ZSAM/2021-05-15 11:16:00
ZSZS/2021-05-15 09:10:00
ZSAM/2021-05-15 18:25:00
ZSAM/2021-05-15 18:50:00
ZGSD/2021-05-15 18:30:00
ZUUU/2021-05-15 23:35:00
ZHCC/2021-05-16 00:31:00
ZSAM/2021-05-15 07:42:00
ZSAM/2021-05-15 20:55:00
ZUCK/2021-05-15 19:11:00
ZSAM/2021-05-15 15:57:00
ZHLY/2021-05-15 22:46:00
ZSYN/2021-05-15 09:42:00
ZSAM/2021-05-15 07:00:00
ZSJN/2021-05-15 14:20:00
ZSAM/2021-05-15 19:08:00
ZSAM/2021-05-15 16:57:00
ZSAM/2021-05-15 06:42:00
ZSAM/2021-05-15 21:01:00
ZSAM/2021-05-15 23:28:00
ZLXY/2021-05-15 09:17:00
ZUCK/2021-05-16 00:38:00
ZGHA/2021-05-15 09:06:00
ZGGG/2021-05-15 07:56:00
EGLL/2021-05-16 00:24:25
ZSYN/2021-05-15 18:21:00
ZSAM/2021-05-16 04:08:00
ZSAM/2021-05-15 07:53:00
ZUGY/2021-05-15 21:26:00
ZSAM/2021-05-16 01:15:00
ZGKL/2021-05-15 09:51:17
ZUGY/2021-05-15 09:42:00
ZSAM/2021-05-15 23:50:00
ZBYN/2021-05-15 21:25:00
ZSAM/2021-05-15 12:39:00
ZSAM/2021-05-16 01:12:00
ZSQD/2021-05-15 18:52:00
ZBAD/2021-05-15 09:21:00
ZSAM/2021-05-15 18:59:00
ZSAM/2021-05-15 09:23:00
ZSAM/2021-05-15 16:38:00
ZSAM/2021-05-16 05:59:00
ZUCK/2021-05-15 16:13:00
ZSAM/2021-05-15 08:18:00
ZSAM/2021-05-15 22:11:00
ZSAM/2021-05-16 11:32:00
ZGBH/2021-05-15 10:54:00
ZYHB/2021-05-15 22:40:00
ZUWX/2021-05-15 16:41:00
ZHCC/2021-05-15 20:07:00
ZSAM/2021-05-16 04:15:00
ZJHK/2021-05-15 11:05:00
ZSSS/2021-05-15 08:42:00
ZSAM/2021-05-15 20:17:00
ZSNJ/2021-05-15 09:09:00
ZSAM/2021-05-15 14:06:00
ZSAM/2021-05-15 07:23:00
ZSHC/2021-05-15 22:35:00
ZSAM/2021-05-15 16:27:00
ZSNB/2021-05-15 17:50:00
ZSAM/2021-05-15 13:17:00
ZSAM/2021-05-15 07:35:00
ZSHC/2021-05-15 17:18:00
ZSAM/2021-05-15 16:11:00
ZSAM/2021-05-15 15:39:00
ZSAM/2021-05-15 08:51:00
ZSAM/2021-05-15 16:05:00
ZSAM/2021-05-15 18:32:00
ZSAM/2021-05-15 19:15:00
ZSLG/2021-05-16 02:27:00
ZBHH/2021-05-15 12:49:00
ZSAM/2021-05-15 09:17:00
ZSZS/2021-05-15 07:59:00
ZGSD/2021-05-15 17:32:00
ZSAM/2021-05-15 11:18:00
ZSAM/2021-05-15 16:22:00
ZBHH/2021-05-15 10:22:00
ZUWX/2021-05-15 22:18:00
ZSAM/2021-05-15 21:22:00
ZBTJ/2021-05-15 11:50:00
ZGHA/2021-05-16 01:29:00
ZSAM/2021-05-15 12:57:00
ZSAM/2021-05-15 08:23:00
ZSQD/2021-05-16 02:01:00
ZBAD/2021-05-15 11:45:00
PL/SQL procedure successfully completed.
SQL>
If you try to put more than 4000 bytes of characters into it then it will fail as the literal (denoted by the surrounding '' characters) will be larger than its maximum size.
Divide it into multiple chunks and use select SQL command:
SELECT (to_clob('') || to_clob('')) from dual;
Related
Oracle HTP.formopen PLS-00306
I have an oracle web PLS-SQL package body that compiles successfully. When executed, get an ORA-06550 & PLS 00306 error "Wrong Number or types of arguments in call". The call is HTP.formopen (code below). Since there is no "arquments", what is wrong with this call? Updated question, how do I pass parameters to a function inside HTP.formopen? HTP.formopen (twbkwbis.f_cgibin || 'bzskaold.FS_P_ProcessRequest'); ------- TYPE varchar2_hashtab IS TABLE OF VARCHAR2(500) INDEX BY VARCHAR2(5); TYPE varchar2_tabtype IS TABLE OF VARCHAR2(26) INDEX BY BINARY_INTEGER; var_empty_hash varchar2_hashtab; var_empty_table varchar2_tabtype; PROCEDURE FS_P_ProcessRequest ( AA IN VARCHAR2 DEFAULT NULL, BB IN VARCHAR2 DEFAULT NULL, CC IN VARCHAR2 DEFAULT NULL, DD IN VARCHAR2 DEFAULT NULL, EE IN VARCHAR2 DEFAULT NULL, FF IN VARCHAR2 DEFAULT NULL, GG IN VARCHAR2 DEFAULT NULL, HH IN VARCHAR2 DEFAULT NULL, II IN OUT bzskaold.varchar2_hashtab, JJ IN bzskaold.varchar2_tabtype DEFAULT var_empty_table, KK IN OUT bzskaold.varchar2_hashtab, LL IN bzskaold.varchar2_tabtype DEFAULT var_empty_table, MM IN OUT bzskaold.varchar2_hashtab, NN IN OUT bzskaold.varchar2_hashtab, OO IN VARCHAR2 DEFAULT NULL, PP IN VARCHAR2 DEFAULT NULL, QQ IN VARCHAR2 DEFAULT NULL, RR IN VARCHAR2 DEFAULT NULL );
Why do I get ORA-06531: reference to uninitialized collection?
I want to call a PL/SQL function with select consult_trac.get_detail_dos_amo('12345') from dual but I get the error: java.sql.SQLException: ORA-06530: Reference to uninitialized composite ORA-06512: à "CNSS_SERVICES.GET_DETAIL_DOS_AMO" at line 60 (ret(v_counter).num_doss := DS_DT.NUM_DOSS;) My PL/SQL function is defined in a package with all the types. Package definition: CREATE OR REPLACE PACKAGE consult_trac AS FUNCTION get_detail_dos_amo (p_num_doss VARCHAR2) RETURN tab_dos_t_amo; END consult_trac; / CREATE OR REPLACE PACKAGE BODY consult_trac AS FUNCTION get_detail_dos_amo (p_num_doss VARCHAR2) RETURN tab_dos_t_amo IS CURSOR DOSS_DET (num_doss VARCHAR2) IS SELECT NUM_DOSS, DAT_DEP, NUM_IMMA, NUM_IND, P_DATE_ACTE, CODE_EVOP, LIB_EVOP, CODE_DR, LIB_DR, C_USER, C_GENCE, C_NIV, L_NIV, DAT_SUI, C_D_ETAT, L_D_ETAT, L_NAT, NUM_RECOM, ACCUSE, P_MONTANT, NUM_D_PARENT, P_INP_DOS, P_ICE_DOS, P_CIN, P_NOM, P_PRENOM, P_N_PAGE, P_D_SORTIE, P_C_CAT, P_C_SOURCE, C_ERROR FROM TYP_DOSS_AMO WHERE NUM_DOSS = p_num_doss; CURSOR SEL_MEDIC(num_doss VARCHAR2) IS SELECT CODE_MEDIC, NOMBRE FROM DOSS_MEDIC WHERE NUM_DOSS = num_doss; CURSOR SEL_INP(num_doss VARCHAR2) IS SELECT CODE_INP FROM DOSS_INP WHERE NUM_DOSS = num_doss; ret tab_dos_t_amo; ret_med tab_medic; ret_inp tab_inp; v_counter number := 0; v_counter_med number := 0; v_counter_inp number := 0; BEGIN FOR DS_DT IN DOSS_DET(p_num_doss) LOOP ret(v_counter).num_doss := DS_DT.NUM_DOSS; ret(v_counter).dat_dep := DS_DT.DAT_DEP; ret(v_counter).num_imma := DS_DT.NUM_IMMA; ret(v_counter).num_ind := DS_DT.NUM_IND; ret(v_counter).p_date_acte := DS_DT.P_DATE_ACTE; ret(v_counter).code_evop := DS_DT.CODE_EVOP; ret(v_counter).lib_evop := DS_DT.LIB_EVOP; ret(v_counter).code_dr := DS_DT.CODE_DR; ret(v_counter).lib_dr := DS_DT.LIB_DR; ret(v_counter).c_user := DS_DT.C_USER; ret(v_counter).c_gence := DS_DT.C_GENCE; ret(v_counter).c_niv := DS_DT.C_NIV; ret(v_counter).l_niv := DS_DT.L_NIV; ret(v_counter).dat_sui := DS_DT.DAT_SUI; ret(v_counter).c_d_etat := DS_DT.C_D_ETAT; ret(v_counter).l_d_etat := DS_DT.L_D_ETAT; ret(v_counter).l_nat := DS_DT.L_NAT; ret(v_counter).num_recom := DS_DT.NUM_RECOM; ret(v_counter).accuse := DS_DT.ACCUSE; ret(v_counter).p_montant := DS_DT.P_MONTANT; ret(v_counter).num_d_parent := DS_DT.NUM_D_PARENT; ret(v_counter).p_INP_dos := DS_DT.P_INP_DOS; ret(v_counter).p_ICE_dos := DS_DT.P_ICE_DOS; ret(v_counter).p_cin := DS_DT.P_CIN; ret(v_counter).p_nom := DS_DT.P_NOM; ret(v_counter).p_prenom := DS_DT.P_PRENOM; ret(v_counter).p_n_page := DS_DT.P_N_PAGE; ret(v_counter).p_d_sortie := DS_DT.P_D_SORTIE; ret(v_counter).p_c_cat := DS_DT.P_C_CAT; ret(v_counter).p_c_source := DS_DT.P_C_SOURCE; ret(v_counter).c_error := DS_DT.C_ERROR; FOR SM IN SEL_MEDIC(p_num_doss) LOOP ret_med(v_counter_med).code_medic := SM.CODE_MEDIC; ret_med(v_counter_med).nombre := SM.NOMBRE; v_counter_med := v_counter_med +1; END LOOP; FOR SI IN SEL_INP(p_num_doss) LOOP ret_inp(v_counter_inp).code_inp := SI.CODE_INP; v_counter_inp := v_counter_inp +1; END LOOP; ret(v_counter).p_tab_medic := ret_med; ret(v_counter).p_tab_inp := ret_inp; v_counter := v_counter + 1; END LOOP; return ret; END; END consult_trac; / Types: create or replace TYPE MEDIC AS OBJECT ( num_doss VARCHAR2(9), code_medic VARCHAR2(10), nombre NUMBER); create or replace TYPE tab_medic IS TABLE OF MEDIC; create or replace TYPE INP AS OBJECT ( num_doss VARCHAR2(9), code_inp VARCHAR2(20)); create or replace TYPE tab_INP IS TABLE OF INP; create or replace TYPE TYP_DOS_AMO AS OBJECT ( num_doss VARCHAR2(9), dat_dep DATE, num_imma VARCHAR2(13), num_ind VARCHAR2(20), p_date_acte DATE, code_evop VARCHAR2(20), lib_evop VARCHAR2(30), code_dr VARCHAR2(20), lib_dr VARCHAR2(30), c_user VARCHAR2(20), c_gence VARCHAR2(20), c_niv VARCHAR2(20), l_niv VARCHAR2(20), dat_sui DATE, c_d_etat VARCHAR2(20), l_d_etat VARCHAR2(20), l_nat VARCHAR2(30), num_recom VARCHAR2(30), accuse VARCHAR2(30), p_montant VARCHAR2(20), num_d_parent VARCHAR2(9), p_INP_dos VARCHAR2(20), p_ICE_dos VARCHAR2(20), p_cin VARCHAR2(10), p_nom VARCHAR2(20), p_prenom VARCHAR2(20), p_n_page VARCHAR2(20), p_d_sortie DATE, p_c_cat VARCHAR2(15), p_c_source VARCHAR2(15), p_tab_medic tab_medic, p_tab_inp tab_inp, c_error INTEGER ); create or replace TYPE tab_INP IS TABLE OF INP;
A nested table object is not the same as an associative array, so it must be initialised before usage. Thus ret tab_dos_t_amo probably needs to be ret tab_dos_t_amo := tab_dos_t_amo(); Now as you want to add elements to it, you need to add an index to the array, for example ret.extend; which now allows you to reference ret(1). You didn't show us the definition for tab_dos_t_amo but I assume it is a table of dos_t_amo. So each entry in that table is an object, which means your code: ret(v_counter).num_doss := DS_DT.NUM_DOSS; ret(v_counter).dat_dep := DS_DT.DAT_DEP; ret(v_counter).num_imma := DS_DT.NUM_IMMA; would now look like ret.extend; ret(v_counter) := dos_t_amo( DS_DT.DAT_DEP, DS_DT.NUM_IMMA, ... ...);
How I can fix "PL/SQL: numeric or value error%s"?
I'm trying to write a procedure. When we query this procedure with id no, the tables will be joined and the results will be as follows; (PROCEDURE_NAME: "student_information") id_no, name, surname, school_number, department_information, city, lesson Here are my tables and procedure code; CREATE TABLE student_info ( school_number NUMBER, id_no NUMBER NOT NULL UNIQUE, name VARCHAR2(50) NOT NULL, surname VARCHAR2(50) NOT NULL, city VARCHAR2(50) NOT NULL, birth_date DATE NOT NULL, CONSTRAINT student_info_pk PRIMARY KEY (okul_numarasi) ); CREATE TABLE school_info ( school_number NUMBER, entry_date DATE NOT NULL, faculty_info VARCHAR2(50) NOT NULL, department_information VARCHAR2(50) NOT NULL, CONSTRAINT school_info_pk PRIMARY KEY (school_number), CONSTRAINT student_school_fk FOREIGN KEY (school_number) REFERENCES student_info(school_number) ); CREATE TABLE lessons( school_number NUMBER, lesson_name VARCHAR2(100) NOT NULL, lesson_number NUMBER NOT NULL, midterm_1 NUMBER, midterm_2 NUMBER, final_note NUMBER, integration_note NUMBER, CONSTRAINT lessons_pk PRIMARY KEY (school_number), CONSTRAINT lessons_student_fk FOREIGN KEY (school_number) REFERENCES ogrenci_bilgileri (okul_numarasi) ); CREATE OR REPLACE PROCEDURE student_information( p_no IN student_info.id_no%type, p_name OUT student_info.name%type, p_surname OUT student_info.surname%type, p_school_number OUT student_info.school_number%type, p_department_information OUT school_info.department_information%type, p_city OUT student_info.city%type, p_lesson OUT lessons.lesson_name%type ) AS BEGIN SELECT o.name, o.surname, o.school_number, ok.department_information, o.city, d.lesson_name INTO p_name, p_surname, p_school_number, p_city, p_department_information, p_lesson FROM student_info o JOIN school_info ok ON o.school_info = ok.school_number JOIN lessons d ON d.school_number = ok.school_number; WHERE o.id_no = p_no; END student_information; And here is my declare to run the procedure. DECLARE v_id student_info.id_no%type:= 12345; v_name student_info.name%type; v_surname student_info.surname%type; v_school_num student_info.school_number%type; v_department school_info.department_information%type; v_city student_info.city%type; v_lesson lessons.lesson_name%type; BEGIN student_information(v_id,v_name,v_surname,v_school_num,v_department,v_city, v_lesson ); DBMS_OUTPUT.put_line ('Student Information'); DBMS_OUTPUT.put_line ('ID: ' || v_id); DBMS_OUTPUT.put_line ('Name: ' || v_name || ' ' || v_surname); DBMS_OUTPUT.put_line ('School Number: ' || v_school_num); DBMS_OUTPUT.put_line ('Department Information: ' || v_department); DBMS_OUTPUT.put_line ('City: ' || v_city); DBMS_OUTPUT.put_line ('Lesson Name:' || v_lesson); END; The error is: ORA-06502: PL / SQL: numerical or value error: character-to-number error ORA-06512: location "SYSTEM.student_information", line 12 ORA-06512: location line 10 06502. 00000 - "PL/SQL: numeric or value error%s" *Cause: An arithmetic, numeric, string, conversion, or constraint error occurred. For example, this error occurs if an attempt is made to assign the value NULL to a variable declared NOT NULL, or if an attempt is made to assign an integer larger than 99 to a variable declared NUMBER(2). *Action: Change the data, how it is manipulated, or how it is declared so that values do not violate constraints.
Simple mismatch on your columns SELECT o.name, o.surname, o.school_number, ok.department_information, <=== o.city, <=== d.lesson_name INTO p_name, p_surname, p_school_number, p_city, <=== p_department_information, <=== p_lesson but before you slap your head and think you've wasted your time, the changes you have made (to using %TYPE etc) have made your code so much more robust and maintainable.
Returning Object Type from Oracle Procedure by partially populating it?
I have created an Object Type in Oracle as below: CREATE OR REPLACE TYPE Generic_MDMU_Scrub_Cols_OBJ as Object ( i_strTypeOfEntry varchar2(50), ID_SCRUB number, NM_DATA_COL1 varchar2(50), NM_DATA_COL2 varchar2(50), NM_DATA_COL3 varchar2(50), NM_DATA_COL4 varchar2(50), NM_DATA_COL5 varchar2(50), NM_DATA_COL6 varchar2(50), NM_DATA_COL7 varchar2(50), NM_DATA_COL8 varchar2(50), NM_DATA_COL9 varchar2(50), NM_DATA_COL10 varchar2(50), NM_DATA_COL11 varchar2(50), NM_DATA_COL12 varchar2(50), NM_DATA_COL13 varchar2(50), NM_DATA_COL14 varchar2(50), NM_DATA_COL15 varchar2(50), NM_DATA_COL16 varchar2(50), NM_DATA_COL17 varchar2(50), NM_DATA_COL18 varchar2(50), NM_DATA_COL19 varchar2(50), NM_DATA_COL20 varchar2(50), DATA_VAL1 varchar2(50), DATA_VAL2 varchar2(50), DATA_VAL3 varchar2(50), DATA_VAL4 varchar2(50), DATA_VAL5 varchar2(50), DATA_VAL6 varchar2(50), DATA_VAL7 varchar2(50), DATA_VAL8 varchar2(50), DATA_VAL9 varchar2(50), DATA_VAL10 varchar2(50), DATA_VAL11 varchar2(50), DATA_VAL12 varchar2(50), DATA_VAL13 varchar2(50), DATA_VAL14 varchar2(50), DATA_VAL15 varchar2(50), DATA_VAL16 varchar2(50), DATA_VAL17 varchar2(50), DATA_VAL18 varchar2(50), DATA_VAL19 varchar2(50), DATA_VAL20 varchar2(50), OLD_DATA_VAL1 varchar2(50), OLD_DATA_VAL2 varchar2(50), OLD_DATA_VAL3 varchar2(50), OLD_DATA_VAL4 varchar2(50), OLD_DATA_VAL5 varchar2(50), OLD_DATA_VAL6 varchar2(50), OLD_DATA_VAL7 varchar2(50), OLD_DATA_VAL8 varchar2(50), OLD_DATA_VAL9 varchar2(50), OLD_DATA_VAL10 varchar2(50), OLD_DATA_VAL11 varchar2(50), OLD_DATA_VAL12 varchar2(50), OLD_DATA_VAL13 varchar2(50), OLD_DATA_VAL14 varchar2(50), OLD_DATA_VAL15 varchar2(50), OLD_DATA_VAL16 varchar2(50), OLD_DATA_VAL17 varchar2(50), OLD_DATA_VAL18 varchar2(50), OLD_DATA_VAL19 varchar2(50), OLD_DATA_VAL20 varchar2(50) ); / Now I want to write a Procedure which returns this Object Type as the output parameter to the calling Java code. Basically there are couple of tables which store columns like OLD_DATA_VAL1...OLD_DATA_VAL20 and DATA_VAL1...DATA_VAL120 and similarly another table having columns NM_DATA_COL1...NM_DATA_COL20 and depending on various use cases only 3 or 5 or any number of columns will have values and other would be null. Eg- OLD_DATA_VAL1,OLD_DATA_VAL2,OLD_DATA_VAL3,DATA_VAL1,DATA_VAL2,DATA_VAL3,NM_DATA_COL1,NM_DATA_COL2,NM_DATA_COL3 have values and other columns are null. I have created a meta table which would give me comma separated column names. Now when I try using type or cursor, the problem is since all the values are not populated it throws error. My procedure is something like this: create or replace PROCEDURE METADATA_AUTOMATION_MDPR ( in_id_scrub IN NUMBER ) AS V_COL_NAMES_CURRENT_SCRUB_DATA VARCHAR2(500); V_COL_NAMES_OLD_SCRUB_DATA VARCHAR2(500); V_COL_HEADER_MAP_WORKFLOW VARCHAR2(500); sqlstmt VARCHAR2(2000); V_Generic_MDMU_Scrub_Cols Generic_MDMU_Scrub_Cols_OBJ; SELECT COL_NAMES_CURRENT_SCRUB_DATA, COL_NAMES_OLD_SCRUB_DATA, COL_HEADER_MAP_WORKFLOW INTO V_COL_NAMES_CURRENT_SCRUB_DATA, V_COL_NAMES_OLD_SCRUB_DATA, V_COL_HEADER_MAP_WORKFLOW FROM MDDBO.MDMU_METADATA_AUTOMATION_MDTB WHERE ID_WORKFLOW_MAINTENANCE_MSTR = in_id_wf; DBMS_OUTPUT.PUT_LINE(V_COL_NAMES_CURRENT_SCRUB_DATA || ' --- ' || V_COL_NAMES_OLD_SCRUB_DATA || ' --- ' || V_COL_HEADER_MAP_WORKFLOW); sqlstmt:= 'select ' || V_COL_NAMES_CURRENT_SCRUB_DATA || ',' || V_COL_NAMES_OLD_SCRUB_DATA || ',' || V_COL_HEADER_MAP_WORKFLOW || ',AUTO.TYPE_OF_ENTRY i_strTypeOfEntry FROM MDDBO.MDMU_SCRUB_DATA_MDTB DATA, MDDBO.MDMU_SCRUB_LOG_MDTB MSTR, MDDBO.MDMU_MAP_WORK_FLOW_MDTB WKF, MDDBO.MDMU_METADATA_AUTOMATION_MDTB AUTO WHERE MSTR.ID_TBL = WKF.ID_WF and MSTR.id_scrub = :in_id_scrub and MSTR.id_scrub = DATA.id_scrub and AUTO.ID_WORKFLOW_MAINTENANCE_MSTR = WKF.ID_WF'; DBMS_OUTPUT.PUT_LINE(sqlstmt); EXECUTE IMMEDIATE sqlstmt INTO V_Generic_MDMU_Scrub_Cols USING in_id_scrub; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('error '||sqlerrm); END METADATA_AUTOMATION_MDPR; But it throws Oracle error like below in case of type- error ORA-00932: inconsistent datatypes: expected - got - Some Oracle Guy suggested using Global Temporary Table (GTT) but I believe they are common for all the sessions and are not viable here. So, if I want to partially populate but I am not sure if thats the best case here or something can be done with object like partially initializing unused values to null. UPDATE Printing the dbms_ouput from the 2 statements to make thing clearer Output1: DATA_VAL1,DATA_VAL2,DATA_VAL3,DATA_VAL4,DATA_VAL5 --- OLD_DATA_VAL1,OLD_DATA_VAL2,OLD_DATA_VAL3,OLD_DATA_VAL4,OLD_DATA_VAL5 --- NM_DATA_COL1,NM_DATA_COL2,NM_DATA_COL3,NM_DATA_COL4,NM_DATA_COL5 Output2: select DATA_VAL1,DATA_VAL2,DATA_VAL3,DATA_VAL4,DATA_VAL5,OLD_DATA_VAL1,OLD_DATA_VAL2,OLD_DATA_VAL3,OLD_DATA_VAL4,OLD_DATA_VAL5,NM_DATA_COL1,NM_DATA_COL2,NM_DATA_COL3,NM_DATA_COL4,NM_DATA_COL5,AUTO.TYPE_OF_ENTRY i_strTypeOfEntry FROM MDDBO.MDMU_SCRUB_DATA_MDTB DATA, MDDBO.MDMU_SCRUB_LOG_MDTB MSTR, MDDBO.MDMU_MAP_WORK_FLOW_MDTB WKF, MDDBO.MDMU_METADATA_AUTOMATION_MDTB AUTO WHERE MSTR.ID_TBL = WKF.ID_WF and MSTR.id_scrub = :in_id_scrub and MSTR.id_scrub = DATA.id_scrub and AUTO.ID_WORKFLOW_MAINTENANCE_MSTR = WKF.ID_WF Main Issue - Having fewer dynamically selected columns compared to the number of columns in the Object Type. (See Output 1, there can be 3 each also) Update 2 Now my main concern is how to get the values from the dynamic sql formed with variable number of selected columns. Using below query I am able to get the column headers but somehow not able to get the col values. My query would return only one row- OPEN rc_ FOR sqlstmt using in_id_scrub; c_ := DBMS_SQL.to_cursor_number(rc_); DBMS_SQL.DESCRIBE_COLUMNS(c_, col_count_, desc_tab_); FOR i_ IN 1..col_count_ LOOP DBMS_OUTPUT.PUT_LINE(desc_tab_(i_).col_name); DBMS_SQL.DEFINE_COLUMN(c_, i_, desc_tab_(i_).COL_NAME, 2000); END LOOP; res := DBMS_SQL.EXECUTE_AND_FETCH(c_, TRUE); --DBMS_OUTPUT.PUT_LINE(res); FOR i IN 1..col_count_ LOOP tab1.EXTEND; DBMS_SQL.COLUMN_VALUE(c_, i, tab1(tab1.LAST)); --DBMS_SQL.COLUMN_VALUE(c_, i, tab1(i)); --DBMS_SQL.COLUMN_VALUE(c_, i, arr1); --DBMS_OUTPUT.PUT_LINE(tab1(1)); END LOOP; DBMS_SQL.CLOSE_CURSOR(c_); FOR l_row IN 1 .. tab1.COUNT LOOP DBMS_OUTPUT.put_line (tab1 (l_row)); END LOOP;
Your specific problem here seems to be this line: sqlstmt:= 'select ' || V_COL_NAMES_CURRENT_SCRUB_DATA || ',' || V_COL_NAMES_OLD_SCRUB_DATA || ',' || V_COL_HEADER_MAP_WORKFLOW || ',AUTO.TYPE_OF_ENTRY i_strTypeOfEntry FROM MDDBO.MDMU_SCRUB_DATA_MDTB DATA, MDDBO.MDMU_SCRUB_LOG_MDTB MSTR, MDDBO.MDMU_MAP_WORK_FLOW_MDTB WKF, MDDBO.MDMU_METADATA_AUTOMATION_MDTB AUTO WHERE MSTR.ID_TBL = WKF.ID_WF and MSTR.id_scrub = :in_id_scrub and MSTR.id_scrub = DATA.id_scrub and AUTO.ID_WORKFLOW_MAINTENANCE_MSTR = WKF.ID_WF'; ...as I understand it, because e.g. V_COL_NAMES_CURRENT_SCRUB_DATA might be null? In that case a simple NVL should suffice: sqlstmt:= 'select ' || NVL(V_COL_NAMES_CURRENT_SCRUB_DATA, 'null as col1') || ... So now instead of: select ,,SOMECOL,... you would get: select null as col1, null as col2, SOMECOL, ...
ORA12899 - creating a function which inserts boolean parameter
I have the following function within a package: FUNCTION FUN_GUARDAR_ENCUESTA( P_CENCUESTA IN VARCHAR2, P_XENCUESTA IN VARCHAR2, P_IHOME IN NUMBER, P_BACTIVO IN CHAR, P_MENSAJE OUT VARCHAR2 ) RETURN VARCHAR2 IS v_codigo_error VARCHAR2(200); BEGIN INSERT INTO INC_ENCUESTAS(CENCUESTA, XENCUESTA, IHOME, BACTIVO) VALUES(P_CENCUESTA, P_XENCUESTA, P_IHOME, P_BACTIVO); p_mensaje := 'Transacción Exitosa'; v_codigo_error := '000'; RETURN v_codigo_error; EXCEPTION WHEN OTHERS THEN v_codigo_error := SQLCODE; p_mensaje := substr(SQLERRM, 1, 200); END FUN_GUARDAR_ENCUESTA; but, whenever I test it it just the next error: ORA-12899: the value is too large for column "INTRANETCORP"."INC_ENCUESTAS"."BACTIVO" (actual: 200, máximum: 1) My table schema is this COLUMN NAME DATA_TYPE CENCUESTA NUMBER(8,0) XENCUESTA VARCHAR2(255 BYTE) IHOME VARCHAR2(5 BYTE) BACTIVO CHAR(1 BYTE) I'm passing 0 as a value using a callableStatement with this query string String query = "{ ? = call PKG_ENC_UTIL.FUN_GUARDAR_ENCUESTA()}";