This might be a silly one but haven't been able to figure it out.
I have a Checkbox Group Item (with Static info) with 4 different options, I want to limit the amount of checked boxes to just two. Is this something possible to make?
Thank you
A checkbox is submitted as a colon-separated string. APEX_STRING has lots of functionality to convert the string to a pl/sql collection (and back). Once converted you can use functions like FIRST, LAST, COUNT. Or even compare collections using INTERSECT. For checking a max nr, a COUNT is enough.
So the validation would be something like this (type Function Body returning Error Text):
DECLARE
l_arr apex_t_varchar2;
BEGIN
l_arr := apex_string.split(:P13_CHECKBOX,':');
IF l_arr.COUNT > 2 THEN
RETURN 'Can only select 2 values';
ELSE
RETURN NULL;
END IF;
END;
Related
i have a function that puts a number in a var (var1). if var1 = 3 then create 3 new variables and assign a value for later send that values in an out type. I don't know how can i do, my code is something like this where "pos" acts like an INSTR() that i know its each 13 chars. And "newvar||var1" is because i want my vars names be newvar1, newvar2, newvar3, etc.:
FOR n IN 1..var1
LOOP
pos NUMBER(4):= 0;
newvar||var1 NUMBER(3);
newvar||var1 := SUBSTR(TO_NUMBER(numberInsideString), 1, 1+pos);
pos := pos+13;
END LOOP;
My question is, how a person who really know PLSQL would do that, im learning PLSQL please help. thank you.
What you want to try to do suggests that you need a one dimensional array in order repeatedly to assign new values for each iteration within the loop. One of the types in OWA package such as vc_arr(composed of VARCHAR2 data type values) is handy to define an array.
Coming to the code, you can start with moving the variables into the declaration section, and write such a simple code as a sample exercise
SET serveroutput ON
DECLARE
pos INT := 0;
numberInsideString VARCHAR2(100):='as12df34sdg345apl8976gkh4f11öjhöh678u7jgvj';
newvar OWA.vc_arr;
BEGIN
FOR n IN 1..3
LOOP
newvar(n) := SUBSTR(numberInsideString, 1, 1+pos);
pos := pos+5;
Dbms_Output.Put_Line(newvar(n));
END LOOP;
END;
/
a
as12df
as12df34sdg
I have a form that has two checkboxes, one is dup and one is sum. They both take values, add them up, and display the total in a display item. I have that part covered in an if statement on both checkboxes. What I need some assistance with, is a third if statement that, if sum is checked and the user checks dup, oracle forms pops up a message, uncheck the dup checkbox, and does nothing else. Here is the code I have so far :
IF :mn_outstanding_trans.cb_duplicate_activity ='Y' THEN
:mn_outstanding_trans.activity_cd := 'SUM';
:bl_control.gross_sum_of_trxs := :bl_control.gross_sum_of_trxs + :mn_outstanding_trans.gross_amt;
:bl_control.net_sum_of_trxs := :bl_control.net_sum_of_trxs + :mn_outstanding_trans.net_amt;
:bl_control.previous_activity_cd := :mn_outstanding_trans.activity_cd;
ELSIF :mn_outstanding_trans.cb_duplicate_activity ='N' THEN
:mn_outstanding_trans.activity_cd := ' ';
:bl_control.gross_sum_of_trxs := :bl_control.gross_sum_of_trxs - :mn_outstanding_trans.gross_amt;
:bl_control.net_sum_of_trxs := :bl_control.net_sum_of_trxs - :mn_outstanding_trans.net_amt;
:bl_control.previous_activity_cd := :mn_outstanding_trans.activity_cd;
END IF;
if sum is checked and the user checks dup, oracle forms pops up a message, uncheck the dup checkbox
It seems that you want to allow either DUP or SUM checkbox set, but never both. If that's so, then you should use a radio button instead of two checkboxes (which are supposed to exclude each other).
Also, maybe it would be easier to understand what you're talking about if you posted a screenshot of that form.
In my Oracle APEX application page I have checkbox item with multiple values. The source of checkbox is like this:
STATIC:One,Two,Apple
In page process I need to use the value from checkbox in PL/SQL code. As far as I understand I get colon separated values. Question is how to use those values and test if Value is One, then do this. If Two is checked as well, then do something more.
Depending on situation you can use:
Convert string with delimiter to table (you can use this as subquery):
select regexp_substr('1:2:3','[^:]+', 1, level) ID from dual
connect by regexp_substr('1:2:3', '[^:]+', 1, level) is not null;
ID
--
1
2
3
Check one value using instr:
where instr('1:2:3', '2') > 0
If value of the second argument of the function is contained inside the first argument - function returns its position, otherwise - 0.
For performance I prefer the INSTR function, e.g. INSTR(':'||:p_item||':',':Two:') > 0
The question sounds easy because only need a substring (name,1,1). But in the Hungarian language there are many letter wich contains multicharacter. eg : CS,DZ,DZS,LY,NY,SZ,TY,ZS
IF v_type='by_name' THEN
select DISTINCT name
into v_result
from my_table
where instr(_START_LETTERS_,substr(upper(v_name),1,1))>0 and ZIPCODE = v_act_zipcode;
return v_result;
and my table eg:
zipcode name _START_LETTERS
1234 Ryan A,B,C
1234 Bryan CS,D
And if i want to get my name CSanád i need to get CS not the first char C-> becuase i will get multirow exception.
Do you have anysuggestion to use get the first lettor? Or I have to write a huge if-else/case structure to make my code awful and impenetrable.
Thanks
I think the most straight-forward solution is to write a stored function that extracts the first letter:
create function hun_first_letter(name in varchar2) return varchar2 as
begin
if substr(upper(name),1,3) in ('DZS') then
return substr(name,1,3);
elsif substr(upper(name),1,2) in ('CS','DZ','LY','NY','SZ','TY','ZS','GY') then
return substr(name,1,2);
else
return substr(name,1,1);
end if;
end;
Try to replace substr(upper(v_name), 1, 1) with:
regexp_substr(upper(v_name), '^[[:alpha:][.cs.][.xx.][.yy.]]', 1, 1, 'i')
where
[:alpha:] is a special function (any letter) - actually, I don't know, maybe this function alone can find collating sequences (depending on NLS)
[.cs.] is an example of a collating sequence;
[.xx.], [.yy.] - other collating sequences possible in your NLS
So the regexp_substr above tries to find any letter OR 'cs' OR 'xx' OR 'yy' and etc.
It starts searching from position = 1 and returns occurance = 1. Finally, the search is case insentitive ('i')
But first of all you may check whether this function:
regexp_substr(upper(v_name), '^[[:alpha:]]', 1, 1, 'i')
would find your collating sequences (I'd be glad to know this)
This snippet not only causes a runtime error, it makes FPC close if I run it using the debugger.
procedure sortplayersbyscore(var vAux:tplayers);
procedure swap(var a:trplayers;var b:trplayers);
var
rAux:trplayers;
begin
rAux:=a;
a:=b;
b:=rAux;
end;
var
i,j:integer;
sorted:boolean;
begin
vAux:=playersarray;
i:=1;
sorted:=false;
while (i <= MAXPLAYERS -1) and not sorted do
begin
j:=1;
sorted:=true;
while (j <= MAXPLAYERS -i) do
begin
if (vAux[j].score < vAux[j+1].score) then
begin
swap(vAux[j],vAux[j+1]);
sorted:=false;
end;
inc(j);
end;
inc(i);
end;
end;
The code itself is part of a really big source file, I can post the whole thing but the responsible for the error is just that bunch of lines. The debugger terminates at line:
swap(vAux[j],vAux[j+1]);
tplayers is just a type defined as an array of records that contain score (an integer) among a bunch of other variables. trplayers is the type of the aforementioned records. I'm at a total loss; FPC (while not under debugging mode) spits an out-of-range error but under my watches I see that the variables I'm trying to read exist. Any help is really appreciated!
rAux:trplayers; have you typed a wrong symbol or the type here really contains "r" in its name?
It looks valid (other than typos) ... so let's try something simple.
What's the value of "j" when you abort?
If the debugger won't tell you, try adding:
writeln ('j = ', j);
just before the "swap" call.
As Yochai's question implied, your array needs to be dimensioned at least from
1 (or lower) to MAXPLAYERS (or larger). (I.e.: 0..MAXPLAYERS-1 would not work,
but 1..MAXPLAYERS should.)