Writing plsql function to find out repeating character in a string
I need to write one pl sql function to compare 2 consecutive character in a word that they are same or not, if same return false otherwise return true. could any one help me on this
what i have written pasting here code or make me correct
CREATE OR REPLACE FUNCTION validate_password (v_string IN VARCHAR2)
RETURN BOOLEAN
IS
v_number NUMBER (3) := 1;
i_length NUMBER (3);
BEGIN
SELECT LENGTH (v_string) INTO i_length FROM DUAL;
IF (i_length > 0)
THEN
FOR v_number IN v_number .. i_length
LOOP
substring (v_string, v_number, 1) :=
substring (v_string, v_number + 1, 1);
v_number := v_number + 1;
END LOOP;
END IF;
RETURN v_string;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('message');
END;
Thanks in advance.
no need to SELECT FROM DUAL;
How do I ask a question on the forums?
SQL and PL/SQL FAQ
scroll down to #9 to see how to use tags as below
[code]
CREATE OR replace FUNCTION Validate_password (v_string IN VARCHAR2)
RETURN BOOLEAN
IS
v_number NUMBER (3) := 1;
i_length NUMBER (3);
BEGIN
i_length := Length (v_string) ;
IF ( i_length > 0 ) THEN
FOR v_number IN v_number .. i_length LOOP
Substring (v_string, v_number, 1) :=
Substring (v_string, v_number + 1, 1)
v_number := v_number + 1;
END LOOP;
END IF;
RETURN v_string;
EXCEPTION
WHEN OTHERS THEN
dbms_output.Put_line ('message');
END;
[/code]
Similar Messages
-
Writing a query to find out who is having a given responsibility name.
Hi,
I am new to Oracle Apps and have no idea about its tables. Can anyone please help me in writing a query to find out who is having a given responsibility name.
Thanks in advance.
Regards
HimanshuHi
you can get required data by using this query
select usr.user_name
, res.responsibility_name
from fnd_user usr
, FND_USER_RESP_GROUPS_DIRECT usrrep
, fnd_responsibility_tl res
where usr.user_id=usrrep.user_id
and usrrep.responsibility_id=res.RESPONSIBILITY_ID
group by usr.user_name,res.responsibility_name
Regards,
Venky -
How we can find the last character in a string(Urgent Plz!)
Gurus!
How we can find the last character in a string.
e.g i have a string say "Str" with value "10-01".
Now i want to find the last character in "Str" i.e "ONE=1".
i am using Oracle developer 6i with Oracle 8i(1.7).
Plz help!
Many thanks!Use the substr() and length() functions -
x := '10-01';
y := substr(x, length(x)); -
Function to find out datatype of a variable
hi
can anyone tell me a function that can find out what type of datatype a variable belongs to...
thank u
rajivYou can overload the function in a package.
SQL> create or replace package say_kids as
2 function what_type_is_it (p number) return varchar2;
3 function what_type_is_it (p varchar2) return varchar2;
4 function what_type_is_it (p date) return varchar2;
5 function what_type_is_it (p sys_refcursor) return varchar2;
6 end;
7 /
Package created.
SQL> create or replace package body say_kids as
2 function what_type_is_it (p number) return varchar2 is
3 begin
4 return 'It''s a number.';
5 end;
6 function what_type_is_it (p varchar2) return varchar2 is
7 begin
8 return 'It''s a string.';
9 end;
10 function what_type_is_it (p date) return varchar2 is
11 begin
12 return 'It''s a date.';
13 end;
14 function what_type_is_it (p sys_refcursor) return varchar2 is
15 begin
16 return 'It''s a cursor.';
17 end;
18 end;
19 /
Package body created.
SQL> select say_kids.what_type_is_it ( 1 ) from dual;
SAY_KIDS.WHAT_TYPE_IS_IT(1)
It's a number.
SQL> select say_kids.what_type_is_it ( 'test' ) from dual;
SAY_KIDS.WHAT_TYPE_IS_IT('TEST')
It's a string.
SQL> select say_kids.what_type_is_it ( sysdate ) from dual;
SAY_KIDS.WHAT_TYPE_IS_IT(SYSDATE)
It's a date.
SQL> var c refcursor
SQL> select say_kids.what_type_is_it ( :c ) from dual;
SAY_KIDS.WHAT_TYPE_IS_IT(:C)
It's a cursor.
SQL> -
Given a table with some columns and data associated with that. Need to find out a column or a combination of some columns, so that the values or combination of values will be unique in the table.
The table and number of columns and the columns will be dynamic.
Can you please help me with the solution?f8d0dcea-cdf0-4935-8734-632fe021456c wrote:
No key is defined in the table.
Suppose a table contains 20 columns then I need the unique combinations of all columns.
Example: A table 'Employee' has 4 columns: Emp_No, Emp_Name,Passport_No,Emp_Designation. No key is defined for Employee table. Need to find out which column(single column and combination if columns) have unique values. Like, First check if Emp_No is unique then check Emp_No+Emp_Name is unique, then check if Emp_No+Emp_Name+Passport_No is unique, then check Emp_No+Emp_Name+Passport_No+Emp_Designation is unique.
Then again try with the combination of Emp_No+Passport_No and so on. In this way I need to find out all the combinations having unique values.
As Paul says, that will be a waste of time, as it will taken a lot of processing for all the possibilities, checking all the data each time to determine which combinations of columns provide uniqueness. What happens if someone inserts or deletes some data whilst your doing it?
You'd be quicker to manually look at the tables, and make an educated guess and then test for uniqueness with a quick query on that guess. -
Is a way to find out the encoding of a String?
Doesn anyone know how to find out the encoding?
There are some circumstances in which a file (or more
generally, a stream) may expose its own encoding,
IIRC. But of course that's the exception, not the rule.As part of a higher level protocol, sure. HTTP, for example, may have it in a couple places (headers or in the HTML head section). Plain text files do not, however.
But anyway at this point I'm not convinced that
anyone knows for sure what the OP wanted or needed.I agree with that. Not convinced the OP knows, either.
Was he really looking for a heuristic to correctly
y guess the encoding of a stream of bytes, so that
encoding could be used as input to a String
constructor? Or did he just not know how to use the
API?To the OP:
If you have a String, there's no encoding, it's all Unicode chars in the string.
If you have a bunch of bytes (byte[], file, input stream, whatever), then there is some encoding. If you don't know what the encoding is, there's no 100% sure way to figure it out. Some code exists, as mentioned, that can make educated guesses, particularly if you know it's one of a few possible choices. Beyond that, bytes are bytes are bytes, and how they are interpreted by character based classes/methods (like new String(byte[], String)) is defined by the encoding you tell it to use.
So aside from that, what's the issue you're trying to solve? -
How to use statement "search" to find out the asterisk in a string?
Hi Guys,
I encouter this question:I need to use "search" statement to find out the asterisk or the underscore in one string,you know these two symbols are wildcards. I don't know how to use statement "search" to find them??
could you please give me some help!!
Thanks a lot,Villy.Lv
Edited by: Villy Lv on Sep 26, 2010 6:50 AMHi,
You cant usesearch statement, rather did you try with CS using IF condition? even you can go with loop statement too.
DATA STRING TYPE STRING.
DATA C TYPE C.
DATA LEN TYPE I VALUE 0.
DATA I TYPE I VALUE 0.
LEN = STRLEN(STRING).
LOOP LEN > I
C = STRING+I.
IF(C == '*' OR C == '_').
ENDIF.
I = I + 1.
ENDLOOP.
This way also you can use.
Hope this may help you.
Regards!
Sheik -
How to find out the repeated character in a string value?
Dear People,
I want to trace out the names where a character occured more than once.for ex, i need o/p as
ENAME
ALLEN
TURNER
ADAMS
In which all the above name consists of repeated characters.
I use Oracle 10g and i tried using REGEXP say for ex,
SELECT ENAME FROM EMP WHERE REGEXP_LIKE(ENAME,'L{2}');
ENAME
ALLEN
MILLERbut this works only for single character.how to specify condition for any character?.pls suggest me.
With Regards
VIDSHere is one way you can use from version 10 upwards:
SQL> with emp as
2 ( select 7369 empno, 'SMITH' ename, 'CLERK' job, 7902 mgr, date '1980-12-17' hiredate, 800 sal, NULL comm, 20 deptno from dual union all
3 select 7499, 'ALLEN', 'SALESMAN', 7698, date '1981-02-20', 1600, 300, 30 from dual union all
4 select 7521, 'WARD', 'SALESMAN', 7698, date '1981-02-22', 1250, 500, 30 from dual union all
5 select 7566, 'JONES', 'MANAGER', 7839, date '1981-04-02', 2975, NULL, 20 from dual union all
6 select 7654, 'MARTIN', 'SALESMAN', 7698, date '1981-09-28', 1250, 1400, 30 from dual union all
7 select 7698, 'BLAKE', 'MANAGER', 7839, date '1981-05-01', 2850, NULL, 30 from dual union all
8 select 7782, 'CLARK', 'MANAGER', 7839, date '1981-06-09', 2450, NULL, 10 from dual union all
9 select 7788, 'SCOTT', 'ANALYST', 7566, date '1982-12-09', 3000, NULL, 20 from dual union all
10 select 7839, 'KING', 'PRESIDENT', NULL, date '1981-11-17', 5000, NULL, 10 from dual union all
11 select 7844, 'TURNER', 'SALESMAN', 7698, date '1981-09-08', 1500, 0, 30 from dual union all
12 select 7876, 'ADAMS', 'CLERK', 7788, date '1983-01-12', 1100, NULL, 20 from dual union all
13 select 7900, 'JAMES', 'CLERK', 7698, date '1981-12-03', 950, NULL, 30 from dual union all
14 select 7902, 'FORD', 'ANALYST', 7566, date '1981-12-03', 3000, NULL, 20 from dual union all
15 select 7934, 'MILLER', 'CLERK', 7782, date '1982-01-23', 1300, NULL, 10 from dual
16 )
17 select ename
18 , e
19 , count(*)
20 from ( select ename
21 , e
22 from emp
23 model
24 return updated rows
25 partition by (ename)
26 dimension by (0 i)
27 measures (ename e)
28 ( e[for i from 1 to length(e[0]) increment 1] = substr(e[0],cv(i),1)
29 )
30 )
31 group by ename
32 , e
33 having count(*) > 1
34 /
ENAME E COUNT(*)
SCOTT T 2
MILLER L 2
ADAMS A 2
ALLEN L 2
TURNER R 2
5 rows selected.Regards,
Rob. -
Writing a function to find whether a value is present in a sql query output
Hi gurus,
I would like to write a function to which i will pass a value and a sql query as parameters.
Now the function needs to execute that sql query and find whether the given value is present in the output list
when the query is executed. If it is present it should return 'T' otherwise 'F'
My function will look like
CREATE FUNCTION CHECK_VALUE(VALUE VARCHAR2,V_SQL VARCHAR2) RETURN VARCHAR2
SELECT CHECK_VALUE('Dallas','SELECT LOCATION_CODE FROM HR_LOCATIONS')
It should check whether the value 'Dallas' is present in the output list returned by the sql query.
Any help will be appreciated.
Thank you.CREATE OR REPLACE
FUNCTION CHECK_VALUE(
VALUE VARCHAR2,
V_SQL VARCHAR2
RETURN VARCHAR2
IS
RETVAL VARCHAR2(4000);
REFCUR SYS_REFCURSOR;
BEGIN
OPEN REFCUR FOR V_SQL;
LOOP
FETCH REFCUR INTO RETVAL;
EXIT WHEN REFCUR%NOTFOUND;
IF RETVAL = VALUE
THEN
CLOSE REFCUR;
RETURN 'T';
END IF;
END LOOP;
CLOSE REFCUR;
RETURN 'F';
END;
Function created.
SQL> SET SERVEROUTPUT ON
SQL> EXEC DBMS_OUTPUT.PUT_LINE(CHECK_VALUE('DALLAS','select loc from dept'));
T
PL/SQL procedure successfully completed.
SQL> EXEC DBMS_OUTPUT.PUT_LINE(CHECK_VALUE('PARIS','select loc from dept'));
F
PL/SQL procedure successfully completed.
SQL> SY. -
Plsql query to find out the concurrent programs attaching a plsql package
I want to find all the concurrent programs attaching a particular package. Please provide me with the appropriate query to get that.
Hello,
1- First thing: we are talking about a SQL query (and not a PL/SQL query).
2- I would like to add an additional filter to the query of shazi as the query should show only PL/SQL packages
SELECT
fcp.CONCURRENT_PROGRAM_ID
,fcp.concurrent_program_name
, fcpt.user_concurrent_program_name
, DECODE(fe.execution_method_code
, 'I', 'PL/SQL'
,'P', 'Reports'
,'C', 'SQL Loader'
,'Q', 'SQL Plus'
,'K', 'Java'
,'H', 'OS executable'
,'B' , 'Req. Set Stage'
) EXECUTION_METHOD
,UPPER(EXECUTION_FILE_NAME) PACKAGE_BODY
from
fnd_concurrent_programs_tl fcpt
, fnd_executables fe
,fnd_concurrent_programs fcp
where 1=1
--and fcpt.concurrent_program_id = fcr.concurrent_program_id
and fe.executable_id = fcp.executable_id
and fcpt.concurrent_program_id = fcp.concurrent_program_id
and fe.execution_method_code = 'I' /* here's the additional filter */
--and fcpt.user_concurrent_program_name = :P_USER_CONC_PROGRAM_NAME
--fcp.concurrent_program_name = :P_CONC_PROGRAM_NAME /* using this filter would use an index */
Lalaina -
Find out the character set of a database
Hi,
I need to know the character set of a database. I don't know which command or utility can I use.
ThanksThis forum is for Oracle Repository.
However, connect as system and run
select * from nls_database_parameters
you should see the nls info. -
Count the repeated character in a string
Hi Great Gurus,
Please tell me how to know how many times a given character repeats in a string.
Please mail me .
Thanks Gurus,
Rahulhi,
same thread----
Re: find number of occurances of a particular character
data: var1(30) type c value 'ghghj#ghjgjgh#ghjghjg#ghjg#'.
data : totcnt type i,
cnt type i,
v type c,
n type i.
cnt = strlen( var1 ).
do cnt times.
move var1+n(1) to v.
if v eq '#'.
totcnt = totcnt + 1.
endif.
n = n + 1.
if n = cnt .
exit.
endif.
enddo.
write:/ 'No of #s', totcnt .
Regards
Reshma -
How to find out no of lines in String
Hi all,
How to find no of lines in a multi lined String.
For example.
String str = "hjkhjkhjhjhkhlk\nfjdhfjhdjfhjdhfj\nfdhfjdhjfhdj\ndfjdkjffjdfjk\nfdffdh";
Here there are 5 lines because there are "\n".
I am not able to substring with "\n".
Any idea please?javadocs StringTokenizer
StringTokenizer(String str, String delim)
Constructs a string tokenizer for the specified string.
Method Summary
int countTokens() -
To find out the position on a string..
Hi,
I want to write a oracle query where i will pass the string and it will give me the position of 'a' on that string.
I dont want to write the procedure, only the select statement. Could we do this..
Like if i will pass Haraprasad, it should give me 2,4,7,9
if i will pass Gopala, it should give me 4,6
Thanks,
Haraprasad..Like if i will pass Haraprasad, it should give me 2,4,7,9
if i will pass Gopala, it should give me 4,6nice homework assignment.
How are YOU going to solve this? -
To find out if the value in string is double or integer
Hello,
I am getting a value from a db which is a string,but some of those
values could be doubles or integers
is there a way to check a string as if it were a double or int,
something like
String s="25.05"; //a double but is a string
if(isDouble.s){
//do some
the point is that I am not sure which string might have a double or int value
so I would rather test every string,and if they are double or float then proces or
else if they are not the do something else with them,
Help is greatly appreciatedHi,
One possible solution is to parse the String into a double and catch the exception:
String s="25.05";
try {
Double dbl = new Double(s);
// do some
} catch (NumberFormatException ex) {}Hope this helps,
Kurt.
Maybe you are looking for
-
Does Keynote 6.0 no longer support Transparent GIF or Quicktime Animations?
So, I have some sample files here: Bees and Honey Clear Quicktime http://www.presentermedia.com/blog/wp-content/uploads/2013/10/beehive_bees_400_c lr_12723.mov Bees and Honey Clear GIF http://www.presentermedia.com/blog/wp-content/uploads/2013/10/bee
-
Save for web - "selected slices" only saves first one selected
This is frustrating me beyond words. I'm trying to export a ton of slices using Save for Web/Devices, and when I choose "selected slices" only 1 slice is actually saved. Has something changed or is this a bug?
-
Hi.. What do u mean BY RR Queue? i know it is replication and reallignment queue.. But whats the need of this one? is it related to data flow with mobile..? 2) what do u mean LUW's? logical unit of work....?what is the significance of thi
-
Since updating to Firefox 23.0.1, I am unable to connect to our company servers. The error message is "Certificate type not approved for application.", and it gives me no option to create an exception. In previous versions, Firefox gave the option of
-
MONI table data encoding logic
Hi All, I want to know how the MONI table data is encoded. Where can I find this information? For background, I want to extract transaction usage information from MONI. I do not want to use any SAP report for that. I want to pull data directly from M