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
Related
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
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.
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;
I have a file with this:
set linesize 1000
set trimspool on
set trimout on
set pagesize 0
set feedback off
spool result.csv
SELECT process_id || ';' || file_name || ';' || source || ';' || destination || ';' || type || ';' || transfer_name || ';' || message || ';' || message2 || ';' || destination_sub_group
FROM table
WHERE process_id = '12345';
And SQLPLUS is calling it
But this is returning blank spaces, specially message2 field, any idea on how to remove it?
Here is the output:
12345;filename.txt;X;X;4;X;xx = xxxx
Warning: Using insecure memory!
Decoding data....
Secret key is required to read it.
Key for user ID "X"
Error decrypting file '/apps/egs/gen/file_name.txt.pgp'.
;INBOUND
Thanks!
I replaced some values with X.
Here is the output I would like:
12345;filename.txt;X;X;4;X;xx = xxxx Warning: Using insecure memory! Decoding data.... Secret key is required to read it. Key for user ID "X" Error decrypting file /apps/egs/gen/file_name.txt.pgp'.;INBOUND
i fought this problem for days, when i wanted to get the query results into a csv...
set mark csv ON ended up solving the problem in that case... took my for ever to find that command
Try using TRIM to remove trailing and leading spaces and REPLACE to remove linefeeds and carriage returns:
SELECT process_id || ';' || file_name || ';' || source || ';' || destination || ';' || type || ';' || transfer_name || ';' || message || ';' ||
replace(replace(trim(message2),CHR(10),' '),CHR(13),' ') || ';' || destination_sub_group
FROM table WHERE process_id = '12345';
Add the following:
COL the_stuff form a1000
Then add the "the_stuff" column alias to your query:
SELECT process_id .... destination_sub_group the_stuff from ..
This will explicitly allow you some control over how this output is displayed.
Next, to deal with the embedded linefeeds in your output, wrap lot around a TRANSLATE ( ..., CHR(10), '+' )
E.g.
This show data with linefeeds:
SQL> select 'line 1' || chr(10) || 'line2' || chr(10) || 'line 3' txt from dual;
TXT
-------------------
line 1
line2
line 3
Translate to replace the linefeeds with "+":
SQL> select translate ( 'line 1' || chr(10) || 'line2' || chr(10) || 'line 3',
chr(10), '+' ) txt
from dual;
TXT
-------------------
line 1+line2+line 3
SQL>