Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


How to find the count of letter "L" in HELLO

Answers were Sorted based on User's Feedback



How to find the count of letter "L" in HELLO..

Answer / dinesh

// in SQL:------------------------------------------
Select length('hello')-length(replace('hello','l','')) From
DUAL;

// IN PL/SQL:-------------------------------------------

create or replace Procedure count_char(name varchar2,c varchar2) IS
m number(11):=0;
d number(11);
a number(11);
b number(11):=1;
BEGIN
a:=length(name);
for i in 1..a
LOOP
IF INSTR(NAME,c,b)>=1 THEN
d:=INSTR(NAME,c,b);
m:=m+1;
b:=d;
END IF;
b:=b+1;
END LOOP;
DBMS_OUTPUT.PUT_LINE('count of '||' '||c ||' '||'is'||' '|| m||' '||'in'||' '||name);
end;

Is This Answer Correct ?    4 Yes 0 No

How to find the count of letter "L" in HELLO..

Answer / mahesh

select regexp_count('hello','l') from dual;

or

SELECT LENGTH('HELLO')-LENGTH(REPLACE('HELLO','L',NULL)) FROM DUAL;

Is This Answer Correct ?    4 Yes 1 No

How to find the count of letter "L" in HELLO..

Answer / ansupriya

SELECT LENGTH(REPLACE(TRANSLATE('HELLO','HEO',' '),' ')) FROM DUAL

Is This Answer Correct ?    1 Yes 1 No

How to find the count of letter "L" in HELLO..

Answer / ajit nayak

FUNCTION
---------
CREATE OR REPLACE FUNCTION FN_WORD_CNT (V_NAME VARCHAR2,V_SRCH_WRD VARCHAR2)
RETURN NUMBER
IS

I_COUNT NUMBER;
I_WRD_CNT NUMBER;

TYPE V_WORD IS TABLE OF VARCHAR2(10)
INDEX BY BINARY_INTEGER;
V_S_WORD V_WORD;

BEGIN
I_WRD_CNT := LENGTH(V_NAME);
DBMS_OUTPUT.PUT_LINE(I_WRD_CNT);
I_COUNT := 0;

FOR I IN 1..I_WRD_CNT
LOOP
SELECT SUBSTR(V_NAME,I,1)
INTO V_S_WORD(I)
FROM DUAL;

END LOOP;
FOR I IN 1..V_S_WORD.COUNT
LOOP

IF(V_S_WORD(I) = V_SRCH_WRD) THEN
I_COUNT := I_COUNT + 1;

END IF;
END LOOP;
RETURN I_COUNT;
END;

FOR RUN
-------

select FN_WORD_CNT('AJIT','A')
from dual;

PROCEDURE
---------
CREATE OR REPLACE FUNCTION FN_WORD_CNT (V_NAME VARCHAR2,V_SRCH_WRD VARCHAR2)
RETURN NUMBER
IS

I_COUNT NUMBER;
I_WRD_CNT NUMBER;

TYPE V_WORD IS TABLE OF VARCHAR2(10)
INDEX BY BINARY_INTEGER;
V_S_WORD V_WORD;

BEGIN
I_WRD_CNT := LENGTH(V_NAME);
DBMS_OUTPUT.PUT_LINE(I_WRD_CNT);
I_COUNT := 0;

FOR I IN 1..I_WRD_CNT
LOOP
SELECT SUBSTR(V_NAME,I,1)
INTO V_S_WORD(I)
FROM DUAL;

END LOOP;
FOR I IN 1..V_S_WORD.COUNT
LOOP

IF(V_S_WORD(I) = V_SRCH_WRD) THEN
I_COUNT := I_COUNT + 1;

END IF;
END LOOP;
RETURN I_COUNT;
END;

RUN THIS PROCEDURE
------------------
DECLARE
v_name varchar2(10) := '&name';
v_srch varchar(2) := '&str';
i_cnt number;
begin
DBMS_OUTPUT.PUT_LINE('ENTER NAME '||v_name||CHR(10)||' SEARCH STR '||v_srch);
P_FN_WORD_CNT(v_name,v_srch,i_cnt);
END;

Is This Answer Correct ?    0 Yes 0 No

How to find the count of letter "L" in HELLO..

Answer / a.brahmam

select length('HELLO')-length(replace('HELLO','L')) from dual;
ANS:=2

Is This Answer Correct ?    0 Yes 0 No

How to find the count of letter "L" in HELLO..

Answer / kuldeep123

select regexp_count('HEllO','L') from dual;

Is This Answer Correct ?    0 Yes 0 No

How to find the count of letter "L" in HELLO..

Answer / radhesh

SELECT 'HELLO', INSTR('HELLO','L') AS INSTR FROM dual;

Is This Answer Correct ?    1 Yes 8 No

Post New Answer



More SQL PLSQL Interview Questions

If we update a complex view, is base table will get update ?

2 Answers   Ardee Technologies, HCL,


How to get the 3rd column(i.e all the data along with the column name)in a table?

2 Answers   Logica CMG,


What is the difference between numeric and autonumber?

0 Answers  


What is TABLE SPACE?

4 Answers   ABB, TCS,


table name: prod there are three fields in the table that are 1.proddate 2.prodQty 3.model Day wise prodQty is stored in the table prod write a query to display total prodqty in the year 2004 april.

2 Answers   Maruti Suzuki,






What does where 1 1 mean in sql?

0 Answers  


What is trigger and stored procedure in sql?

0 Answers  


how to write utl file pkg in SQL

1 Answers   Oracle,


what is meant by urlencode and urldocode? : Sql dba

0 Answers  


what are properties of a transaction? : Sql dba

0 Answers  


If there are 1 to 100 numbers in a table and in that 100 numbers some 10 numbers are deleted.I want to find out the missing numbers between 1 to 100 by pl/sql how?

8 Answers   JPMorgan Chase,


If a View on a single base table is manipulated will the changes be reflected on the base table?

5 Answers  






Categories