Assuming that you are in PL/SQL and you need to split a value of a parameter or a variable into four variables, this could be a way:
declare
param varchar2(100);
param1 varchar2(100);
param2 varchar2(100);
param3 varchar2(100);
param4 varchar2(100);
begin
param := '1234@5432@4567@8763';
--
param1 := substr(param, 1, instr(param, '@', 1, 1)-1);
param2 := substr(param, instr(param, '@', 1, 1) +1 , instr(param, '@', 1, 2) - instr(param, '@', 1, 1)-1);
param3 := substr(param, instr(param, '@', 1, 2) +1 , instr(param, '@', 1, 3) - instr(param, '@', 1, 2)-1);
param4 := substr(param, instr(param, '@', 1, 3) +1 );
--
dbms_output.put_line('Param1: ' || param1);
dbms_output.put_line('Param2: ' || param2);
dbms_output.put_line('Param3: ' || param3);
dbms_output.put_line('Param4: ' || param4);
end;
With regular expressions, you can get the same result by searching the 1st, 2nd, ... occurrence of a string that is followed by a @
or by the end of the line ('$'
); a better explanation of this approach is described in the link gave by Gary_W in his comment
...
param1 := regexp_substr(param, '(.*?)(@|$)', 1, 1, '', 1 );
param2 := regexp_substr(param, '(.*?)(@|$)', 1, 2, '', 1 );
param3 := regexp_substr(param, '(.*?)(@|$)', 1, 3, '', 1 );
param4 := regexp_substr(param, '(.*?)(@|$)', 1, 4, '', 1 );
...