8
Answers

How to use keyword in a sentence?

Photo of Syed Arbab Ahmed

Syed Arbab Ahmed

14y
2.9k
1


I am calculating the length of a sentence using Length (scalar function), then I also used that keyword in the sentence, but I am having an error for all the queries below:


                              Error: Missing right parenthesis.

1-SELECT LENGTH('This sentence's length will be calculated') "Length of characters"
FROM dual;

2- SELECT LENGTH('This sentence's 'length' will be calculated') "Length of characters"
FROM dual;

3- SELECT LENGTH('This sentence's "length" will be calculated') "Length of characters"
FROM dual;

4-SELECT LENGTH('This sentence's "\length\" will be calculated') "Length of characters"
FROM dual;


5- SELECT LENGTH('This sentence's '\length\' will be calculated') "Length of characters"
FROM dual;

What should be the correct way to write this query?

Thanks in advance

Answers (8)

0
Photo of Suthish Nair
NA 30.5k 7.2m 14y
If this query got resolved then please Accept the post that helped you as Answer.

So other members can easily find the answers.
0
Photo of Suthish Nair
NA 30.5k 7.2m 14y

Sayed,

As you said "I want to learn, how to be a good programmer. ", did you tried to explore why the error came up.

No, but you got a reply with sql statement and you copy paste that statement  into editor and executed, you got the o/p.

I posted clearly, to escape single quote you need to use double quotes or two single quotes.

This is how people learn, from errors, mistakes etc...

0
Photo of Syed Arbab Ahmed
NA 104 0 14y
Your reply was not clear as you just wrote

use " (double quotes) or '' (two single quotes) to escape single quote

where, when & how to use it? If you would have write the query using quotes, It would have been better for a novice like me.


0
Photo of Suthish Nair
NA 30.5k 7.2m 14y
so you didnt see my post reply?
0
Photo of Syed Arbab Ahmed
NA 104 0 14y
1- The query below worked fine:

SELECT LENGTH('This sentence''s length will be calculated') "Length of characters"
FROM dual;

Your query had Len instead of length which gave "Invalid Identifier" error.

2- The good point of your reply was single quote after sentence word along with its apostrophe, I got it from there, but it took time as you did not defined it.
0
Photo of sanjay dobhal
NA 9 0 14y
SELECT LEN('This sentence''s length will be calculated') 'Length of characters'
0
Photo of Manikavelu Velayutham
253 7.6k 2.5m 14y

SELECT
len('This sentence''s length will be calculated') "Length of characters" FROM dual
This is the right way
 
 
0
Photo of Suthish Nair
NA 30.5k 7.2m 14y
use " (double quotes) or '' (two single quotes) to escape single quote