Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number of lines in SQLite string

Tags:

sqlite

I have an SQLite table where a column is of type 'text'. Each item in that column is program code. I want to find out how many lines each text item is. i.e. The following should be 3 lines:

program "help"
print "Help"
return.
like image 290
John Smith Avatar asked Dec 06 '25 19:12

John Smith


1 Answers

You can count the \ns by doing

LENGTH(TheColumn) - LENGTH(REPLACE(TheColumn, X'0A', '')) + 1
like image 112
dan04 Avatar answered Dec 08 '25 15:12

dan04



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!