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..

// 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..

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..

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..

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..

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..

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..

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

 Is This Answer Correct ? 1 Yes 8 No

More SQL PLSQL Interview Questions

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

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

What is the difference between numeric and autonumber?

What is TABLE SPACE?

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.

What does where 1 1 mean in sql?

What is trigger and stored procedure in sql?

how to write utl file pkg in SQL

what is meant by urlencode and urldocode? : Sql dba

what are properties of a transaction? : Sql dba

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?

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

Categories