Isnumeric in postgreSQL [duplicate] - java

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.

Related

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

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

using postgresql NOT IN statement [duplicate]

This question already has answers here:
PreparedStatement IN clause alternatives?
(33 answers)
Closed 3 years ago.
i have this query in spring:
private String SQL_Clear_Deleted_Options = "DELETE FROM vote_votes WHERE poll_id=? AND option_id NOT IN ?"
my problem is with second ?. the correct form would be (id1,id2,id3,...). how can i pass a string like cl="0,1,2,3,6" to this query?
i'm using jdbcTemplate. so it would be
jdbcTemplate.update(SQL_Clear_Deleted_Options, id,cl)
what should be cl?
You can use setArray of PreparedStatement to set multiple values.
https://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html#setArray(int,%20java.sql.Array)
And the array should be of the correct type, so you could create it with the Connection.createArrayOf function:
https://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html#createArrayOf(java.lang.String,%20java.lang.Object[])
You can see a lot of discussions about that topic on SO already, e.g.:
How to use an arraylist as a prepared statement parameter
Edit: Forgot to mention: The JdbcTemplate should set the Parameter correctly when the Array is given as parameter.

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?

Apply formatting to variables in Java [duplicate]

This question already has answers here:
Converting Integer to String with comma for thousands
(15 answers)
Closed 9 years ago.
Is there a simple way to format variables on a GUI with spaces (or commas) between so its easier to read.
Example:
int x = 12000000;
JLabel.setText(x);
which outputs 1200000, however I am trying to achieve on of the following.
1 200 000
1,200,000
If you want to use the user's locale to determine whether to use commas or decimal points, use the following:
String formattedNum = NumberFormat.getIntegerInstance().format(x);
For Americans, you would see 1,200,000.
You can try this:
int x = 12000000;
JLabel.setText(NumberFormat.getInstance().format(x));

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