How could I split one row into multiple rows? [duplicate] - java

This question already has answers here:
Turning a Comma Separated string into individual rows
(16 answers)
Closed 12 months ago.
So, I have this table
col1
1,2,3
1,4,5
and I want it to be like this
col1
1
2
3
1
4
5

You can split string like this:
SELECT
value
FROM
STRING_SPLIT('a,b,c', ',');

It seems your delimited data is in a column. If so, you can use string_split() in concert with a CROSS APPLY
Select col1=B.value
From YourTable A
Cross Apply string_split(A.col1,',') B

Related

How to print character repeatedly using specifier instead of loop in java? [duplicate]

This question already has answers here:
Simple way to repeat a string
(32 answers)
Closed 6 months ago.
I want to print a char '=' repeatedly where I give the no. of times the asterisk should be repeated.
Example: count = 20 and I want to print ==================== using printf() and format specifiers.
String#repeat
Simply append a string generated by String#repeat method, in Java 11+.
String result = "=".repeat( 20 ) ;
====================

How randomise the sqlite syntax [duplicate]

This question already has answers here:
Select random row from a sqlite table
(7 answers)
Closed 3 years ago.
I want to randomize some values using ID in sqlite query.
* am using quiz app and want to randomize our question. In database there is a column for category where category id is used to select proper cat and I want randomize only question with limit *
String query = "select * from quiz where id =" +id ;
SELECT *
Says to select all non-hidden columns from the table. The correct syntax for retrieving specific columns is to code the specific column names (or if there are potential ambiguities tablename.columnname e.g. quiz.question).
So you would want
SELECT question FROM quiz .....
To select a random question, assuming that question is the required column name, then you could use :-
String query = "SELECT question FROM quiz ORDER BY random();";
If you wanted to limit the number of rows returned you could use
String query = "SELECT question FROM quiz ORDER BY random() LIMIT 10;";

Passing variable into IN clause in java [duplicate]

This question already has answers here:
Hibernate Criterion IN Clause 1000 break up
(3 answers)
Java Oracle exception - "maximum number of expressions in a list is 1000"
(7 answers)
Closed 5 years ago.
I am constructing a hibernate query and I pass a list of String values into the IN clause. That list sometimes happens to be more than 1000 values so I receive an error. I have looked up some solutions like breaking that clause into smaller ones or making temporary table, but none of them showed how actually it is better to work with variable list.
So if I had something like:
SELECT * FROM MY_TABLE WHERE NAME IN (list).
What would be the best way to handle this?

Isnumeric in postgreSQL [duplicate]

This question already has answers here:
Postgres query to check a string is a number
(8 answers)
Closed 5 years ago.
I have column in my database table named 'anwers' of type 'character'. Data may be numbers or strings that's why I used column of type 'character'. And I have to calculate the sum of anweres if it is a numeric. But I found that ISNUMERIC will not work for column type of text/character .
How can I solve this issue?
In DB2, I've done something like UCASE(answers) = LCASE(answers) to test if it's numeric. This could work if your column is simple letters/numbers, not including punctuation characters.

how do I split string equation into its own array of strings? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How would I Evaluate a certain formula?
How would I split this formula into an array of characters each having their own number in the array:
a1+a2+a5*((a1+a6)*a3)
one I have added the spaces I am going to get column 1 because a1 will indicate column one and it will contain a number than I will add that to column 2. I am not allowed to use a tree or any of those other things just stacks and I have been asking that. But people keep telling me to use libraries and trees I am only in a 200 level course !
You need a grammar and a parser to do this in a general way. Something like this.

Categories

Resources