"ORA-22992: cannot use LOB locators selected from remote tables " - sql

I have a query in oracle 19 which works fine:
select a.x,
b.y
from tab1#dblink a
join tab2#dblink b
on a.x = b.y
But when I create a view from this query, I have the error - "ORA-22992: cannot use LOB locators selected from remote tables".
Columns x and y are varchar2 not lobs.
Tables:
CREATE TABLE tab1
(
x VARCHAR2(4000 BYTE),
x2 CLOB,
x3 VARCHAR2(100 BYTE)
),
CREATE TABLE tab2
(
y VARCHAR2(4000 BYTE),
y2 CLOB,
y3 VARCHAR2(100 BYTE)
)
Do you have any idea why I have this error?
I want to know why query works fine and view doesn't.

Related

Using Right() or Substr() in an UPDATE statement

I have two tables :
Add_T
Add_ID NUMBER(10,0)
Add_GEOMETRY SDO_GEOMETRY
STRTN VARCHAR2(40 BYTE)
CITY VARCHAR2(45 BYTE)
STATE VARCHAR2(2 BYTE)
ZIPCODE VARCHAR2(10 BYTE)
HC_ID NUMBER(10,0)
P_ID NUMBER(10,0)
Second Table :
HC_T
HC_GEOMETRY SDO_GEOMETRY
HC_ID NUMBER(10,0)
TYPE VARCHAR2(2 BYTE)
FACY NUMBER(10,0)
COORD_X NUMBER(15,0)
COORD_Y NUMBER(15,0)
I need to update the field HC_ID of Add_T Table and I use the following SQL statement:
update add_t set hc_Id = ( SELECT HC_ID FROM HC_T
WHERE ADD_T.P_ID = HC_T.FACY AND
HCO_T.TYPE='R' ) WHERE hc_ID IS NULL and
subtr(strtn,-4,4) = "-LOC"
It doesn't work. Also, I used the right() function and also got incorrect results.
update add_t set hc_Id = ( SELECT HC_ID FROM HC_T
WHERE ADD_T.P_ID = HC_T.FACY AND
HCO_T.TYPE='R' ) WHERE hc_ID IS NULL and
RIGHT(strtn,4) = "-LOC"
Could anyone say where is the mistake?
Looks like you need the last 4 characters of a string. If so, then you'd
UPDATE add_t
SET hc_id =
(SELECT hc_id
FROM hc_t
WHERE add_t.p_id = hc_t.facy
AND hco_t.TYPE = 'R')
WHERE hc_id IS NULL
AND SUBSTR (strtn, -4) = '-LOC';
because e.g.
SQL> SELECT SUBSTR ('some string', -4) FROM DUAL;
SUBS
----
ring
SQL>
(Note also that you'd enclose strings into single quotes in Oracle, not double ones (as you tried with the "-LOC" string).

select query with PL/SQL

I ran this PL/SQL script, I want to store this PL/SQL in a procedure so that I would give it one parameter and returns info about that parameter, for now I ran it separately outside the procedure but I get the following error, please your help :
error signaled in parallel query server
declare
a VARCHAR2(100 CHAR);
b VARCHAR2(30 CHAR);
c VARCHAR2(50 CHAR);
d VARCHAR2(30 CHAR);
e VARCHAR2(100);
f VARCHAR2(30 CHAR);
BEGIN
SELECT
col1 ,
col2,
col3,
col4,
col5,
col6,
INTO
a,
b,
c,
d,
e,
f
FROM
MY_TABLE
WHERE
col1= 123;
dbms_output.put_line(a||','||b||','||c||','||d||','||e||','||f);
END;
There is a misplaced comma (,) after col6. Remove it the code will work:
declare
a VARCHAR2(100 CHAR);
b VARCHAR2(30 CHAR);
c VARCHAR2(50 CHAR);
d VARCHAR2(30 CHAR);
e VARCHAR2(100);
f VARCHAR2(30 CHAR);
BEGIN
SELECT
col1 ,
col2,
col3,
col4,
col5,
col6,
INTO
a,
b,
c,
d,
e,
f
FROM
MY_TABLE
WHERE
col1= 123;
dbms_output.put_line(a||','||b||','||c||','||d||','||e||','||f);
END;
If you want to create a procedure then here goes the code:
declare
a VARCHAR2(100 CHAR);
b VARCHAR2(30 CHAR);
c VARCHAR2(50 CHAR);
d VARCHAR2(30 CHAR);
e VARCHAR2(100);
f VARCHAR2(30 CHAR);
BEGIN
SELECT
col1 ,
col2,
col3,
col4,
col5,
col6
INTO
a,
b,
c,
d,
e,
f
FROM
MY_TABLE
WHERE
col1= 123;
dbms_output.put_line(a||','||b||','||c||','||d||','||e||','||f);
END;
I really was stuck on this, but this is my final answer as the query returns more than one row, and it works just fine.
CREATE OR REPLACE PROCEDURE my_fun
(
PARAM1 IN VARCHAR2
) AS
ref_curs SYS_REFCURSOR;
a VARCHAR2(100 CHAR);
b VARCHAR2(30 CHAR);
c VARCHAR2(50 CHAR);
d VARCHAR2(30 CHAR);
e VARCHAR2(100);
f VARCHAR2(30 CHAR);
BEGIN
OPEN ref_curs FOR
SELECT
col1 ,
col2,
col3,
col4,
col5,
col6
FROM
my_table
WHERE
col1= = PARAM1 ;
DBMS_OUTPUT.PUT_LINE('col1 ,col2,col3,col4,col5,col6');
LOOP
FETCH ref_curs INTO a,b,c,d,e,f;
EXIT WHEN ref_curs%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(a||','|| b||','||c||','||d||','||e||','||f);
END LOOP;
CLOSE ref_curs;
END my_fun;

Inserting a Date data

so I have this table
RPG_RETCON (
UNIQUE_ID VARCHAR2(100 BYTE),
CONTAINER VARCHAR2(100 BYTE),
DATA_POINT_NAME VARCHAR2(100 BYTE),
SOURCE_VALUE VARCHAR2(100 BYTE),
CSS_VALUE VARCHAR2(100 BYTE),
STATUS VARCHAR2(100 BYTE)
)
And I I'm trying to insert this select statement into that table.
INSERT INTO RPG_RETCON
(SELECT A.POOL_CUSIP_ID AS UNIQUE_ID,
'1_13_1C' AS CONTAINER,
'SECU_ACTL_STLM_DT' AS COLUMN_NAME1,
TO_CHAR(A.SECU_ACTL_STLM_DT),
TO_CHAR(B.SECU_ACTL_STLM_DT),
CASE
WHEN A.SECU_ACTL_STLM_DT = B.SECU_ACTL_STLM_DT
THEN
'PASS'
ELSE
'FAIL'
END
AS STATUS
FROM POOL_1_13_1C_TRGT A
LEFT JOIN POOL_1_13_1C_CSS B ON A.POOL_CUSIP_ID = B.POOL_CUSIP_ID);
Now the problem is that SECU_ACTL_STLM_DT is a date field and when I try to do the inserts, I get an invalid number error. If I take away the TO_CHAR to just A.SECU_ACTL_STLM_DT,
B.SECU_ACTL_STLM_DT,
I get invalid month.
Note: I absolutely cannot change
SOURCE_VALUE VARCHAR2(100 BYTE)
CSS_VALUE VARCHAR2(100 BYTE)
-- Within the table structure...
They need to be VARCHAR2 Data types.
Are there any suggestions to where I can insert this select statement error free?
I think your code should work. However, I would list the columns explicitly and add date formats for the insert. Perhaps this will help:
INSERT INTO RPG_RETCON(UNIQUE_ID, CONTAINER, COLUMN_NAME1, SOURCE_VALUE, CSS_VALUE, STATUS)
SELECT A.POOL_CUSIP_ID AS UNIQUE_ID, '1_13_1C' AS CONTAINER,
'SECU_ACTL_STLM_DT' AS COLUMN_NAME1,
TO_CHAR(A.SECU_ACTL_STLM_DT, 'YYYY-MM-DD'),
TO_CHAR(B.SECU_ACTL_STLM_DT, 'YYYY-MM-DD'),
(CASE WHEN A.SECU_ACTL_STLM_DT = B.SECU_ACTL_STLM_DT
THEN 'PASS'
ELSE 'FAIL'
END) AS STATUS
FROM POOL_1_13_1C_TRGT A LEFT JOIN
POOL_1_13_1C_CSS B
ON A.POOL_CUSIP_ID = B.POOL_CUSIP_ID;
It is possible that one of the SECU_ACTL_STLM_DT columns is not a date and the comparison is failing.

Extract data from flat file to a table

I'm using Oracle database 9i.
I want to extract data from flat file(.txt) then insert them into a table (on the client) using other than sql_loader, utl_file, external table, sqldeveloper, toad.
Example of flat file source :
Allain Analyst 13456...
King manager 98768 ...
This extracts data from file_name.csv file and inserts it into EX_TABLE
create table EX_TABLE(
COL1 varchar2(13 BYTE)
,COL2 varchar2(250 CHAR)
,COL3 varchar2(210 CHAR)
,COL4 varchar2(70 CHAR)
)
organization external
(type oracle_loader
default directory EXT_DIR
access parameters
(
records delimited by newline
fields terminated by ','
missing field values are null
reject rows with all null
fields(COL1 CHAR(13)
,COL2 char(250)
,COL3 char(210)
,COL4 char(70)
)
)
location ('file_name.csv')
)
reject limit unlimited
;
CREATE TABLE EX_TABLE
( COL1 varchar2(3 BYTE)
,COL2 varchar2(3 CHAR)
,COL3 varchar2(1 CHAR)
,COL4 varchar2(10 CHAR)
)
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER
DEFAULT DIRECTORY DAT_DIR
ACCESS PARAMETERS
( RECORDS DELIMITED BY \n
CHARACTERSET JA16SJISTILDE BADFILE BAD_DIR : 'test_%p_%a.bad' LOGFILE LOG_DIR : 'test_%p_%a.log' READSIZE 10485760 FIELDS LRTRIM MISSING FIELD VALUES ARE NULL REJECT ROWS
WITH ALL NULL FIELDS ( COL1 ( 1: 3) CHAR(3) ,COL2 ( 4: 6) CHAR(3) ,COL3 ( 7: 7) CHAR(1) COL4 ( 8: 17) CHAR(10) ))
LOCATION
( 'STS.txt'
)
)
REJECT LIMIT UNLIMITED;
Loading data to external table based on position in the file

ORACLE SQL ORA-22814 attribute or element value is larger than specified in type

I'm calling a function that returns a type of table.
My function receives a variable of the type varchar. Because i return a type that i created i had to make cast and multiset...
My problems is that, the select inside my multiset executes without problem outside of the function, but when i execute my function it gives me ORA-22814 attribute or element value is larger than specified in type error.
NOTE: i always run the script with the same variable value
Type OBJECT:
create or replace
TYPE Z_PEDIDO_SeB IS OBJECT(
Contrato varchar2(4000 BYTE),
DataObjectivo date,
DataObjectivoSpecified date,
Descricao varchar2(500 BYTE),
DireccaoRequerente varchar2(50 BYTE),
Empresa varchar2(50 BYTE),
Estado varchar2(50 BYTE),
GestorDDS varchar2(100 BYTE),
GestorEncomenda varchar2(30 BYTE),
Referencia varchar2(50 BYTE),
Link varchar2(500 BYTE),
ObsComite varchar2(4000 BYTE),
OutrosFornecedores varchar2(4000 BYTE),
OutrosSistAfectados varchar2(4000 BYTE),
PrincipalSistAfectado varchar2(4000 BYTE),
Prioridade varchar2(50 BYTE),
Rede varchar2(50 BYTE),
Requerente varchar2(100 BYTE),
TestesAceitacao varchar2(10 BYTE),
proj_id varchar2(50 BYTE));
Type TABLE:
create or replace
TYPE Z_TABLE_PEDIDO_SeB IS TABLE OF Z_PEDIDO_SeB;
FUNCTION:
create or replace
function Z_GetDadosCreateUpdate_SEB(
proj_id in varchar2
)
return Z_TABLE_PEDIDO_SeB as
t_dados Z_TABLE_PEDIDO_SeB;
begin
select
cast(
multiset(
--STARTS HERE WHAT I RUN WITHOUT PROBLEM OUTSIDE THE FUNCTION
select
(SELECT line_text
from long_text
where key2 = proj_id and key1 = 'contrato'
) Contrato,
NVL(SCHEDULE_FINISH,ACTUAL_FINISH) DataObjectivo,
NVL(SCHEDULE_FINISH,ACTUAL_FINISH) DataObjectivoSpecified,
pedidos.description as Descricao,
costum.direcaorequerente DireccaoRequerente,
costum.empresa Empresa,
estado.description Estado,
costum.gestordds GestorDDS,
(select recursos.description
from structure recursos,
resources,
workflow,
wf_team
where recursos.structure_code = resources.resource_code
and workflow.planning_code = projectos.structure_code
and wf_team.workflow_id = workflow.workflow_id
and wf_team.lifecycle_role_code = '868'
and wf_team.user_name = resources.LOGON_ID
and rownum = 1
) GestorEncomenda,
pedidos.structure_code ID,
(SELECT line_text
from long_text
where key2 = proj_id and key1 = 'urlcadernoreq'
) Link,
(SELECT line_text
from long_text
where key2 = proj_id and key1 = 'observacoescomite'
) ObsComite,
(SELECT line_text
from long_text
where key2 = proj_id and key1 = 'outrosfornecedores'
) OutrosFornecedores,
(SELECT line_text
from long_text
where key2 = proj_id and key1 = 'outrossistemas'
) OutrosSistAfectados,
(SELECT line_text
from long_text
where key2 = proj_id and key1 = 'principalsistema'
) PrincipalSistAfectado,
costum.prioridade Prioridade,
(SELECT rede.description
from structure rede, planning_entity proj
where proj.code88 = rede.structure_code
and proj.planning_code = proj_id
) Rede,
costum.requerente Requerente,
(SELECT rede.description
from structure rede, planning_entity proj
where proj.code89 = rede.structure_code
and proj.planning_code = proj_id
) TestesAceitacao,
projectos. structure_code proj_id
from structure projectos,
planning_entity,
structure pedidos,
structure estado,
custom_data costum
where projectos.structure_code = planning_entity.planning_code
and planning_entity.planning_code = planning_entity.ppl_code
and pedidos.structure_code = planning_entity.code31
and estado.structure_code = planning_entity.code20
and projectos.structure_code = proj_id
and costum.planning_code = proj_id
-- HERE ENDS WHAT I RUN OUTSIDE THE FUNCTION WITHOUT A PROBLEM
)
as Z_TABLE_PEDIDO_SeB)
into
t_dados
from
dual;
return t_dados;
end Z_GetDadosCreateUpdate_SEB;
What i execute:
SELECT * FROM table (PVDEV.Z_GetDadosCreateUpdate_SEB('184765'));
Error i got:
ORA-22814: valor do atributo ou elemento é superior ao especificado no tipo
ORA-06512: na "PVDEV.Z_GETDADOSCREATEUPDATE_SEB", linha 7
22814. 00000 - "attribute or element value is larger than specified in type"
*Cause: Value provided for the object type attribute or collection element
exceeded the size specified in the type declaration.
*Action: Choose another value and retry the operation.
NOTE: if i try 18476 instead of 184765 it runs with no problem. So? how did i put such restriction? Where?
NOTE: Now i'm showing the error, the real one, i'm really sorry for the mistake
I would really appreciate any answer as other's people work is waiting for my part :S. Anyway thanks in advance for any information.
If I were you I would declared the function as the pipelined one and returned values by pipe row statement. And surely get rid of CAST/multiset. For loop statement is your choice. I'm sure it will work using my piece of advice.