SQL Oracle error - sql

insert into tour_concerts values
('1', to_date('02/08/1974', 'DD/MM/YYYY'), 'Misc Concerts', 'UK'),
insert into tour_concerts values
('2', to_date('01/01/1977', 'DD/MM/YYYY'), 'The Hoople North America Your', 'USA'),
insert into tour_concerts values
('3', to_date('05/09/1971', 'DD/MM/YYYY'), 'Sheer Heart Attack UK tour', 'UK'),
insert into tour_concerts values
('4', to_date('09/02/1972', 'DD/MM/YYYY'), 'Works Japan tour', 'Japan'),
insert into tour_concerts values
('5', to_date('03/10/1975', 'DD/MM/YYYY'), 'Magic Tour', 'UK'),
insert into tour_concerts values
('6', to_date('02/01/1974', 'DD/MM/YYYY'), 'Freddie Mercury Tribute Concert for AIDS Awareness', 'UK');
SQL> #tour_concerts1;
('6', to_date('02/01/1974', 'DD/MM/YYYY'), 'Freddie Mercury Tribu
te Concert for AIDS Awareness', 'UK')
*
ERROR at line 2:
ORA-12899: value too large for column "S3327043"."TOUR_CONCERTS".
"TYPE" (actual: 50, maximum: 30)
Can someone help me fix this error?
OKAY I'VE FIXED IT

This error is clearly stating that you're trying to insert a too long varchar value in the 3rd column of the tour_concerts table.
You can fix this by:
Altering the table's structure to make the column accept more than 30 characters. For instance, 50 is the number of characters of the statement that is failing.
alter table tour_concerts modify column_name varchar2(50)
Use the Oracle substr function:
`insert into tour_concerts values ('6', to_date('02/01/1974', 'DD/MM/YYYY'), substr('Freddie Mercury Tribute Concert for AIDS Awareness', 0, 30), 'UK');
If these records are inserted thorugh an application via jdbc for instance, trim user input to not exceed your table's maximum sizes.

Error is clear: TOUR_CONCERTS.TYPE field allows 30 chars, no more, and you're trying to insert a longer string.
You have two ways to solve this:
Shorten string you're inserting (Freddie Mercury Tribute Concert for AIDS Awareness is longer than 30 chars)
Change your table definition and set TOUR_CONCERTS.TYPE field length to an higher value (say 200?)

Huh.I think you should alter your table.30 is too short.
If your DB is oracle:
alter table YOURTABLE alter column 'S3327043' varchar(100)

Check this article it seems your trying to insert longer value than the field, make the fields bigger than the maximal value you could need.

Related

MariaDb Begin End in a multi-value Insert

Im using MariaDb and Im trying to execute a multi-value insert query using Begin End and I get the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'END' at line 1 0.000 sec
BEGIN;
INSERT INTO Client (Id, Name, Total)
VALUES
(1, 'John', 1000),
(2, 'Mary', 3000),
(3, 'Mike', 14000),
(4, 'George', 15000);
END;
Can I use Begin, End with a multi-value insert and if yes what is the correct syntax here?
I have millions of data to insert. the above is just a small sample of my dataset

I'm wondering why after running the SQL query I get this error 1241 - what's wrong here?

CREATE TABLE MOROCCO
(
NUM_PER_MANAGE INT ,
MOYEN_RENT DECIMAL (5,2),
GENDER enum ('m','f'),
race varchar (205)
);
INSERT INTO morocco (NUM_PER_MANAGE, MOYEN_RENT, GENDER, race)
VALUES (3, (300, 45), 'm', 'black');
you must specify decimal value as 300.45 not (300, 45):
INSERT INTO MOROCCO (NUM_PER_MANAGE, MOYEN_RENT, GENDER, race)
VALUES (3, 300.45, 'm', 'black');
and if you are using mysql in linux then you should use the table name in correct case(table name is case sensitive in linux).

Postgres insert into a table

I have a SQL script like this which I run from the command line using psql:
insert into "A"."B" values
(1, 'name=a', 'a#example.com', 'K')
How do I convert it into INSERT command inside a database?
INSERT INTO "A"."B" (first_column, second_c, third_c, fourth_1)
VALUES ('2', 'name=a', 'a#example.com.com', 'K');
Also what does "A"."B" do? I read somewhere that double quotes are needed when table name has Capitals. I seem to get an error with that when I run commands inside the database.
You said that your database name was DB and your table name was B.
You can simply use the table name alone:
INSERT INTO "B" (first_column, second_c, third_c, fourth_1)
VALUES ('2', 'name=a', 'a#example.com.com', 'K');
If you want to include the database name, then use:
INSERT INTO "DB"."B" (first_column, second_c, third_c, fourth_1)
VALUES ('2', 'name=a', 'a#example.com.com', 'K');
The double quotes are only required when the name of any entity (e.g. table, column, etc...) is a reserved word.
You can use this query where A is schema and B is table name.
INSERT INTO "A"."B" (first_column, second_c, third_c, fourth_1)
VALUES ('2', 'name=a', 'a#example.com.com', 'K');

What's wrong with this SQL INSERT statement?

I want to insert a certain value into a certain field of five different rows altogether. But whenever I run this query it doesn't get executed. What's wrong with it, and how can I fix it?
INSERT INTO `employee`(`password`) VALUES ('abc') WHERE `id` IN (1,2,3,4,5);
An INSERT can't have a WHERE clause. It looks like you meant to do an update:
UPDATE `employee`
SET `password` = 'abc'
WHERE `id` IN (1,2,3,4,5);
Or perhaps a multi-row insert:
INSERT INTO `employee` (`id`, `password`)
VALUES (1, 'abc'), (2, 'abc'), (3, 'abc'), (4, 'abc'), (5, 'abc');
Also, FYI, you really shouldn't be storing passwords as plain text, which it looks like you may be doing.

Why this insert query go into error?

I am very new to Microsoft SQL Server and I have a problem with this INSERT query that inserts a new record in a very very big table (it has many columns).
I have this query:
INSERT INTO VulnerabilityAlertDocument ([Id],
[VulnerabilityAlertId],
[SourceId],
[BugTraqID],
[Title],
[StatusID],
[CVE],
[Published],
[LastUpdated],
[Remote],
[Local],
[Credibility],
[Classification],
[Availability],
[Ease],
[Authentication],
[CVSS2_BaseScore],
[CVSS2_TemporalScore],
[CVSS2_BaseVector],
[CVSS2_TemporalVector],
[CVSS1_BaseScore],
[CVSS1_TemporalScore],
[NVD_CVSS2_BaseScore],
[NVD_CVSS2_ComponentString],
[ImpactRating],
[Severity],
[EaseofExploit],
[UrgencyRating],
[LastChange],
[ShortSummary],
[Impact],
[TechnicalDescription],
[AttackScenario],
[Exploit],
[Credit],
[URL],
[AlertStatusId],
[Type],
[DetailLevel],
[Language],
[dd])
VALUES('10000',
'10000',
'TEST',
'5',
'TEST TITLE',
'1',
'TEST CVE',
'1998-04-30 00:00:00.000',
'2007-11-05 16:32:34.000',
'TEST REMOTE',
'TEST LOCAL',
'TEST CREDIBILITY',
'TEST CLASSIFICATION',
'TEST Availability',
'TEST EASE',
'TEST Authentication',
'TEST CVSS2_BaseScore',
'TEST VSS2_TemporalScore',
'TEST CVSS2_BaseVector',
'TEST VSS2_TemporalVector',
'TEST CVSS1_BaseScore',
'TEST CVSS1_TemporalScore',
'TEST NVD_CVSS2_BaseScore',
'TEST NVD_CVSS2_ComponentString',
'2',
'3',
'10',
'7',
'TEST LastChange',
'TEST ShortSummary',
'TEST IMPACT',
'TEST TechnicalDescription',
'TEST AttackScenario',
'TEST Exploit',
'TEST Credit',
'TEST URL',
'5',
'3',
'1',
'TEST Language',
'NULL');
In which I insert a specific value into a specified column (I specify columns by the first query section, and I specify the related values by the second section of the query)
The problem is that when I try to execute the previous query I obtain the following error
Msg 544, Level 16, State 1, Line 1
Cannot insert explicit value for identity column in table 'VulnerabilityAlertDocument' when
IDENTITY_INSERT is set to OFF.
Why? What does this mean? How can I change my query to solve this problem and so insert the record in my table?
Try SET IDENTITY_INSERT VulnerabilityAlertDocument ON before INSERT
After INSERT, add SET IDENTITY_INSERT VulnerabilityAlertDocument OFF
you have an identity column then you don't have to insert the Id, you have to delete Id from your query and the value of the Id
Remove the [Id] column from the list of columns and its corresponding value '10000'. The error is due you are trying to populate a column with a value and SQL is complaining that a automated handled value just he can provide.
BTW, you don't need to quote your numeric values if that columns are of numeric type.
Use SET IDENTITY_INSERT ON before your query.
Identity columns are auto-increasing and so do not allow insertion.
You need to explicitly state that you want to insert data into the column so that SQL server allows it.
Make sure you do not insert duplicate values for this column.
The best practice is to avoid inserting values into IDENTITY column.
Remove "[ID]"
write it like that:
INSERT INTO your table name
For example:
If you have Instructor table with attributes ID, name and dept_name
Use: Insert Command like bellow
Insert Into Instructor (ID, name, dept_name) Values (11111, 'Andrea', 'Biology');
Try this and let me show you result !!