Response row size overflow (9804) error - teradata

i am executing below query in teradata 14.0
SELECT oreplace(CAST(RULE_ID AS VARCHAR(1000)),' ','') RULE_ID,
oreplace(CAST(PHASE_ID AS VARCHAR(1000)),' ','') PHASE_ID,
oreplace(CAST(TARGET_TABLE_NAME AS VARCHAR(1000)),' ','') TARGET_TABLE_NAME,
oreplace(CAST(AUDIT_TABLE_NAME AS VARCHAR(1000)),' ','') AUDIT_TABLE_NAME,
oreplace(CAST(PROC_NAME AS VARCHAR(1000)),' ','') PROC_NAME,
oreplace(CAST(ACTIVE_START_DT AS VARCHAR(1000)),' ','') ACTIVE_START_DT,
oreplace(CAST(ACTIVE_END_DT AS VARCHAR(1000)),' ','') ACTIVE_END_DT,
oreplace(CAST(ACTIVE_IND AS VARCHAR(1000)),' ','') ACTIVE_IND,
oreplace(CAST(WRITE_AUDIT_IND AS VARCHAR(1000)),' ','') WRITE_AUDIT_IND,
oreplace(CAST(SCENARIO_TYPE AS VARCHAR(1000)),' ','') SCENARIO_TYPE,
oreplace(CAST(RULE_ORDER AS VARCHAR(1000)),' ','') RULE_ORDER
FROM table
When i execute this query, 9804 (response row size overflow) is received.
Charaterset used : ASCII

The resulting datatype of oReplace is a VarChar(8000) you must CAST the result of the function, not the parameter:
CAST(oreplace(PROC_NAME,' ','') AS VARCHAR(1000)) AS PROC_NAME,
But why do you want to remove all spaces? If there are trailing spaces you can simply TRIM them.

Related

Create index if not exist

ALL,
SQL> SELECT 1 FROM all_indexes WHERE table_name = UPPER( 'abcatcol' ) AND index_name = UPPER( 'abcatcol_tnam_ownr_cnam' );
no rows selected
SQL> CREATE INDEX abcatcol_tnam_ownr_cnam ON abcatcol(abc_tnam, abc_ownr, abc_cnam);
CREATE INDEX abcatcol_tnam_ownr_cnam ON abcatcol(abc_tnam, abc_ownr, abc_cnam)
*
ERROR at line 1:
ORA-01408: such column list already indexed
SQL> SELECT 1 FROM all_indexes WHERE table_name = UPPER( 'abcatcol' );
1
----------
1
SQL> SELECT index_name FROM all_indexes WHERE table_name = UPPER( 'abcatcol' );
INDEX_NAME
------------------------------
SYS_C007087
SQL >
What am I missing? Why can't I create an index?
EDIT:
SQL> select index_name, listagg(column_name, ', ') within group(order by 1)-- over(partition by index_name)
2 from dba_ind_columns
3 where table_name = 'ABCATCOL'
4 group by index_name;
INDEX_NAME
------------------------------
LISTAGG(COLUMN_NAME,',')WITHINGROUP(ORDERBY1)--OVER(PARTITIONBYINDEX_NAME)
--------------------------------------------------------------------------------
SYS_C007087
ABC_CNAM, ABC_OWNR, ABC_TNAM
SQL> SELECT index_name FROM all_indexes WHERE table_name = UPPER( 'abcatcol' );
INDEX_NAME
------------------------------
SYS_C007087
SQL>
EDIT2:
The suggested question utilizes PL/SQL. I want to understand how to do that using standard SQL and why my queries do not work as expected.
EDIT3:
This is the table definition:
CREATE TABLE abcatcol(abc_tnam char(129) NOT NULL, abc_tid integer, abc_ownr char(129) NOT NULL, abc_cnam char(129) NOT NULL, abc_cid smallint, abc_labl char(254), abc_lpos smallint, abc_hdr char(254), abc_hpos smallint, abc_itfy smallint, abc_mask char(31), abc_case smallint, abc_hght smallint, abc_wdth smallint, abc_ptrn char(31), abc_bmap char(1), abc_init char(254), abc_cmnt char(254), abc_edit char(31), abc_tag char(254), PRIMARY KEY( abc_tnam, abc_ownr, abc_cnam ));
So I guess since those fields are part of the PK Otacle already made the index, right?
You are looking for an index by it's name whereas oracle says to you this set of columns has been already indexed.
It means there is already an index with another name over that column set.
You need to check against dba_ind_columns table to get the index name over that column set
UPD. Here is the query to help you out to find the columns indexed
select index_name, listagg(column_name, ', ') within group(order by 1)-- over(partition by index_name)
from dba_ind_columns
where table_name = 'TABLE_NAME'
group by index_name;

Use cursor in LOOP in new QUERY

"I missing the forest through the trees..."
I want to query each column of a table which I retrieve in a FOR LOOP, but the inner query doesn't return the right thing.
Seems that the inner query not use the current column_name.
DECLARE
v_max_TS TIMESTAMP;
BEGIN
FOR cols IN (SELECT column_name FROM all_tab_cols WHERE table_name = '<tablename>')
LOOP
SELECT
MAX(CURR_TIMESTAMP) INTO v_max_TS
FROM <tablename>
WHERE cols.column_name IS NOT NULL
ORDER BY TO_TIMESTAMP(CURR_TIMESTAMP,'MM/DD/YYYY HH24:MI:SS') DESC;
dbms_output.put_line(cols.column_name || ' ' || v_max_TS);
END LOOP;
END;
Apart from the fact that your query doesn't make much sense (as Boneist wrote as a comment), that won't work as you need to use dynamic SQL (execute immediate) for such a purpose.
Here's an example based on Scott's schema. Have a look, adjust it if necessary.
SQL> set serveroutput on
SQL> declare
2 l_str varchar2(200); -- will hold the SELECT statement
3 v_max varchar2(30);
4 begin
5 for cols in (select column_name
6 from all_tab_cols
7 where table_name = 'DEPT'
8 )
9 loop
10 l_str := 'select max(' || cols.column_name ||') from dept';
11 execute immediate l_str into v_max;
12 dbms_output.put_line(cols.column_name ||': '|| v_max);
13 end loop;
14 end;
15 /
DEPTNO: 40
DNAME: SALES
LOC: NEW YORK
PL/SQL procedure successfully completed.
SQL>

Getting error :Error(2,3): PL/SQL: SQL Statement ignored Error(8,5): PL/SQL: ORA-00984: column not allowed here

My code is like below.
create table XXINF_DB_OBJECT_DDL_LOG (
EVENT_DATE DATE NOT NULL,
EVENT_TIMESTAMP TIMESTAMP NOT NULL,
EVENT_TYPE VARCHAR2(30) NOT NULL,
OBJECT_TYPE VARCHAR2(30) NOT NULL,
OBJECT_OWNER VARCHAR2(30) NOT NULL,
OBJECT_NAME VARCHAR2(30) NOT NULL,
DB_USER VARCHAR2(30) NOT NULL,
OS_USER VARCHAR2(100) ,
HOST_NAME VARCHAR2(100),
HOST_IP_ADDRESS VARCHAR2(30)
);
create or replace trigger XXINF_DB_OBJECT_DDL_LOG_AUDIT
AFTER DDL ON schema
begin
insert into XXINF_DB_OBJECT_DDL_LOG values(
sysdate,
systimestamp,
ora_sysevent,
ora_dict_obj_type,
ora_dict_obj_owner,
ora_dict_odj_name,
ora_login_user,
SYS_CONTEXT('USERENV','OS_USER'),
SYS_CONTEXT('USERENV','TERMINAL'),
SYS_CONTEXT('USERENV','IP_ADDRESS')
);
END;
/
when I execute get error:
Error(2,3): PL/SQL: SQL Statement ignored Error(8,5): PL/SQL:
ORA-00984: column not allowed here
Please use the corrections as below:
create or replace trigger XXINF_DB_OBJECT_DDL_LOG_AUDIT
AFTER DDL ON SCHEMA
begin
insert into XXINF_DB_OBJECT_DDL_LOG
(
EVENT_DATE,
EVENT_TIMESTAMP,
EVENT_TYPE,
OBJECT_TYPE,
OBJECT_OWNER,
OBJECT_NAME,
DB_USER,
OS_USER,
HOST_NAME,
HOST_IP_ADDRESS
)
values
(
sysdate,
systimestamp,
ora_sysevent,
ora_dict_obj_type ,
ora_dict_obj_owner,
ora_dict_obj_name ,
ora_login_user ,
SYS_CONTEXT('USERENV','OS_USER'),
SYS_CONTEXT('USERENV','TERMINAL'),
SYS_CONTEXT('USERENV','IP_ADDRESS') );
END;
/

Create table and then insert data into the new table from another table

I am creating one table name emp_inforamtion with checking that table is exist in database or not ,and if not then creating table then inserting the data from bank table in to emp_information table.
DECLARE
ncount NUMBER;
v_sql VARCHAR2(4000);
CURSOR c1
IS
SELECT bank_code,
center_code,
bank_name,
logo
FROM bank
WHERE bank_code ='607143';
BEGIN
SELECT COUNT(1) INTO ncount FROM tab WHERE tname LIKE '%EMP_INFORMATION%';
IF (ncount <= 0) THEN
DBMS_OUTPUT.PUT_LINE (ncount || 'count');
BEGIN
v_sql :=' CREATE TABLE EMP_INFORMATION
(
emp_id VARCHAR2(3),
emp_name VARCHAR2(20),
emp_salary VARCHAR2(3),
emp_department VARCHAR2(3)
)';
EXECUTE immediate v_sql;
COMMIT;
BEGIN
FOR i IN c1
LOOP
INSERT
INTO EMP_INFORMATION
(
emp_id,
emp_name,
emp_salary,
emp_department
)
VALUES
(
i.bank_code,
i.bank_name,
i.center_code,
i.logo
);
END LOOP;
END;
END;
END IF;
end;
/
found below error after executing the above cursor:
ORA-06550: line 30, column 16: PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 29, column 11: PL/SQL: SQL Statement ignored
When you create a table using execute immediate in an anonymous block, use execute immediate to insert the data into it.
DECLARE
ncount NUMBER;
v_sql VARCHAR2(4000);
CURSOR c1
IS
SELECT bank_code,
center_code,
bank_name,
logo
FROM bank
WHERE bank_code ='607143';
BEGIN
SELECT COUNT(1) INTO ncount FROM tab WHERE tname LIKE '%EMP_INFORMATION%';
IF (ncount <= 0) THEN
DBMS_OUTPUT.PUT_LINE (ncount || 'count');
BEGIN
v_sql :=' CREATE TABLE EMP_INFORMATION
(
emp_id VARCHAR2(3),
emp_name VARCHAR2(20),
emp_salary VARCHAR2(3),
emp_department VARCHAR2(3)
)';
EXECUTE IMMEDIATE v_sql;
BEGIN
FOR i IN c1
LOOP
EXECUTE IMMEDIATE 'INSERT
INTO EMP_INFORMATION
(
emp_id,
emp_name,
emp_salary,
emp_department
)
VALUES
(
:a,
:b,
:c,
:d
)' using i.bank_code, i.bank_name, i.center_code, i.logo;
END LOOP;
END;
END;
END IF;
end;
/

SQLiteMetro Group by

Is Group by clause supported by this lib?
I wrote query Select SectionName, DepartmentName, SUM(SalesValue) FROM ( SELECT SectionName, Date, DepartmentName, SalesValue FROM StockDaily join Section on StockDaily.idSection=Section._id join Department on StockDaily.idDepartment = Department._id where idStore=1 and Date >=" + '"' + from + '"' + "and Date <=" + '"' + to + '"' + ")"+" Group by SectionName
It works in sqlite manager but in cod with lib not:/ Do you have any ideas?
Yes, sqlite supports GROUP BY aggregation. Here is the reference.

Resources