Error in the sql command line - sql

Every time I insert new data to my table using the command line, it is inserted successfully (and I check my insertion by typing select * from table_name;) but when I close the command line and open it again and write the sql statement which (select * from table_name;) it says that there are no rows selected. I mean the inserted row is not saved in the database.
Please can someone help me to know the problem?

Use COMMIT; to apply your SQL statements

Related

pyodbc - insert into 'select' not working

I am trying to run INSERT INTO SELECT statement in cur.execute. The code executes without any error, but there are no records inserted in the table.
Here is the table data:
I execute the following query,
cursor = conn.cursor()
query = 'INSERT INTO destination_test_hist SELECT * FROM destination_test'
cursor.execute(query)
conn.commit()
Where am I going wrong? I need some assistance
Syntax-wise, I don't see any errors.
Just a few simple things to check to be sure:
Check that your connection is correct and you are checking that server/db, your source table(in this case destination_test) and target table (in this case destination_test_hist) are correct.
Check your database environment and relevant tables in the same. You might have checked the QA test environment maybe or post the query with output of no records with database name and tables.
Also, at programming level it may appear that it might not have got executed in the database do debug the query output what it returns at programming level too.

I create some tables in SqlDeveloper but I can not see the data stored in the tables. Why I can't see the data in my tables?

I created a sql script to create and populate tables. The script was run in SqlDeveloper.
When I run the query
Select * from table_name
in Sql Developer it does work and returns the data from the table.
But when I open the Command Prompt and I login and execute the same query I receive the message "no rows selected". I also tried to run
SELECT table_name FROM user_tables;
in command line and it does work, all the tables names are returned.
Sounds like you did not commit the transaction. Issue a
COMMIT;
after your INSERT statements.

Sql server trigger : Invalid 'inserted' object name

I have a table that I want to test on it a trigger I try to SELECTED the line of
the query to see what the table contains but an error appear and In all MY sql project inserted and deleted table doesn't work for me this is what I wrote
the is the error that appear (On the Image)
CREATE TRIGGER TR
on Ligne
for insert
as
begin
select * from inserted
end
please is there any solution for this problem and thanks
I find that when i hover on inserted it show me this
Have you made sure intellisense is enabled in SSMS ?
Go to Tools >> Options >> Text Editor >> Transact-SQL >> IntelliSense
Then - if it is enabled - sometimes it helps to refresh the local cache:
Have you tried placing an i at the back of the keyword, inserted?
CREATE TRIGGER TR
on Ligne
for insert
as
begin
select * from inserted i
end

Delete statement after executing a SQL insert twice

From an Oracle database, I have executed an insert SQL statement twice in a production environment.
Sadly, the rollback option did not seem to work.
The insert statement was:
INSERT INTO MAE_INT.T_INT_APPLICATION (INAP_IDENT, INAP_PARAM, INAP_VALEUR, INAP_DATE)
VALUES ((SELECT MAX(INAP_IDENT)+1 FROM MAE_INT.T_INT_APPLICATION), 'monitoring', 'true', '10/06/2016');
COMMIT;
I guess the only option now is to make a delete statement for the double.
Anyone can help with that? Not sure how to write it
You can delete max(INAP_IDENT) like below, thereby leaving you with first insert statement only.
NOTE: TEST IT IN DEV/UAT ENVIRONMENT FIRST
delete from MAE_INT.T_INT_APPLICATION
where INAP_IDENT=
(SELECT MAX(INAP_IDENT) FROM MAE_INT.T_INT_APPLICATION);
Before committing, check if you dont have duplicate entry.

Is it possible to go back to line after error in PL/SQL?

I have tons of insert statements.
I want to ignore errors during the execution of these lines, and I prefer not to wrap each line seperately.
Example:
try
insert 1
insert 2
insert 3
exception
...
I want that if an exception was thrown in insert 1, it will ignore it and go back to perform insert 2, and etc.
How can I do it?
I'm looking for something like "Resume next" in VB.
If you can move all the inserts to a sql script and then run them in sql*plus, then every insert will run by its own and the script will continue to run.
If you are using plsqldeveloper (you taged it), then open a new command window (wich is exactly like a sql script run by sql*plus) and put your staements like this:
insert into table your_table values(1,'aa');
insert into table your_table values(2/0,'bb');
insert into table your_table values(3,'cc');
commit;
Even though statement (2) will throw an execption, since it's not in a block it will continue to the next command.
UPDATE: According to #CheranShunmugavel comment, add
WHENEVER SQLERROR CONTINUE NONE
at the top of the script (especially if your using sql*plus which there the difault is exit).
You'd need to wrap each INSERT statement with its own exception handler. If you have "tons" of insert statements where any of the statements can fail, however, I would tend to suspect that you're approaching the problem incorrectly. Where are these statements coming from? Could you pull the data directly from that source system? Could you execute the statements in a loop rather than listing each one? Could you load the data first into a set of staging tables that will ensure that all the INSERT statements succeed (i.e. no constraints, all columns defined as VARCHAR2(4000), etc.) and then write a single SQL statement that moves the data into the actual destination table with appropriate validations and exception handling?
Use the log error clause. More information in Avoiding Bulk INSERT Failures with DML Error Logging