Create a simple function named wordCount that takes a sentence (String) separated with space and count the words in the sentence. The function will return the number of words in the given sentence.Use the skeleton file, to develop the function.FUNCTION wordCount(str IN VARCHAR2)Function name : wordCountparameter : str datatype VARCHAR2Function return type : NumberNote:Do not change the function nameDo not change the argument count and orderDo not change the output text.You can query the table records using select statementDelimiter / is mandatory. If delimiter is missed, then while executing nothing will be displayedWhile executing, if you get WARNING: FUNCTION CREATED WITH COMPILATION ERRORS, then use SHOW ERRORS to display the errors in the function.Instructions:1. Create the function successfully2. Once the function is created, check the functionality of the function using appropriate select call3. DO NOT submit the select statement. Submit only the CREATE FUNCTION query.Sample Input and Output:If we execute the function with "HELLO WORLD" it should return 2.SubmitSaveExecutePrevious Submission
Question
Create a simple function named wordCount that takes a sentence (String) separated with space and count the words in the sentence. The function will return the number of words in the given sentence.Use the skeleton file, to develop the function.FUNCTION wordCount(str IN VARCHAR2)Function name : wordCountparameter : str datatype VARCHAR2Function return type : NumberNote:Do not change the function nameDo not change the argument count and orderDo not change the output text.You can query the table records using select statementDelimiter / is mandatory. If delimiter is missed, then while executing nothing will be displayedWhile executing, if you get WARNING: FUNCTION CREATED WITH COMPILATION ERRORS, then use SHOW ERRORS to display the errors in the function.Instructions:1. Create the function successfully2. Once the function is created, check the functionality of the function using appropriate select call3. DO NOT submit the select statement. Submit only the CREATE FUNCTION query.Sample Input and Output:If we execute the function with "HELLO WORLD" it should return 2.SubmitSaveExecutePrevious Submission
Solution
Here is a simple function in PL/SQL that counts the number of words in a given sentence:
CREATE OR REPLACE FUNCTION wordCount(str IN VARCHAR2)
RETURN NUMBER IS
word_count NUMBER := 1;
BEGIN
FOR i IN 1..LENGTH(str) LOOP
IF SUBSTR(str, i, 1) = ' ' THEN
word_count := word_count + 1;
END IF;
END LOOP;
RETURN word_count;
END;
/
This function works by looping through each character in the input string. If it encounters a space character, it increments the word count by 1. The function starts with a word count of 1 because a sentence without spaces has one word.
To test this function, you can use a SELECT statement like this:
SELECT wordCount('HELLO WORLD') FROM dual;
This should return 2, as there are two words in "HELLO WORLD".
Similar Questions
Create a simple function named characterCount that takes a string and count the characters in the string. The function will return the number of characters in the given string.Use the skeleton file, to develop the function.FUNCTION characterCount(str IN VARCHAR2) Function name : characterCountparameters : str datatype VARCHAR2Function return type : NumberNote:Do not change the function nameDo not change the argument count and orderDo not change the output text.You can query the table records using select statementDelimiter / is mandatory. If delimiter is missed, then while executing nothing will be displayedWhile executing, if you get WARNING: FUNCTION CREATED WITH COMPILATION ERRORS, then use SHOW ERRORS to display the errors in the function.Instructions:1. Create the function successfully2. Once the function is created, check the functionality of the function using appropriate select call3. DO NOT submit the select statement. Submit only the CREATE FUNCTION query.Sample Input and Output:If we execute the function with "HELLO" it should return 5.SubmitPreviously Executed Queries
We are given a function countWordOccurrences that takes two string parameters sentence and word."Sentence" is a string made up of multiple words separated by spaces.We have to find how many times 'word' occurs in the given 'sentence'.The 'word' should be an exact match.Note: The case (uppercase/lowercase) of the letters in the word does NOT matter.InputFirst line contains space separated series of words which represents the string "sentence".Second line contains a single word "word".Constraints1 ≤ length(sentence), length(word) ≤ 104length(word) ≤ length(sentence)OutputWe have to return an integer which is the number of occurrences of the single word 'word' in the string 'sentence'.
Complete the find_string(sentence, string_to_find) function that takes two string parameters, namely sentence and string_to_find. This function should return the number of times that the parameter, string_to_find, appears in the sentence.
Write a function repeat_word_count(text, n) that takes a string text and a positive integer n, converts text into a list of words based on simple whitespace separation (with no removal of punctuation or changing of case), and returns a sorted list of words that occur n or more times in text. For example:>>> repeat_word_count("buffalo buffalo buffalo buffalo", 2)['buffalo']>>> repeat_word_count("one one was a racehorse two two was one too", 3)['one']>>> repeat_word_count("how much wood could a wood chuck chuck", 1)['a', 'chuck', 'could', 'how', 'much', 'wood']
Select the correct implementation of a piece of code that accepts a sentence as input and prints the number of words in it. A sentence is just a sequence of words with a space between consecutive words. You can assume that the sentence will not have any other punctuation marks. You can also assume that the input string will have at least one word.1sentence = input()2space = ' ' # there is a single space between the quotes3num_words = sentence.count(space)4print(num_words)1sentence = input()2space = ' ' # there is a single space between the quotes3num_words = sentence.count(space) + 14print(num_words)1sentence = int(input())2space = ' ' # there is a single space between the quotes3num_words = sentence.count(space)4print(num_words)1sentence = input()2num_words = len(sentence)3print(num_words)
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.