Something is missing in my querie, and i feel burned [closed] - oracle

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 10 months ago.
Improve this question
I have this complicated querie and I have to fix it, at the moment I think there is an error in the where, something will be missing there, but I am not sure, that's why I ask you for help from the powerful people of stackoverflow.
If you want it is good and without errors, that means that the error is in the data entry, and that would have an easier solution.
I definitely have to improve in consultations.
Query:
SELECT
t.TICKET,
t.TIPOOPERACION,
o.DESCRIPCION_CAS AS DESCOPCAS,
o.DESCRIPCION_CAT AS DESCOPCAT,
o.DESCRIPCION_EN AS DESCOPEN,
ca.ORDEN,
t.APLORIGEN,
t.FECHAALTA,
t.FECHACADUCIDAD,
t.ESTADO,
t.OFICINA,
t.CONTRATO,
t.VISIBILIDAD,
t.VISIBLECLI,
t.RESPONSABLE,
t.USUARIOMOD,
t.CANAL,
t.IDPART,
t.DATOS,
t.FECHAMODIFICACION,
t.COMENTARIOS,
t.PEA,
t.PARAMETROSPEA,
t.URL,
ca.DESCRIPCION_CAS AS descCategoriaCas,
ca.DESCRIPCION_CAT AS descCategoriaCat,
ca.DESCRIPCION_EN AS descCategoriaEn,
t.categoria,
o.IMAGEN,
t.NUM_MENSAJE,
NVL2(t.FECHAMODIFICACION, 'S', 'N') AS LEIDO,
t.COD_VISUALIZACION,
t.INFO_VARIABLE,
TRUNC(
(
TO_DATE(t.FECHACADUCIDAD, 'YYYYMMDD') - TO_DATE(TO_CHAR(SYSDATE, 'YYYYMMDD'), 'YYYYMMDD')
)
) AS DIAS_CADUCIDAD,
t.ID_APLICACION,
t.HORA_CADUCIDAD,
t.DATOS_VISUALIZACION,
t.IMPORTE,
t.DIVISA,
o.OPERATIVA,
t.LISTA_ID_GDD AS listaiddocumentos,
t.REF_AGRUPADORA_GDD,
T.FECHA_INICIO AS FECHAINICIO,
TO_DATE(
CONCAT(
CONCAT(t.FECHACADUCIDAD, ' '),
DECODE (t.HORA_CADUCIDAD, NULL, '23:59', t.HORA_CADUCIDAD)
),
'YYYYMMDD HH24:MI'
) AS FECHACADUCIDADCOMPLETA,
t.PREGUNTA_SECRETA,
t.OPERACION_BLOQUEADA,
t.FECHA_BLOQUEO,
o.MINUTOS_BLOQUEO,
t.NUMERO_EMPLEADO,
t.NUMERO_EMPLEADO_MOD,
t.TIPO_PERSONA,
t.CONSOLIDA_SIN_FIRMA AS CONSOLIDARSINFIRMA,
o.CONSOLIDAR_SIN_FIRMA AS PUEDECONSOLIDADSINFIRMA,
o.CONSOLIDAR_CON_ERROR_FIRMA as puedeConsolidarErrorFirma,
t.LISTA_DOC_NO_DEMORABLE AS listaDocNoDemorable,
t.DEMORA,
t.SUBCANAL,
t.MONITORING_DATOS,
(
SELECT
LITERAL_MOTIVO
FROM
TDE_MOTIVOS_ELIMINAR M
INNER JOIN TDE_TAREAS T ON T.ID_MOTIVO_ELIMINAR = M.ID_MOTIVO
WHERE
TICKET = ?
) as motivoEliminar,
DECODE(
(
SELECT
ESTADO
FROM
TDE_TAREAS
WHERE
TICKET = ?
),
4,
'S',
'N'
) AS puedeFirmar,
t.PNOW,
t.POFI,
t.PARAMETROS_POFI as parametrosPOfi,
t.LITERAL_AGRUPACION,
DECODE (t.TICKET_ANIDADO, NULL, 'N', 'S') AS STOPANIDADO,
t.TIPOANIDAMIENTO,
t.TICKET_PADRE AS ticketPadre,
t.NUEVO_CIRCUITO as nuevoCircuito,
t.ticket_anidado as ticketAnidado,
(
DECODE (t.TIENE_HIJOS, NULL, 'N', t.TIENE_HIJOS)
) AS tieneHijos,
o.tipoanulacion AS tipoAnulacion,
o.eliminable,
t.VISIBILIDAD_PERSONA AS visibilidadPer
FROM
tde_tareas t,
tde_operaciones o,
tde_categoria ca
WHERE
AND o.tipooperacion = t.tipooperacion
AND o.categoria = t.categoria
AND ca.categoria = t.categoria
This is the error:
ORA-00936: missing expression

This is wrong:
WHERE
AND o.tipooperacion = t.tipooperacion
Remove AND (or add some condition behind WHERE, if there is any you - possibly - missed or deleted).

You haven't joined the tables in the FROM
FROM
tde_tareas t
join tde_operaciones o
on o.tipooperacion = t.tipooperacion AND o.categoria = t.categoria
join tde_categoria ca on ca.categoria = t.categoria;

Related

Is there any approach to increasing the performance of below query?

The below query is returning almost 800k records for period Sep-21 with all account and LOB
and is taking 9+hrs to generate a report.
the code is pretty straight forward. When tried with individual queries, i.e, inline and outer query, it was taking less time (Individual), but when i join those 2 query with the condition
AND gl.gl_sl_link_table (+) =XAL.gl_sl_link_table
AND gl.gl_sl_link_id (+) =XAL.gl_sl_link_id
this was taking time.
Is there any approach to modify this query, such that overall performance is increased?
SELECT
XAH.AE_HEADER_ID,
XAH.APPLICATION_ID,
XAH.LEDGER_ID,
XAH.ENTITY_ID,
XAH.EVENT_ID,
XAH.EVENT_TYPE_CODE,
XAH.ACCOUNTING_DATE,
XAH.GL_TRANSFER_STATUS_CODE,
XAH.GL_TRANSFER_DATE,
XAH.JE_CATEGORY_NAME,
XAH.ACCOUNTING_BATCH_ID,
XAH.PERIOD_NAME,
XAH.LEGAL_ENTITY_ID,
XAH.DESCRIPTION,
XAL.ENTERED_DR,
XAL.ENTERED_CR,
XAL.ACCOUNTED_CR,
XAL.ACCOUNTED_DR,
XAL.CURRENCY_CONVERSION_RATE,
XAL.CURRENCY_CONVERSION_DATE,
XAL.CURRENCY_CODE,
XAL.CURRENCY_CONVERSION_TYPE,
XAL.CODE_COMBINATION_ID,
XAL.DESCRIPTION DESCRIPTION1,
XASV.SEGMENT_VALUE ,
XASV.SEGMENT_TYPE_CODE,
GCC.SEGMENT1,
GCC.SEGMENT2,
GCC.SEGMENT3,
GCC.SEGMENT4,
GCC.SEGMENT5,
GCC.SEGMENT6,
GCC.SEGMENT7,
pbe.sourceref "SOURCE_REFERENCE",
gl.name AS "BATCH_NAME",
DECODE(gl.status, 'P', 'Posted', 'U', 'UnPosted', gl.status) AS "BATCH_STATUS"
FROM
XLA_AE_HEADERS XAH,
XLA_AE_LINES XAL,
XLA_AE_SEGMENT_VALUES XASV,
GL_CODE_COMBINATIONS GCC,
pjb_rev_distributions prd,
pjb_billing_events pbe,
(
SELECT
gir.gl_sl_link_table,
gir.gl_sl_link_id,
gjb.name,
gjb.status
FROM
gl_import_references gir,
gl_je_batches gjb,
gl_je_headers gjh,
gl_je_lines gjl
,GL_ledgers gl
WHERE
1 = 1
AND gjh.je_header_id = gir.je_header_id
AND gjl.je_line_num = gir.je_line_num
AND gjh.je_batch_id = gjb.je_batch_id
AND gjh.je_header_id = gjl.je_header_id
AND gjl.je_line_num = gir.je_line_num
and gjh.ledger_id =gl.ledger_id
and gl.LEDGER_CATEGORY_CODE = 'PRIMARY'
) gl
WHERE
XAH.AE_HEADER_ID=XAL.AE_HEADER_ID
AND XAH.APPLICATION_ID='10036'
AND XAH.EVENT_TYPE_CODE in ('IP_REVENUE','EX_REVENUE','IP_REVENUE_ADJ','EX_REVENUE_ADJ')
AND XAH.PERIOD_NAME = (:PERIOD_NAME)
AND XASV.AE_HEADER_ID(+)=XAL.AE_HEADER_ID
and XAL.CODE_COMBINATION_ID=GCC.CODE_COMBINATION_ID
AND (GCC.SEGMENT2 IN (:ACCOUNT) OR 'All' IN (:ACCOUNT || 'All'))
AND (GCC.SEGMENT5 IN (:LOB) OR 'All' IN (:LOB || 'All'))
AND XAH.event_id = prd.sla_event_id (+)
AND prd.transaction_id = pbe.event_id (+)
AND gl.gl_sl_link_table (+) =XAL.gl_sl_link_table
AND gl.gl_sl_link_id (+) =XAL.gl_sl_link_id
SQL Explain plan

MERGE into getting stuck all of a sudden

I have a stored procedure that is getting stuck on the merge into all of a sudden but has been working fine for years. Any advice ? The SP is in Oracle SQL developer and it is being executed in a Visual Studios SSIS package
Query below:
MERGE INTO CORE_APPT C
USING (
SELECT DISTINCT
TST_TKR_ID,
TST_TKR_ID_SRC,
APPT_ID_SRC,
APPT_CRETN_DTE,
APNTMT_DT,
ETS_APNTMT_ID,
ETS_TST_CNTR,
TST_STS_TYP_DESC,
APPT_STS_TYP,
TST_DLVR_MTHD_TYP_CDE,
DLVR_GRP_TYP,
TST_LNCH_TM,
TRNSCTN_ID,
TST_PKG_ID,
RND_TRIP_TST_FLG,
UPDT_DTE_TM,
PROD_ID,
ACTN_DTE_TM,
TST_DURN,
BRKRG_APPT_UPDT_DTM,
TST_APPT_TYP_CDE,
CNCL_MKUP_RSN_TYP,
DLNQNT_HLD_FLG,
TST_TKR_TST_UPDT_DTE_TM,
SCR_HLD_LVL_TYP_CDE,
SCR_CNCL_FLG,
ETS_CANDTE_SCR_HLD_FLG,
TST_CNTR_HLD_FLG,
TST_ADM_HLD_FLG,
ETS_SCR_CNCL_FLG,
TST_ADM_HLD_RSN_CDE,
TST_CNTR_HLD_RSN_CDE,
ETS_CANDTE_SCR_HLD_RSN_CDE,
ETS_SCR_CNCL_RSN_CDE,
DLNQNT_HLD_RSN_CDE,
TST_TKR_SCR_STS_TYP_CDE,
TST_TKR_SCR_STS_RSN_TYP_CDE,
PYMT_NO,
DATA_SRCE AS DATA_SRCE,
CURRENT_FLAG,
PRGRM_TYP,
sysdate as RCD_CRTD_DTE,
user as RCD_CRTD_USER,
REG_SYS_ID AS REG_SYS_ID,
TST_NAM AS TST_NAM,
CNTRY_SETL_RSP AS CNTRY_SETL_RSP
FROM STG_CMMN_APPT A
WHERE A.CURRENT_FLAG = 'Y'
) S
ON (C.APPT_ID_SRC = S.APPT_ID_SRC
AND C.REG_SYS_ID = S.REG_SYS_ID
AND C.DATA_SRCE = S.DATA_SRCE) -- added in EREG4.0 changes
WHEN MATCHED THEN UPDATE
SET C.CURRENT_FLAG = 'N'
WHERE C.CURRENT_FLAG = 'Y'
WHEN NOT MATCHED THEN INSERT
(
C.TST_TKR_ID,
C.TST_TKR_ID_SRC,
C.APPT_ID_SRC,
C.APPT_CRETN_DTE,
C.APNTMT_DT,
C.ETS_APNTMT_ID,
C.TST_CNTR_ID_SRC,
C.TST_STS_TYP_DESC,
C.APPT_STS_TYP,
C.TST_DLVR_MTHD_TYP_CDE,
C.DLVR_GRP_TYP,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.SCR_HLD_LVL_TYP_CDE,
S.SCR_CNCL_FLG,
S.ETS_CANDTE_SCR_HLD_FLG,
S.TST_CNTR_HLD_FLG,
S.TST_ADM_HLD_FLG,
S.ETS_SCR_CNCL_FLG,
S.TST_ADM_HLD_RSN_CDE,
S.TST_CNTR_HLD_RSN_CDE,
S.ETS_CANDTE_SCR_HLD_RSN_CDE,
S.ETS_SCR_CNCL_RSN_CDE,
S.DLNQNT_HLD_RSN_CDE,
S.TST_TKR_SCR_STS_TYP_CDE,
S.TST_TKR_SCR_STS_RSN_TYP_CDE,
S.PYMT_NO,
S.DATA_SRCE,
S.CURRENT_FLAG,
S.PRGRM_TYP,
S.RCD_CRTD_DTE,
S.RCD_CRTD_USER,
S.REG_SYS_ID,
S.TST_NAM,
S.CNTRY_SETL_RSP
)
;
TIA!

Basic ways to optimize this query?

title pretty much says it all. I wrote this big, ugly query that works...however it takes forever to run. I have no experience whatsoever with optimizing SQL, and am pretty new to the language and its functions. I realize none of you will be familiar with the environment I am working in, but I was just wondering if any basic things jump out at you about it. Thanks!
SELECT MAX(INVOICE.invoice_id) invoice_id, MAX(invoice.vendor_num) vendor_num, max(invoice.vendor_name) vendor_name,
MAX(invoice.po_number) po_number, MAX(invoice.invoice_date) invoice_date, MAX(invoice.invoice_num) invoice_num,
MAX(invoice.terms_name) terms_name, MAX(invoice.invoice_amount) invoice_amount, MAX(invoice.amount_applicable_to_discount) amount_applicable_to_discount,
MAX(invoice.amount_paid) amount_paid, MAX(invoice.payment_date) payment_date, MAX(invoice.document_id) document_id,
MAX(invoice.filename) filename,
STAMPS.page_markups_view_id, STAMPS.TEXT, STAMPS.TOOL_NAME
FROM
(SELECT DISTINCT inv.invoice_id,
vendor.segment1 vendor_num,
vendor.vendor_name,
MAX(poh.segment1) po_number,
inv.invoice_date,
inv.invoice_num,
terms.name terms_name,
inv.invoice_amount,
inv.amount_applicable_to_discount,
inv.amount_paid,
pmt.check_date payment_date,
path.document_id,
vendor.segment1 || '-' || inv.invoice_num || '.pdf' filename
FROM apps.ap_invoices_all inv,
apps.ap_invoice_distributions_all dist,
apps.po_distributions_all podi,
apps.ap_invoice_payment_history_v pmt,
apps.fnd_attached_docs_form_vl fnd,
markview.mv_page_image_paths path,
apps.po_vendors vendor,
apps.po_headers_all poh,
apps.ap_terms terms
WHERE inv.invoice_id = to_number(fnd.pk1_value)
AND inv.invoice_id = dist.invoice_id
AND poh.po_header_id(+) = podi.po_header_id
AND podi.po_distribution_id(+) = dist.po_distribution_id
AND fnd.file_name = to_char(path.document_id)
AND inv.invoice_id = pmt.invoice_id
AND fnd.category_description = 'MarkView Document'
AND fnd.entity_name = 'AP_INVOICES'
AND inv.vendor_id = poh.vendor_id(+)
AND inv.terms_id = terms.term_id
AND inv.vendor_id = vendor.vendor_id
AND path.platform_name = 'UNIX_FS_TO_DOC_SERVER'
AND pmt.void = 'N'
and inv.invoice_id = 1908784
GROUP BY
inv.invoice_id,
vendor.segment1 ,
vendor.vendor_name,
inv.invoice_date,
inv.invoice_num,
terms.name ,
inv.invoice_amount,
inv.amount_applicable_to_discount,
inv.amount_paid,
path.document_id,
pmt.check_date,
vendor.segment1 || '-' || inv.invoice_num || '.pdf'
) INVOICE,
( SELECT mp.document_id,
moi.markup_object_id,
moi.page_markups_view_id,
moi.text,
mvt.tool_name,
mp.page_id
FROM markview.mv_markup_object moi,
markview.mv_tool mvt,
markview.mv_page_markups_view mpmv,
markview.mv_page mp
WHERE moi.tool_id = mvt.tool_id
AND mp.page_id = mpmv.page_id
AND mpmv.page_markups_view_id = moi.page_markups_view_id
AND mvt.tool_id IN
(
SELECT mvt.tool_id
FROM markview.mv_tool
WHERE mvt.tool_name IN ( 'Green Text',
'Blue Sticky Note' ) )) STAMPS
WHERE invoice.document_id = stamps.document_id(+)
GROUP BY
page_markups_view_id, TEXT, TOOL_NAME
)

ORA-00920 Invalid Relational operator *Where Clause Error Help*

I'm trying to see what operator is wrong in this huge query. It seems that an operator is wrong in all this. Any expert can help me out? Thanks everyone for helping me out
INSERT
INTO FORUORH
(
FORUORH_USER_ID_ENTERED,
FORUORH_COAS_CODE,
FORUORH_ORGN_CODE,
FORUORH_ACCESS_IND,
FORUORH_ACTIVITY_DATE,
FORUORH_USER_ID,
FORUORH_END_DATE,
FORUORH_WBUD_ACCESS_IND
)
SELECT FORUSOR_USER_ID_ENTERED,
FORUSOR_COAS_CODE,
FORUSOR_ORGN_CODE,
FORUSOR_ACCESS_IND,
FORUSOR_ACTIVITY_DATE,
FORUSOR_USER_ID,
SYSDATE,
FORUSOR_WBUD_ACCESS_IND
FROM FORUSOR
WHERE FORUSOR_USER_ID_ENTERED = :KEY_BLOCK_USER_ID
AND ((FORUSOR_COAS_CODE, FORUSOR_ORGN_CODE)) IN (
(SELECT FORUSOR_COAS_CODE,
FORUSOR_ORGN_CODE
FROM FORUSOR
WHERE FORUSOR_COAS_CODE LIKE NVL(:KEY_BLOCK_INCLUDE_COAS_CODE, '%')
AND FORUSOR_ORGN_CODE LIKE NVL(:KEY_BLOCK_INCLUDE_ORGN_CODE, '%')
AND FORUSOR_USER_ID_ENTERED = :KEY_BLOCK_USER_ID
MINUS
SELECT FORUSOR_COAS_CODE,
FORUSOR_ORGN_CODE
FROM FORUSOR
WHERE FORUSOR_COAS_CODE LIKE NVL(:KEY_BLOCK_EXCLUDE_COAS_CODE, '%')
AND FORUSOR_ORGN_CODE LIKE NVL(:KEY_BLOCK_EXCLUDE_ORGN_CODE, '#')
AND FORUSOR_USER_ID_ENTERED = :KEY_BLOCK_USER_ID
)) ";
((FORUSOR_COAS_CODE, FORUSOR_ORGN_CODE)) vector should be (FORUSOR_COAS_CODE, FORUSOR_ORGN_CODE)

Suppress ORA-01403: no data found excpetion

I have the following code
SELECT SUM(nvl(book_value,
0))
INTO v_balance
FROM account_details
WHERE currency = 'UGX';
--Write the balance away
SELECT SUM(nvl(book_value,
0))
INTO v_balance
FROM account_details
WHERE currency = 'USD';
--Write the balance away
Now the problem is, there might not be data in the table for that specific currency, but there might be data for the 'USD' currency. So basically I want to select the sum into my variable and if there is no data I want my stored proc to continue and not throw the 01403 exception.
I don't want to put every select into statement in a BEGIN EXCEPTION END block either, so is there some way I can suppress the exception and just leave the v_balance variable in an undefined (NULL) state without the need for exception blocks?
select nvl(balance,0)
into v_balance
from
(
select sum(nvl(book_value,0)) as balance
from account_details
where currency = 'UGX'
);
SELECT L1.PKCODE L1CD, L1.NAME L1N, L1.LVL L1LVL,
L2.PKCODE L2CD, L2.NAME L2N, L2.LVL L2LVL,
L5.PKCODE L5CD, L5.NAME L5N,
INFOTBLM.OPBAL ( L5.PKCODE, :PSTDT, :PSTUC, :PENUC, :PSTVT, :PENVT ) OPBAL,
INFOTBLM.DEBIT ( L5.PKCODE, :PSTDT,:PENDT, :PSTUC, :PENUC, :PSTVT, :PENVT ) AMNTDR,
INFOTBLM.CREDIT ( L5.PKCODE, :PSTDT,:PENDT, :PSTUC, :PENUC, :PSTVT, :PENVT ) AMNTCR
FROM FSLVL L1, FSLVL L2, FSMAST L5
WHERE L2.FKCODE = L1.PKCODE
AND L5.FKCODE = L2.PKCODE
AND L5.PKCODE Between :PSTCD AND NVL(:PENCD,:PSTCD)
GROUP BY L1.PKCODE , L1.NAME , L1.LVL ,
L2.PKCODE , L2.NAME , L2.LVL ,
L5.PKCODE , L5.NAME
ORDER BY L1.PKCODE, L2.PKCODE, L5.PKCODE

Resources