How to insert empty_clob() from java to Oracle - sql

I am having an NCLOB column in oracle. When I create a row, I need to insert an empty_clob() using normal java insert query.
Does anyone know how this is done? I am looking for something like the one below from java.
INSERT INTO MY_TABLE VALUES(1,'Abraham','empty_clob');
Thanks and Regards,
Abraham Menacherry

You should correct your insert statement:
INSERT INTO MY_TABLE VALUES(1,'Abraham',empty_clob());
You should also take a look here.
The empty_clob function is also useful as default value for the clob column.

Related

SQL Developer: Procedure To Insert In A table New Records from Another One

I'm triying to figure out how to insert records stored in the #TableA (STAGE_REMEDY) that does not exist in the #TableB (HIST_REMEDY). Comparing each other using the Date (FECHA_ENVIO field in my case), just to validate that I'd be inserting just NEW data and agrouping in the right way.
I'm using SQL Developer and I've tried to develop different procedures to reach my objective. My code below shows my tried that in fact does not work (Doesn't insert data in the table i don't know why). Also, I'm using SUBSTR , cause' the field has the date in the format (dd/mm/yyyy hh:mm:ss)
AS
BEGIN
INSERT INTO HIST_REMEDY (HORA_ENVIO, HORA_RESOLUCION,
TIEMPO_SLA_MINUTOS, GRUPO_ASIGNADO,INCIDENCIA,CUENTA,
RESUMEN,COMENTARIOS,ESTADO,
FECHA_ENVIO,FECHA_RESOLUCION,FECHA_ULTIMA_MODIFICACION,
USUARIO_ASIGNADO,REGION,CIUDAD,RESOLN1,RESOLN2,RESOLN3,
CN,NO_ACTIVIDAD,
OS,DEPARTAMENTO,ORGANIZACION,AREA,USUARIOR,NOMBRE,APELLIDO,GRUPO_ASIGNADO_MDA,AREA_ESCALA,
CATEGORIA_SLA,MAL_GENERADO,
USR_SIEBEL,NOMBRE_CLAVE,
AREA_PROVENIENTE,RECURRENTE,
ESCALADO,SEVERIDAD, SERVICIO)
SELECT HORA_ENVIO, HORA_RESOLUCION,
TIEMPO_SLA_MINUTOS, GRUPO_ASIGNADO,INCIDENCIA,CUENTA,
RESUMEN,COMENTARIOS,ESTADO,
FECHA_ENVIO,FECHA_RESOLUCION,FECHA_ULTIMA_MODIFICACION,
USUARIO_ASIGNADO,REGION,CIUDAD,RESOLN1,RESOLN2,RESOLN3,
CN,NO_ACTIVIDAD,
OS,DEPARTAMENTO,ORGANIZACION,AREA,USUARIOR,NOMBRE,APELLIDO,GRUPO_ASIGNADO_MDA,AREA_ESCALA,
CATEGORIA_SLA,MAL_GENERADO,
USR_SIEBEL,NOMBRE_CLAVE,
AREA_PROVENIENTE,RECURRENTE,
ESCALADO,SEVERIDAD, SERVICIO
FROM STAGE_REMEDY
WHERE NOT EXISTS (SELECT * FROM HIST_REMEDY WHERE SUBSTR (HIST_REMEDY.FECHA_ENVIO,0,10) = SUBSTR (STAGE_REMEDY.FECHA_ENVIO,0,10))
GROUP BY HORA_ENVIO, HORA_RESOLUCION,
TIEMPO_SLA_MINUTOS, GRUPO_ASIGNADO,INCIDENCIA,CUENTA,
RESUMEN,COMENTARIOS,ESTADO,
FECHA_ENVIO,FECHA_RESOLUCION,FECHA_ULTIMA_MODIFICACION,
USUARIO_ASIGNADO,REGION,CIUDAD,RESOLN1,RESOLN2,RESOLN3,
CN,NO_ACTIVIDAD,
OS,DEPARTAMENTO,ORGANIZACION,AREA,USUARIOR,NOMBRE,APELLIDO,GRUPO_ASIGNADO_MDA,AREA_ESCALA,
CATEGORIA_SLA,MAL_GENERADO,
USR_SIEBEL,NOMBRE_CLAVE,
AREA_PROVENIENTE,RECURRENTE,
ESCALADO,SEVERIDAD, SERVICIO;
COMMIT;
END;
My expectations is get a database where I can store all the new data gets on the #TableA (STAGE_REMEDY).
Regards!

is it possible to insert data where null value is locating by using insert into keyword

Insert into table_name
values('hyd') where col1 isnull;
INSERT syntax can't have WHERE clause. You can use INSERT INTO command for this type of use case.

How to validate/restrict values in a column as per a specific format in a sql Database

I am working on an application that populates values from sql Database in a format two numeric and alpha character e.g 11G,34H. There is no validation or check for the same.I want to put put checkpoint/validation from Database end.Is it possible to implement via SQL procedure or anything.Can anyone help me with the code.
Try the below query
DECLARE #strtable TABLE (column1 VARCHAR(50))
INSERT INTO #strtable
VALUES ('11H'),('sda'),('175HH'),('1H1'),('282')
INSERT INTO YourTable (Column1)
SELECT Column1
FROM #strtable
WHERE LEN(column1)=3
AND ISNUMERIC(LEFT(column1,2))=1
AND ISNUMERIC(RIGHT(column1,1))!=1
--Output : 11H

Insert empty string into INT column for SQL Server

A SAMPLE table has only one column ID of type int, default null.
In Oracle when I do:
insert into SAMPLE (ID) values ('');
the new record is added with blank value. But in SQL Server 2008, when I run the same insert statement, the new record has the value of 0.
Is there a way to force SQL Server 2008 to default blank string to NULL instead of 0 (for numerical type of columns)?
Assuming that your INSERT statement is part of a stored procedure re-used in many places of your application (or, perhaps, is a batch always constructed by the same part of the client code) and that the inserted value is a number passed as a string argument, you could modify the INSERT like this:
INSERT INTO SAMPLE (ID) VALUES (NULLIF(#argument, ''));
Use NULL instead.
insert into SAMPLE (ID) values (NULL);
How about another idea - define an INSTEAD OF INSERT Trigger.
Despite the fact that you're trying to insert a string, with this the operation is "intercepted", empty string is replaced by NULL, and the insert succeeds.
If you define this trigger on your table, then you can continue to insert empty string as before, with no other changes.
Edit: As Martin Smith points out, this effectively is a comparison to 0 (the equivalent of empty string as an int) meaning you won't be able to store 0 in this table. I leave this answer here in case that's acceptable to your situation - either that or re-do all your queries!
CREATE TRIGGER EmptyStringTrigger
ON [SAMPLE]
INSTEAD OF INSERT
AS
BEGIN
INSERT INTO [SAMPLE](ID)
SELECT CASE
WHEN ID = '' THEN NULL
ELSE ID
END
FROM inserted
END
SQL Fiddle example
You can't insert a 'string' into a int column. Oracle must be just handling that for you.
Just try inserting NULL if that's what you need.
insert into SAMPLE (ID) values (NULL);
One more option
insert into SAMPLE (ID) values (DEFAULT)

Inserting a null value into the database

Good Morning,
Say I have an insert statement:
Insert INTO tblTest (fieldOne,FieldTwo,fieldThree) VALUES ('valueOne','valueTwo','null')
This statement doesn't seem to want to insert a null value into the database... I have also tried to insert the word "nothing".
Has anyone any ideas how to make this work? I am using SQL server 2005.
First of all, instead of 'null', try null (lose the quotes)
Then check that the fieldThree column on TblTest doesn't have any constraint prohibiting the use of null values...
Try
Insert INTO tblTest (fieldOne,FieldTwo,fieldThree) VALUES ('valueOne','valueTwo',NULL)
Check for fieldThree not to be NOT NULL.
If you're trying to INSERT 'NULL' string, then just check if fieldThree is varchar type.
Insert INTO tblTest (fieldOne,FieldTwo) VALUES ('valueOne','valueTwo').