How do I convert the following IIF statement to oracle decode statement :
IIF(lkp_LAST_NAME1 = 'Unknown', lkp_LAST_NAME1,
IIF(lkp_FIRST_NAME1 =' ' OR lkp_MIDDLE_NAME1 = ' ',lkp_LAST_NAME1,
IIF(ISNULL(lkp_LAST_NAME1), lkp_FIRST_NAME1 || ' ' || lkp_MIDDLE_NAME1,
IIF((ISNULL(lkp_FIRST_NAME1) AND ISNULL(lkp_MIDDLE_NAME1)), lkp_LAST_NAME1,
lkp_LAST_NAME1 || ', ' || lkp_FIRST_NAME1 || ' ' || lkp_MIDDLE_NAME1))))
CASE should take care of it
case
when lkp_LAST_NAME1 = 'Unknown' then lkp_LAST_NAME1
else
case when lkp_FIRST_NAME1 =' ' OR lkp_MIDDLE_NAME1 = ' ' then lkp_LAST_NAME1
else
case when lkp_LAST_NAME1 is null then lkp_FIRST_NAME1 || ' ' || lkp_MIDDLE_NAME1
else
case when lkp_FIRST_NAME1 is null and lkp_MIDDLE_NAME1 is null then lkp_LAST_NAME1
else lkp_LAST_NAME1 || ', ' || lkp_FIRST_NAME1 || ' ' || lkp_MIDDLE_NAME1
end
end
end
end
Related
Can I get a single output by using loop in pl/sql instead of multiple outputs?
Below is my query and the output I am getting.
declare
CURSOR VALIGN_DAILY IS
SELECT AUDT.WKFL_NM,
AUDT.JOB_STAT,
AUDT.STRT_DT,
AUDT.END_DT,
AUDT.SRC_REC_CNT,
AUDT.TGT_REC_CNT,
AUDT.ERR_REC_CNT
FROM CRMF_AUDT_PROC_LOG AUDT
WHERE AUDT.WKFL_NM IN ('wf_ALIGNMENT_TERR_FIELDFORCE_EZFLEX_INB','wf_ALIGNMENT_USER_TERR_EZFLEX_INB','wf_ALIGNMENT_FIELDFORCE_STG_INB','wf_ALIGNMENT_TERR_STG_INB','wf_ALIGNMENT_USER_TERR_STG_INB')
AND (AUDT.JOB_STAT = 'S' OR AUDT.JOB_STAT = 'P' OR AUDT.JOB_STAT = 'E' OR AUDT.JOB_STAT = 'F')
AND TRUNC(AUDT.STRT_DT)=TRUNC(SYSDATE);
VALIGNSTATUS VALIGN_DAILY%ROWTYPE;
BEGIN
FOR VALIGNSTATUS IN VALIGN_DAILY LOOP
CASE VALIGNSTATUS.JOB_STAT
WHEN 'S' THEN DBMS_OUTPUT.PUT_LINE('VALIGN_DAILY' || ' ' || 'COMPLETED' || ' ' || VALIGNSTATUS.STRT_DT || ' ' || VALIGNSTATUS.END_DT || ' ' || VALIGNSTATUS.WKFL_NM);
WHEN 'P' THEN DBMS_OUTPUT.PUT_LINE('VALIGN_DAILY' || ' ' || 'IN_PROGRESS' || ' ' || VALIGNSTATUS.STRT_DT || ' ' || VALIGNSTATUS.END_DT || ' ' || VALIGNSTATUS.WKFL_NM);
WHEN 'E' THEN DBMS_OUTPUT.PUT_LINE('VALIGN_DAILY' || ' ' || 'ERRED' || ' ' || VALIGNSTATUS.STRT_DT || ' ' || VALIGNSTATUS.END_DT || ' ' || VALIGNSTATUS.WKFL_NM);
WHEN 'F' THEN DBMS_OUTPUT.PUT_LINE('VALIGN_DAILY' || ' ' || 'FAILED' || ' ' || VALIGNSTATUS.STRT_DT || ' ' || VALIGNSTATUS.END_DT || ' ' || VALIGNSTATUS.WKFL_NM);
ELSE
DBMS_OUTPUT.PUT_LINE ('VALIGN_DAILY' || ' ' || 'NOT_STARTED' || ' ' || 'N/A' || ' ' || 'N/A');
END CASE;
END LOOP;
end;
And my output is like--
VALIGN_DAILY COMPLETED 28-MAY-2018 28-MAY-2018 wf_ALIGNMENT_FIELDFORCE_STG_INB
VALIGN_DAILY COMPLETED 28-MAY-2018 28-MAY-2018 wf_ALIGNMENT_USER_TERR_EZFLEX_INB
VALIGN_DAILY COMPLETED 28-MAY-2018 28-MAY-2018 wf_ALIGNMENT_TERR_FIELDFORCE_EZFLEX_INB
VALIGN_DAILY COMPLETED 28-MAY-2018 28-MAY-2018 wf_ALIGNMENT_USER_TERR_STG_INB
VALIGN_DAILY COMPLETED 28-MAY-2018 28-MAY-2018 wf_ALIGNMENT_TERR_STG_INB
This is the procedure
PROCEDURE NON_BLOCKING_STATUS
IS
cursor badcur is
select query;
BEGIN
dbms_output.put_line('sch_id sch_revision SCD_SEQUENCE SCH_STATUS scD_status scd_action scd_object SCD_NAME scl_text');
for badrow in badcur LOOP
dbms_output.put_line ( badrow.sch_id || ' ' || badrow.sch_revision || ' ' || badrow.SCD_SEQUENCE || ' ' || badrow.SCH_STATUS || ' ' || badrow.scD_status || ' ' || badrow.scd_action || ' ' || badrow.scd_object || ' ' || badrow.SCD_NAME || ' ' || badrow.scl_text);
end loop;
end;
The select sql query is returning rows while running it on SQL developer but while using it in the above procedure, its not working.
Thanks in Advance.
reportDimMCP and reportValMCP are two different presentation variable for two prompt. i want to represent using a string the output of a select case.
i try this :
SELECT CASE '#{reportDimMCP}{Utilizzato}' WHEN 'Numero' THEN '( case '#{reportValMCP} {NULL}' ' || when ||' ' Utilizzo > 0' '|| then || 'ho scelto Numero con Utilizzo > 0' || when ||' ' Utilizzo = 0' ' || then 'ho scelto Numero con Utilizzo = 0' || end || ')'
FROM "Myself"
but doesn't work
Any idea?
Is the problem that your second case is incorrectly inside quotes? i.e. should it look more like this:
case '{pvTest1}{A}'
when 'A' then
case '{pvTest2}{X}'
when 'X' then 'Foo'
else 'Bar'
end
else 'wibble'
end
this question is a part of this one
limit records in cursor by using a variable
the original question was a 2 part question, 1 part being, IS THERE A BETTER WAY TO DO THIS
i have code that works but it's EXTREMELY slow, about 2 seconds for each record.
so i have a table, NR_POSTAL_ABBR, that has 2 fields and about 400 records
ReplaceWhat ReplaceWith
Ave Avenue
St Street
i want to be able to replace the Address field in another table with the valules from the table above
so if i have an address 123 Main St - it should say 123 Main Street
if i have 123 Main Street - it should stay 123 Main Street, it shouldn't become 123 Main Streetreet
the table with addresses has a few million rows, is there a fast way of doing this?
thank you
So as you asked. My suggestion is go through regular expressions So here is un update code for your case.
Suppose you have a table test with the field address, what you have to do is very simple, create an regular expression that match your requirements.
So: You need to replace every St for Street and Av for Avenue this is what you should do.
update test
set address =
regexp_replace(
regexp_replace(address, 'Av | Av$| Av ', ' Avenue ' ),
'St | St$| St ', ' Street ');
Here is a SQLFiddle example
Explaining the regex:
The regexp_replace replaces a string for another based on a regular expression pattern, see the docs: REGEXP_REPLACE
About the regular expressions you can see it here Regular Expressions Wiki Almost every language follow the POSIX pattern, so once you learn it you will be good.
So I've used to regexp_replace to achieve what you want because you gave two requirements. I will not write about the parameters of the function just the expressions.
At the first expression you have 'Av | Av$| Av ' which means:
PS.: I put the - just to you see the space (so ignore it). SO wont let me put it.
-Av - (with a space at end) = Find every Av with a space after it on the string
-|- (pipe sign) = Equals an or statement
- Av$- = Find all Av with a space before it and when Av is at the end of the string. $
- Av - = Find all Av with a space before and a space after
Then The function replace any of theese ocurrences with the word Avenue. Notice that I put a space before and one after to avoid something like Peer HarborAvenue
The same explanation goes to St string
If you like the regular expressions function you can see more with it here: Oracle Regular Expressions Functions
just posting the automated version based on Jorge's reply, in case someone needs it.
DECLARE
ReplOrder NUMBER;
BEGIN
ReplOrder := 1;
DECLARE
CURSOR getReplsStrng IS
SELECT replacewhat
,replacewith
FROM analyst.NR_POSTAL_ABBR
WHERE ReplaceOrder = ReplOrder;
BEGIN
FOR getInnerRec IN getReplsStrng LOOP
-- DBMS_OUTPUT.put_line('replace what ' || getInnerRec.replacewhat);
-- DBMS_OUTPUT.put_line('Replace Order ' || ReplOrder);
UPDATE NR_TMP_106 tmp
SET NewAddress = LOWER(REGEXP_REPLACE(LOWER(NewAddress)
, '$'
|| getInnerRec.replacewhat
|| ' | '
|| getInnerRec.replacewhat
|| '$| '
|| getInnerRec.replacewhat
|| ' '
,' ' || getInnerRec.replacewith || ' '))
WHERE 1 = 1
AND ( tmp.NewAddress LIKE '%' || CHR(32) || '' || getInnerRec.replacewhat || '' || NULL || '%'
OR tmp.NewAddress LIKE '%' || CHR(32) || '' || getInnerRec.replacewhat || '' || CHR(32) || '%'
OR tmp.NewAddress LIKE '%' || NULL || '' || getInnerRec.replacewhat || '' || CHR(32) || '%');
COMMIT;
END LOOP;
END;
ReplOrder := 2;
DECLARE
CURSOR getReplsStrng IS
SELECT replacewhat
,replacewith
FROM analyst.NR_POSTAL_ABBR
WHERE ReplaceOrder = ReplOrder;
BEGIN
FOR getInnerRec IN getReplsStrng LOOP
-- DBMS_OUTPUT.put_line('replace what ' || getInnerRec.replacewhat);
-- DBMS_OUTPUT.put_line('Replace Order ' || ReplOrder);
UPDATE NR_TMP_106 tmp
SET NewAddress = LOWER(REGEXP_REPLACE(LOWER(NewAddress)
, '$'
|| getInnerRec.replacewhat
|| ' | '
|| getInnerRec.replacewhat
|| '$| '
|| getInnerRec.replacewhat
|| ' '
,' ' || getInnerRec.replacewith || ' '))
WHERE 1 = 1
AND ( tmp.NewAddress LIKE '%' || CHR(32) || '' || getInnerRec.replacewhat || '' || NULL || '%'
OR tmp.NewAddress LIKE '%' || CHR(32) || '' || getInnerRec.replacewhat || '' || CHR(32) || '%'
OR tmp.NewAddress LIKE '%' || NULL || '' || getInnerRec.replacewhat || '' || CHR(32) || '%');
COMMIT;
END LOOP;
END;
END;
here is my code
vJS VARCHAR2(3500); --25065
gMaxDays s_criteria%rowtype := get_criteria_rec('MAX_DAYS_BOOKING');
BEGIN
IF NOT Sec_Pkg.chk_sec('ATLAS_INV_OVERBOOK') THEN
-- Exit procedure if security did not pass
RETURN;
END IF;
--
vJS := ' gMaxDays;'||CHR(10)||
'function checkfields() {' ||CHR(13) ||
' // Setting the target here' ||CHR(13) ||
' document.frmInvSelect.target="_top"' ||CHR(13) ||
i created gMaxDays,at first i had it hardcoded but now its on a table called s_criteria and MAX_DAYS_BOOKING is part of s_criteria. im i calling it the right way?
this is how it use to look and it work
vJS VARCHAR2(3500); --25065
BEGIN
IF NOT Sec_Pkg.chk_sec('ATLAS_INV_OVERBOOK') THEN
-- Exit procedure if security did not pass
RETURN;
END IF;
--
vJS := 'var gMaxDays = 366;'||CHR(10)||
'function checkfields() {' ||CHR(13) ||
' // Setting the target here' ||CHR(13) ||
' document.frmInvSelect.target="_top"' ||CHR(13) ||
[/code]
Err ... Are you saying that
You used to have a code snippet that "worked":
vJS := 'var gMaxDays = 366;'||CHR(10)||
'function checkfields() {' ||CHR(13) ||
' // Setting the target here' ||CHR(13) ||
' document.frmInvSelect.target="_top"' ||CHR(13) ||
When you modified the snippet to be:
vJS := ' gMaxDays;'||CHR(10)||
'function checkfields() {' ||CHR(13) ||
' // Setting the target here' ||CHR(13) ||
' document.frmInvSelect.target="_top"' ||CHR(13) ||
It "works" no more ?
I guess you're trying to generate a JavaScript code snippet. Maybe this is what you're looking for:
declare
vJS VARCHAR2(3500);
gMaxDays s_criteria%rowtype := get_criteria_rec('MAX_DAYS_BOOKING');
begin
-- here you have to call the correct field from the record
-- in this example I assume it's max_day
vJS := 'var gMaxDays = ' || gMaxDays.max_day || ';' || CHR(10)||
'function checkfields() {' || CHR(10) ||
' // Setting the target here' || CHR(10) ||
' document.frmInvSelect.target="_top"' || CHR(10) ||
' // Add here something that makes this a valid JavaScript.'
end;
Check what the documentation says about PL/SQL record variables.