Enter records interactively - sql

I am using Oracle 11g
I need to enter data interactively in the following query
What is the input format?
Insert into tab_name values (&project_id, '&project_name', '&client_name');

Insert into tab_name values (:project_id, :project_name, :client_name);

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!

How to insert multiple values in 11g?

How to insert multiple values in a table in oracle 11g using query?
I tried This
Use the following DML known as INSERT ALL statement :
insert all into departmentstrigger values(4,'Hello')
into departmentstrigger values(5,'HEy There')
into departmentstrigger values(6,'sup')
into departmentstrigger values(7,'Hii')
select * from dual;
SQL Fiddle Demo
For a detailed explanation you may look at : Insert All Statement

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

How to insert french number format in oracle SQL table

I am facing the issue to insert the french number in a number field of oracle.I am using SQL Developer IDE. When i insert the number(say 3,4) its says invalid number. Specifically,
I don't want to replace the value 3,4 to 3.4.
I tried with changing the NLS Setting also (using command
Alter session set NLS_NUMERIC_CHARACTERS=',';
If I use this command I am able to insert directly in editor but insert command is not working due to comma, Oracle assume that its another value.
Any help would be appreciated.
You can't and you don't need to.
The number format for SQL literals requires the . for the decimal separator.
In the column itself the decimal separator isn't stored at all. You just need to change the display format of the number. This is ideally done in your application, not on SQL level. But if you require this in the SQL output, use to_char() to format your numbers:
select to_char(your_number_column, '9999D99')
from your_table;
The D in the format mask will be replaced with the decimal separator defined by the current session's NLS settings.
A dot . and , are returned literally:
select to_char(your_number_column, '9999,99')
from your_table;
More details on the to_char() format mask can be found in the manual: https://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements004.htm#BABIGFBA
You application/ide may be performing an implicit conversion of character data into number, which uses the session default nls_numeric_characters.
You can force the insert command to perform an explicit conversion as follows using to_number:
SQL> alter session set nls_language = ENGLISH;
Session altered
SQL> alter session set nls_numeric_characters = ',.';
Session altered
SQL> create table t1 (num_col number);
Table created
SQL> insert into t1 (num_col) values ('3.4');
insert into t1 (num_col) values ('3.4')
ORA-01722: invalid number
SQL> -- this is equivalent to:
SQL> insert into t1 (num_col) values (to_number('12345,678', '999999D999', 'NLS_NUMERIC_CHARACTERS=.,'));
insert into t1 (num_col) values (to_number('12345,678', '999999D999', 'NLS_NUMERIC_CHARACTERS=.,'))
ORA-01722: invalid number
SQL> -- now converting explictly
SQL> insert into t1 (num_col) values (to_number('12.345,678', '999999D999', 'NLS_NUMERIC_CHARACTERS=,.'));
1 row inserted
SQL> insert into t1 (num_col) values (to_number('12345,678', '999999D999', 'NLS_NUMERIC_CHARACTERS=,.'));
1 row inserted
in NLS_NUMERIC_CHARACTERS the first character is the decimal separator and the second one is the thousands grouping marker.
The docs have more info:
https://docs.oracle.com/cd/B28359_01/olap.111/b28126/dml_functions_2117.htm

How to insert empty_clob() from java to Oracle

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.