Inserting a Date data - sql

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.

Related

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

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.

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).

Counting of Tries for a log

I have 3 tables. INV_HDR, PAYM_LOG, PAY_CA. The schema are as follow
CREATE TABLE INV_HDR
(
INV_HDR_ID NUMBER(19, 0) DEFAULT "SEQ_INV_HDR_ID"."NEXTVAL" NOT NULL
, INV_NO VARCHAR2(30 BYTE) NOT NULL
, INV_TYPE_CD VARCHAR2(10 BYTE)
, INV_PARTY_UEN VARCHAR2(17 BYTE)
, INV_DT DATE
, GIRO_STS_CD VARCHAR2(11 BYTE) DEFAULT '0' NOT NULL
, INV_STS_CD VARCHAR2(11 BYTE) DEFAULT '1' NOT NULL
, PAYMENT_STS_CD VARCHAR2(11 BYTE) DEFAULT '1' NOT NULL
, RFD_STS_CD VARCHAR2(11 BYTE) DEFAULT '0' NOT NULL
, WAIVE_WRITE_DRAW_STS_CD VARCHAR2(11 BYTE) DEFAULT '0' NOT NULL
) ;
CREATE TABLE PAYM_LOG
(
PAYMENT_LOG_ID NUMBER(19, 0) DEFAULT "SEQ_PAYMENT_LOG_ID"."NEXTVAL" NOT NULL
, INV_HDR_ID NUMBER(19, 0) NOT NULL
, INV_PARTY_UEN VARCHAR2(17 BYTE)
, INV_NO VARCHAR2(30 BYTE) NOT NULL
, TRANS_DT DATE
, AMT NUMBER(15, 2) DEFAULT 0 NOT NULL
, VOUCHER_NO VARCHAR2(30 BYTE)
, REASON VARCHAR2(60 BYTE)
, CREATED_BY VARCHAR2(35 BYTE) NOT NULL
, CREATED_DT TIMESTAMP(6) DEFAULT SYSTIMESTAMP NOT NULL
, LAST_UPDATED_BY VARCHAR2(35 BYTE) NOT NULL
, LAST_UPDATED_DT TIMESTAMP(6) DEFAULT SYSTIMESTAMP NOT NULL
, PAYMENT_STS VARCHAR2(11 BYTE)
) ;
CREATE TABLE PAY_CA
(
PAY_CA_ID NUMBER(19, 0) DEFAULT "SEQ_PAY_CA_ID"."NEXTVAL" NOT NULL
, CA_ID VARCHAR2(2 BYTE)
, TRANS_DT DATE
, JOURNAL_HDR_ID NUMBER(19, 0)
, CREATED_BY VARCHAR2(35 BYTE) NOT NULL
, CREATED_DT TIMESTAMP(6) DEFAULT SYSTIMESTAMP NOT NULL
, LAST_UPDATED_BY VARCHAR2(35 BYTE) NOT NULL
)
INV_HDR
1. Invoice is created for every Invoice generated. PK = INV_HDR_ID
2. GIRO_STS_CD will be updated from 2(Success) to 3(Fail) when payment has been made successfully
PAYM_LOG
1. Every attempted payment is recorded.
2. PAYMENT_STS = 12 (Fail), 13 (Pass)
PAY_CA
1. Only successful payment that has been made will have records created.
Thing is I would like to generate a report where there are 4 statuses.
1. GIRO Successful -- 1st time successful payment
2. GIRO Failed
3. GIRO Failed - 1st Retry
4. GIRO Failed - 2nd Retry
My report columns will be
S/N | INV_HDR.UNV_PARTY_UEN | CA_ID | Payment Status | Amount | Retry
With a summary to count the 4 different statuses.
Summary Count Amount
GIRO Successful x 100
GIRO Failed y 200
GIRO Failed - 1st Retry z 50
GIRO Failed - 2nd Retry w 10
Is it possible to do it in a single SQL? I have something like this so far..
SELECT PAY_CA.CA_ID, INV_HDR.INV_PARTY_UEN ,
INV_HDR.GIRO_STS_CD AS PAYMENT_STATUS,
PAY_CA.AMT,
SUM (
CASE
WHEN PAYM_LOG.PAYMENT_STS = '12'
THEN 1
ELSE 0
END ) AS RETRY
FROM INV_HDR,
PAYM_LOG,
PAY_CA
WHERE INV_HDR.INV_HDR_ID = CA_PAY.INV_HDR_ID
AND INV_HDR.INV_NO = PAYM_LOG.INV_NO
AND INV_HDR.GIRO_STS_CD IN ('2' ,'3')
GROUP BY PAY_CA.CA_ID ,
INV_HDR.INV_PARTY_UEN ,
INV_HDR.GIRO_STS_CD ,
PAY_CA.AMT
Thing is I need to retrieve both Failed and successful payment. Joining with PAY_CA will only allow me to get successful payments. How do i also get non-successful payments into counting of the retries?

How to get data from oracle database in hourly basis

i have one table call CMH_VITALSIGN, There is one column in this table as Time, which stores date and time (3/2/2016 11:33:17 AM). Now i want to get data from this table on hourly basis. MY Table columns is ..
(
VITAL_SIGNNO NUMBER,
CONSULT_NO VARCHAR2(16 BYTE),
REG_NO VARCHAR2(16 BYTE),
ADMISSION_NO VARCHAR2(16 BYTE),
DN_NO VARCHAR2(16 BYTE),
CONSULT_DT DATE,
TEMP_C NUMBER(4,2),
TEMP_F NUMBER(5,2),
PULSE NUMBER(3),
RR NUMBER(2),
BP_HIGHER NUMBER(5,2),
BP_LOWER NUMBER(5,2),
RESP NUMBER(3),
SPECIALITY_NO VARCHAR2(16 BYTE),
ENTERED_BY VARCHAR2(16 BYTE),
ENTRY_TIMESTAMP DATE,
UPDATED_BY VARCHAR2(16 BYTE),
UPDATE_TIMESTAMP DATE,
COMPANY_NO VARCHAR2(10 BYTE) DEFAULT 1,
SL_NO VARCHAR2(16 BYTE)
)
now i want to show data as line chart hourly base...
SELECT to_date(ENTRY_TIMESTAMP) DAY,
DECODE(TO_CHAR(ENTRY_TIMESTAMP,'HH24'),'11',pulse, 0) "00",
DECODE(TO_CHAR(ENTRY_TIMESTAMP,'HH24'),'12',pulse,0)"01",
DECODE(TO_CHAR(ENTRY_TIMESTAMP,'HH24'),'13',pulse,0) "02",
DECODE(TO_CHAR(ENTRY_TIMESTAMP,'HH24'),'14',pulse,0) "03"
FROM CMH_VITALSIGN
WHERE pulse IS NOT NULL
--where to_date(ENTRY_TIMESTAMP) ='01_MAY-2010'
--GROUP by to_char(ENTRY_TIMESTAMP,'YYYY-MON-DD'), to_date(ENTRY_TIMESTAMP)
ORDER BY to_date(ENTRY_TIMESTAMP);
Can anybody help me in this query.
If you want calculate data per every hour try implement this:
SELECT TO_CHAR( d, 'yyyy-mm-dd hh24') hour, COUNT(*)
FROM (SELECT SYSDATE + LEVEL / 26 / 60 d
FROM DUAL
CONNECT BY LEVEL < 1000)
GROUP BY TO_CHAR( d, 'yyyy-mm-dd hh24')
SELECT TO_CHAR ( ENTRY_TIMESTAMP, 'HH24') AS hour_num,
PULSE,
TEMP_C,
TEMP_F,
RR,
BP_HIGHER,
BP_LOWER,
RESP
FROM cmh_vitalsign
WHERE TRUNC (ENTRY_TIMESTAMP) = TO_DATE ( '3/2/2016', 'MM/DD/YYYY')
and ADMISSION_NO = 'A011009011297';

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.