Decode function inside a decode function oracle - oracle

I have a requirement wherein I have to execute this query (SUBSTR(sct.state_customer_type,INSTR(sct.state_customer_type,'(')+1,INSTR(sct.state_customer_type,')')-INSTR(sct.state_customer_type,'(')-1)) when user selects English language and if the language is selected as Spanish then execute this query (SUBSTR(sct.state_customer_type,1,INSTR(sct.state_customer_type,'(')-1)).
The language id would also come dynamically.
How can I write decode inside another decode function.
Thank you for your replies in advance.

I don't see any decode functions in your code, but if your language id variable is v_lang, you could write:
select decode(v_lang,
'English',
(SUBSTR(sct.state_customer_type,INSTR(sct.state_customer_type,'(')+1,INSTR(sct.state_customer_type,')')-INSTR(sct.state_customer_type,'(')-1)),
'Spanish',
(SUBSTR(sct.state_customer_type,1,INSTR(sct.state_customer_type,'(')-1)),
null -- if v_lang is something else
)
from ....
where ....
However, these days we recommend using ANSI CASE statements instead of decode. It's similar but easier to read and more portable.
select CASE v_lang
WHEN 'English'
THEN (SUBSTR(sct.state_customer_type,INSTR(sct.state_customer_type,'(')+1,INSTR(sct.state_customer_type,')')-INSTR(sct.state_customer_type,'(')-1))
WHEN 'Spanish'
THEN (SUBSTR(sct.state_customer_type,1,INSTR(sct.state_customer_type,'(')-1))
ELSE null -- if v_lang is something else
END
from ....
where ....

Related

IF EXISTS Statement in a PLSQL Procedure

im very new at plsql and try to implement my procedure.
My procedure signature looks like
PROCEDURE signal_merge(s1 IN SIGNAL_STRUCT, s2 IN SIGNAL_STRUCT, rs OUT SIGNAL_STRUCT)
SIGNAL_STRUCT has an (I call it field?) "updated" that is of a type UPDATED_STRUCT
Now I want to do something like
if s2.updated exists
do something
Even with Google I cant find a solution, can somebody explain me how I can achieve this?
Thank you all
I need to know its null or not
Then test for that:
if s2.updated is not null then
-- do something
end if;
Read more.
You want to know whether s2.updated is filled:
IF s2.updated IS NOT NULL THEN
do something
END IF;
I would rather use a non-nullable boolean variable, however, that would either be true or false. Then you'd ask
IF s2.updated THEN
do something
END IF;
which I consider more readable.
The struct declaration would then look like
TYPE signal_struct IS RECORD
(
updated BOOLEAN NOT NULL,
...
);

how acess the report column value in oracle-apex?

I need the "elabora prenotazione" button to be shown only when the column "stato prenotazione" is "IN SOSPESO"
I tried to set a condition but I don't know how to pick the column value
If I understand your question, this could help:
For the source of your report:
SELECT
CASE
WHEN stato_prenotazione = 'in sospeso' THEN 'elabora prenotazione'
ELSE ''
END name_of_column,
prenotazione,
username,
nome,
cognome,
viaggio,
stato_viaggio,
data_prenota,
stato_prenotazione,
numero_ospiti
FROM your_table
Then set the column "name_of_column" to type: link, and fill the target.
Wrap a condition around a call to apex_page.get_url within your SQL, so it will only produce a link when relevant
Example of function in use, sans condition:
https://azureoutput.wordpress.com/2017/10/18/custom-hyperlink-in-interactive-report/
Use this to make the button look prettier, and maybe get some other ideas
https://www.grassroots-oracle.com/2015/12/tutorial-include-action-button-in-report.html
See this in regard to escaping special characters, otherwise you'll just see HTML in your report
https://www.grassroots-oracle.com/2017/01/escape-special-characters-apex-demo.html
This could be resolved by a simple case statement as #sara mentioned.
something like:
select (case stato_prenotazione when 'in sospeso' then 'elabora prenotazione' end) as your_column
I would not keep else condition so that the column will simply contain null value if the condition is not met.

How to WRITE a structure?

How can I do the following:
data: ls_header type BAPIMEPOHEADER.
" fill it
write ls_header.
currently I'm getting an error because write can not parse the complex type to a string. Is there a simple way to get this code running in abap?
You could use something like:
DATA: g_struct TYPE bapimepoheader.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE g_struct TO FIELD-SYMBOL(<f>).
IF sy-subrc NE 0.
EXIT.
ENDIF.
WRITE: / <f>.
ENDDO.
Perhaps not exactly the answer you expect: If you list each field.
This can be done quite easy via the Pattern-mask in SE38:
Select the Write-pattern:
Enter the structure you want:
Select the fields
Confirm with "Copy"
Confirm and you get
WRITE: bapimepoheader-po_number,
bapimepoheader-comp_code,
bapimepoheader-doc_type,
bapimepoheader-delete_ind,
bapimepoheader-status,
bapimepoheader-creat_date,
bapimepoheader-created_by,
bapimepoheader-item_intvl,
bapimepoheader-vendor,
bapimepoheader-langu,
bapimepoheader-langu_iso,
bapimepoheader-pmnttrms,
bapimepoheader-dscnt1_to,
bapimepoheader-dscnt2_to,
bapimepoheader-dscnt3_to,
bapimepoheader-dsct_pct1,
bapimepoheader-dsct_pct2,
bapimepoheader-purch_org,
bapimepoheader-pur_group,
bapimepoheader-currency,
bapimepoheader-currency_iso,
bapimepoheader-exch_rate,
bapimepoheader-ex_rate_fx,
bapimepoheader-doc_date,
bapimepoheader-vper_start,
bapimepoheader-vper_end,
bapimepoheader-warranty,
bapimepoheader-quotation,
bapimepoheader-quot_date,
bapimepoheader-ref_1,
bapimepoheader-sales_pers,
bapimepoheader-telephone,
bapimepoheader-suppl_vend,
bapimepoheader-customer,
bapimepoheader-agreement,
bapimepoheader-gr_message,
bapimepoheader-suppl_plnt,
bapimepoheader-incoterms1,
bapimepoheader-incoterms2,
bapimepoheader-collect_no,
bapimepoheader-diff_inv,
bapimepoheader-our_ref,
bapimepoheader-logsystem,
bapimepoheader-subitemint,
bapimepoheader-po_rel_ind,
bapimepoheader-rel_status,
bapimepoheader-vat_cntry,
bapimepoheader-vat_cntry_iso,
bapimepoheader-reason_cancel,
bapimepoheader-reason_code,
bapimepoheader-retention_type,
bapimepoheader-retention_percentage,
bapimepoheader-downpay_type,
bapimepoheader-downpay_amount,
bapimepoheader-downpay_percent,
bapimepoheader-downpay_duedate,
bapimepoheader-memory,
bapimepoheader-memorytype,
bapimepoheader-shiptype,
bapimepoheader-handoverloc,
bapimepoheader-shipcond,
bapimepoheader-incotermsv,
bapimepoheader-incoterms2l,
bapimepoheader-incoterms3l.
Now you can make a simple replacement of bapimepoheader with ls_header and you have an output of all fields of the structure.
Maybe this is not elegant and you must adapt your report, if the structure changes. But I like this way, because often I don't need all fields and I can select the fields in an easy way.
I know two ways, one is procedural, the other is oop.
Here is the procedural approach.
Select the structure's fields (or whatever else You might need ) from the data-dictionary table DD03L into a local internal table.
Loop over the table into a work-area
Check, whether current field is a flat single datatype, and if so,
Assign component workarea-fieldname of structure ls_header into anyfieldsymbol
Write anyfieldsymbol
Do You need the code ?
Class CL_ABAP_CONTAINER_UTILITIES was specially introduced for that by SAP.
Use FILL_CONTAINER_C method for output the structure in a WRITE manner:
DATA: ls_header type BAPIMEPOHEADER.
CALL METHOD CL_ABAP_CONTAINER_UTILITIES=>FILL_CONTAINER_C
EXPORTING
IM_VALUE = ls_header
IMPORTING
EX_CONTAINER = DATA(container)
EXCEPTIONS
ILLEGAL_PARAMETER_TYPE = 1
others = 2.
WRITE container.
You can write your structure to a string and then output the string. Same method idoc segments are created.

Understanding evaluate function in OBIEE

I read some stuff on OBIEE Evaluate function and could not really understand as I am new to this.
EVALUATE('GetValue(%1,''SELECT MAX(P3_LST37) INTO :strValue FROM MV_ITEMSX WHERE ITEM_NUMBER = XXXX '' )' AS VARCHAR(2000), "Product")
Can you please help me to understand the function describe above?
Thanks
The Evaluate function enables you to send a function to the database to evaluate and return data to OBIEE. For security purposes you must use references in the function rather than the values themselves.
For example, if I have a column "Core"."Date" which returns the date as a string and want to use the TO_DATE function of evaluate, I would issue the following evaluate expression:
EVALUATE('TO_DATE(%1,'DD-MON-YYYY') AS DATE',"Core"."Date")
Hope that helps.

Getting an Error “ORA-06502: PL/SQL: numeric or value error: character string buffer too small”

This is my query
begin
select ceq_specimens.numero as NUMERO,
analyseEffectuee.DESCRIPTION as analyseEffectuee
into out_rec.NUMERO_SPECIMEN3, out_rec.SPEC3_ANALYSE_EFFECTUE
from CEQ_FORMULAIRES_ANALYSES
inner join ceq_liste_choix analyseEffectuee on analyseEffectuee.ID_LISTE_CHOIX=CEQ_FORMULAIRES_ANALYSES.ID_ANALYSE_EFFECTUE
inner join ceq_specimens on ceq_specimens.ID_SPECIMEN=CEQ_FORMULAIRES_ANALYSES.ID_SPECIMEN and ceq_specimens.ID_SPECIMEN=vintIdSpecimen3
where CEQ_FORMULAIRES_ANALYSES.ID_FORMULAIRE=out_rec.ID_FORMULAIRE;
EXCEPTION
WHEN NO_DATA_FOUND THEN
out_rec.NUMERO_SPECIMEN3 := ' ';
out_rec.SPEC3_ANALYSE_EFFECTUE := ' ';
END;
...
IF analyseEffectuee.DESCRIPTION as analyseEffectuee = Spécimen impossible à analyser: Préciser en commentaire(s)
I get error ''string buffer too small”
IF analyseEffectuee.DESCRIPTION as analyseEffectuee= Non
No problem in this case
Thanks for helping me!
I get Error ''string buffer too small” "
What that means is your variable out_rec.SPEC3_ANALYSE_EFFECTUE is not big enough to hold teh value Spécimen impossible à analyser: Préciser en commentaire(s).
The best way to define PL/SQL variables is to use the %TYPE keyword. This creates a variable which matches the column's definition.
Your code uses something called OUTREC. You haven't given us the definition of this, which makes it harder to correct your specfic problem but perhaps you should be doing something like this. Declare a PL/SQL record type which matches you're desired output, then declare a variable of that type:
type my_rec_t is record (
NUMERO_SPECIMEN1 ceq_specimens.numer%type,
SPEC1_ANALYSE_EFFECTUE analyseEffectuee.DESCRIPTION%type,
NUMERO_SPECIMEN2 ceq_specimens.numer%type,
SPEC2_ANALYSE_EFFECTUE analyseEffectuee.DESCRIPTION%type,
NUMERO_SPECIMEN3 ceq_specimens.numer%type,
SPEC3_ANALYSE_EFFECTUE analyseEffectuee.DESCRIPTION%type
);
out_rec my_rec_t;
ORA-02303: cannot drop or replace a type with type or table dependents
So this means you're using SQL Types, with inheritance. Sorting this out is a bit of a problem. There is some syntax which we can use with the ALTER TYPE command which allows us to handle dependent types. Find out more.

Resources