notnull

insert a NOT NULL column to an existing table

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 10:29:12
问题 I have tried: ALTER TABLE MY_TABLE ADD STAGE INT NOT NULL; But it gives this error message: ALTER TABLE only allows columns to be added that can contain nulls or have a DEFAULT definition specified 回答1: As an option you can initially create Null-able column, then update your table column with valid not null values and finally ALTER column to set NOT NULL constraint: ALTER TABLE MY_TABLE ADD STAGE INT NULL GO UPDATE MY_TABLE SET <a valid not null values for your column> GO ALTER TABLE MY_TABLE

How do I check if a SQL Server text column is empty?

前提是你 提交于 2019-12-17 17:25:20
问题 I am using SQL Server 2005. I have a table with a text column and I have many rows in the table where the value of this column is not null, but it is empty. Trying to compare against '' yields this response: The data types text and varchar are incompatible in the not equal to operator. Is there a special function to determine whether the value of a text column is not null but empty? 回答1: where datalength(mytextfield)=0 回答2: ISNULL( case textcolum1 WHEN '' THEN NULL ELSE textcolum1 END

Make Java infer @NotNull for Optional Return Types

徘徊边缘 提交于 2019-12-13 17:02:48
问题 Using Optional s in Java does not protect from NPEs since values still can be null : Optional<String> myMethod() { return null; } A way to protect from this at least at runtime is the use of @NotNull annotations. (Not possible at compile time in Java since it does not have non-null references, as opposed to more sophisticated languages like Swift and Kotlin). Using @NotNull will immediately crash when null is detected, thus preventing null traversing through the program, and making it easier

Select all columns except null or NVL all null

 ̄綄美尐妖づ 提交于 2019-12-11 09:44:42
问题 Is any way to select all columns in a record where fields are not null or NVL the null fields to ''? Im working on ORACLE Something like this SELECT * IS NOT NULL FROM table WHERE id_table ='001' or like this SELECT NVL(*,'') FROM table WHERE id_table ='001' 回答1: Just reverse the NULL logic in the demonstration about Find all columns having at least a NULL value from all tables in the schema. For example, FIND_NULL_COL is a simple user defined function (UDF) which will return 1 for the column

Retrofit API call: How to make sure that value is not null after making api call?

耗尽温柔 提交于 2019-12-11 08:27:00
问题 I have below AuthenticationResponse model that I use for 3 api calls using retrofit2. If I make the verifyEmail call f.e. the JSON response body only contains an attribute for valid email (so something like {"validEmail": true} ). The other 2 calls only contain attributes for "resetSuccesful" or the other 4. How can I make sure/check that when I receive the response to the verifyEmail call f.e. that it contains a non null value for validEmail?? Service: interface AuthenticationService { @POST

java/beans validation - collection/map does not contain nulls

若如初见. 提交于 2019-12-10 11:32:34
问题 There is the @NotNull annotation which validates that a certain object is not null. There is the @NotEmpty annotation which validates that a certain collection/map/string/... is not empty. Is there also an annotation which valides that a certain collection/map does not contain any nulls? I am unable to find it. It seems so basic, that I believe it must be in the JSR-303 spec. 回答1: There is no such built-in constraints. You can easily write your custom constraints, eg @NoNullElements, which

@Nullable and SonarQube 'Conditionally executed blocks should be reachable' warning

99封情书 提交于 2019-12-10 02:48:41
问题 Package has following package-info.java: @ParametersAreNonnullByDefault package foo; import javax.annotation.ParametersAreNonnullByDefault; Class has the following method: private static String toIsoString(@Nullable Instant dateTime) { return dateTime == null ? null : dateTime.toString(); } On which SonarQube (Version 6.2, SonarJava 4.14.0.11784) gives the following warning (squid:S2583): How can I convince SonarQube that the code is actually correct? Interestingly, SonarLint plugin (3.0.0

Insert default value when null is inserted

梦想的初衷 提交于 2019-12-09 08:56:11
问题 I have an Oracle database, and a table with several not null columns, all with default values. I would like to use one insert statement for any data I want to insert, and don't bother to check if the values inserted are nulls or not. Is there any way to fall back to default column value when null is inserted? I have this code: <?php if (!empty($values['not_null_column_with_default_value'])) { $insert = " INSERT INTO schema.my_table ( pk_column, other_column, not_null_column_with_default_value

Sql Conditional Not Null Constraint

冷暖自知 提交于 2019-12-09 04:18:13
问题 I am curious to know is it possible to create a conditional not null constraint in sql? In otherwords is it possible to create a constraint such that a column B can be null as long column A contains lets say 'NEW' but if the contents of column A changes to something else then column B is no longer allowed to be null? And to extend on that, it is then possible to make it so that column B must be null or empty as long as column A says 'NEW'? Thanks All :D 回答1: This is perfectly fine for

Select all if parameter is null in stored procedure

試著忘記壹切 提交于 2019-12-08 16:04:50
问题 I want to create a procedure in SQL Server that will select and join two tables. The parameters @company, @from and @to are always set but @serie_type can be NULL. If @serie_type is not NULL i just want to include the specified types, simple AND S.Type = @serie_type , but if @serie_type is NULL i want to include all types, simple, just dont include the AND statement. My problem is that i dont know if @serie_type will be set therefore i would like o have something like this: /* pseudocode */ ?