How to insert multiple values in 11g? - sql

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

Related

Access INSERT with nested SELECT

Why does the following SQL statement not work?
INSERT INTO dialog (speaker, dialog_text) VALUES (
(
SELECT FIRST(id)
FROM FIGURE
WHERE char_name="Doe" AND forename="John"
),
"Some text"
);
It produces this error:
Query input must contain at least one table or query.
The single SELECT statement works.
An Access SQL INSERT ... VALUES statement will not let you use a subquery for one of the VALUES
Switching to an INSERT ... SELECT statement, as Piotr suggested will work.
Or you could use an Access Domain Aggregate function, instead of a subquery, in your INSERT ... VALUES statement:
INSERT INTO dialog (speaker, dialog_text)
VALUES (
DMin("id", "FIGURE", "char_name='Doe' AND forename='John'"),
'Some text'
);
Following works:
INSERT INTO dialog (speaker, dialog_text)
SELECT FIRST(id), "Some text"
FROM FIGURE
WHERE char_name="Doe" AND forename="John"

Insert multiple records in oracle [duplicate]

This question already has answers here:
Best way to do multi-row insert in Oracle?
(9 answers)
Closed 8 months ago.
I am using oracle sql developer to insert rows in my database.
While this request is working :
INSERT INTO TABLE ( USERID, USERNAME) VALUES (1,"ok1")
The second one (when I am trying to insert multiple rows)is not working:
INSERT INTO TABLE ( USERID, USERNAME) VALUES (1,"ok1"),(2,"ok2")
I am getting this error :
Erreur SQL : ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
You could use INSERT ALL statement. For example:
INSERT ALL
INTO mytable (column1, column2, column3) VALUES ('val1.1', 'val1.2', 'val1.3')
INTO mytable (column1, column2, column3) VALUES ('val2.1', 'val2.2', 'val2.3')
INTO mytable (column1, column2, column3) VALUES ('val3.1', 'val3.2', 'val3.3')
SELECT * FROM dual;
Oracle does not support multi-row inserts. You need to write one insert per row:
INSERT INTO TABLE ( USERID, USERNAME) VALUES (1,'ok1');
INSERT INTO TABLE ( USERID, USERNAME) VALUES (2,'ok2');
Additionally: string literals need to be enclosed in single quotes in SQL. Double quotes are for identifiers. "ok1" is a column name, 'ok1' is a string constant.
See this recent post for some other ways to enter test data as well:
Insert same data multiple times
If you are not worried about SQL injection then run the following :
BEGIN
INSERT INTO TABLE ( USERID, USERNAME) VALUES (1,'ok1');
INSERT INTO TABLE ( USERID, USERNAME) VALUES (2,'ok2');
END;

Enter records interactively

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);

Insert rows based on insert statement (nested insert)

A common insert statement is this..
INSERT INTO tbl_name (ID) VALUES (1)
What I wanted to achieve is to Insert an ID using another insert statement from another table.. It would look like this
INSERT INTO tbl_name VALUES (INSERT INTO tbl_name2 (ID) VALUES (1))
I have tried it but it's giving me errors..
INSERT INTO tblReport_OPA (ID_Main) VALUES (INSERT INTO tblReport_OPF (ID_Main) VALUES (1))
I'm currently developing under vb.net 2010 and sql express 2005
You probably can use OUTPUT clause, like this:
INSERT INTO tblReport_OPF (ID_Main)
OUTPUT Inserted.Id_Main
INTO tblReport_OPA
SELECT 1 as Id_Main
Note you'll have to use SELECT instead of VALUES
Opyionally a merge can be used.
merge into #a T1
using (select -1 as ID)Q on Q.ID=T1.ID
WHEN NOT matched by target then
insert(id) values(1)
output
inserted.id
INTO #b;

Counting Null records not working

create table scoda(product varchar(25),price int,sale varchar(23))
insert into scoda values('watch',10,6)
insert into scoda values('socks',8,'NULL')
SELECT COUNT(*) AS GK FROM scoda WHERE sale IS NULL
Expected output:1
Actual output:0
help needed to continue i am beginner in sql
USE
insert into scoda values('socks',8,NULL)
(without quotes).
Problem is in insert statement:
insert into scoda values('socks',8,NULL)