I am aware of only truncate command in sqlplus,
connect myuser/mypassword#myserver
truncate table mytable;
EXIT;
/
Wondering if there is a delete command, I read about DEL but not sure how to use it appropriately, please advice if there is something to use like the below in sqlplus if any,
delete from mytable where emp_id in (1,5);
Answer to your question is yes.
In fact, what you have written is a perfectly valid delete command.
See http://www.techonthenet.com/oracle/delete.php for a simple tutorial and guide. Not just Oracle, but all SQL databases support it. It is part of the SQL language itself.
Related
Running following statement in DB2 CLP (Command Window)
db2 "truncate table MYSCHEMA.TABLEA immediate"
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0969N There is no message text corresponding to SQL error "-20356" in the
message file on this workstation. The error was returned from module
"SQLNQBE2" with original tokens "MYSCHEMA.TABLEA".
Can some please tell me what I'm doing wrong or what I'm missing? I'm trying to simply truncate from a single table and I'm getting the following error message. Not sure what I'm doing wrong. I've tried it with/without quotes, with/without schema, with/without immediate. I've also tried in Command Editor (remove db2 and quotes) and still not working. I'm using:
DB2/AIX64 9.7.9
Also, I have delete privilege as I am able to delete records but I want to truncate.
Thanks in advance!
The version of the DB2 client you're using doesn't seem to match that of the server, this is why you cannot see the actual error message for SQLCODE -20356. If you could, you'd see this:
The table MYSCHEMA.TABLEA cannot be truncated because DELETE triggers
exist for the table, or the table is the parent in a referential
constraint.
Further explanation and suggested actions can be found, as usual, in the fine manual.
ALTER TABLE MYSCHEMA.TABLEA ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE
or
import from /dev/null of del replace into MYSCHEMA.TABLEA
I had this problem recently too. In my case I had to do a COMMIT WORK right before TRUNCATE. This solved my problem. Please try and tell us if this helped.
Whenever I issue 'alter session force parallel DML;' from Pro*C I get an error. Although, it works fine from sqlplus for the same user. Is there any reason for that?
This isn't directly related to Pro*C. The error ORA-12841: Cannot alter the session parallel DML state within a transaction happened in Pro*C because it had already performed DML, whereas a new SQL*Plus session did not. Moving the COMMIT or the ALTER statement should resolve the issue.
Thanks to Hemant K Chitale and €$ħ₪ on the Oracle Forum: https://community.oracle.com/message/10002348
Are you sure that the trailing semicolon ';' is part of the SQL statement?
Usually it only tells sqlplus that the SQL statement end here, but the semicolon is not part of the SQL syntax (except for PL/SQL)
So, given an SQL file to be executed in Oracle, we are asked to determine how many blocks are to be executed within the SQL file. For example, there is one block in an SQL file containing the following command,
CREATE TABLE customer (id varchar2(42));
two blocks in the following SQL file,
ALTER TABLE customer ADD name varchar2(42);
ALTER TABLE customer DROP COLUMN id;
and three blocks in the following SQL file
CREATE OR REPLACE PROCEDURE printHelloWorld IS
BEGIN
dbms_output.put_line('Hello World!');
END;
/
INSERT INTO customer VALUES ('ivan');
DROP TABLE customer;
We can't assume anything else about the input, other than the fact it will be executed without any error in Oracle SQLDeveloper.
UPDATE
The purpose of asking the question is to ensure that there would only be one statement, which is to be executed, in the SQL file. I am also open to the answer of this question. It would be even better to be able to create a script to split a multiple-statement SQL file to multiple files.
Not a perfect solution but will work in most cases I think.
First create a duff user with no rights except to create a session.
CREATE USER duff IDENTIFIED BY "password";
GRANT CREATE SESSION TO duff;
Then use this with sqlplus and grep to count the ORA- errors - should be one per statement.
sqlplus duff/password#db < script.sql | grep -c ORA-
If you have ALTER SESSION statements then you need a bit more
sqlplus duff/password#db < script.sql | grep -Ec 'ORA-|Session altered.'
There maybe other exceptions, but I think it gives you a workable solution for little overhead. Be careful that scripts don't switch user - but if you have hard-coded usernames and passwords in your scripts you have other issues.
What's the proper syntax for writing stored procedures in sqlplus? The internet is surprisingly unhelpful on this point since SQL tutorials don't seem to specify their environment, or the example they give is a little confusing. I think the simplest way to figure this is that I'll post two commands (out of several I need to make), and if someone can write what they'd look like as stored procedures, I'm sure I can figure the rest out on my own.
Command 1:
code:
SELECT COUNT(username)
FROM "ValidClients"
WHERE username = [username goes here];
Command 2:
code:
INSERT into "ValidClients"
/*zero is overridden by a sequence trigger*/
VALUES (0, [username], [password]);
As you can see, it's really basic stuff, I'm just used to Microsoft SQL Server and so SQLPlus syntax is tripping me up a little. Thanks in advance.
Here's an example from Google:
CREATE PROCEDURE addtuple1(i IN NUMBER) AS
BEGIN
INSERT INTO T2 VALUES(i, 'xxx');
END addtuple1;
The entire tuturial looks kindof nice.
is there any way to execute multiple statements (none of which will have to return anything) on Firebird? Like importing a SQL file and executing it.
I've been looking for a while and couldn't find anything for this.
Execute block is exactly for that purpose. Works in IBExpert too, a simple example :
execute block as
begin
Update stuff;
Delete stuff;
Update stuff;
end
Comprehensive guide, with temporary variables and cycles into it:
EXECUTE BLOCK
You can do it from IBExpert with Script Executive (Menú Tools -> Script Executive). Be sure to connect to the DB you want to run the query's and then at the Script Executive dialog check the "Use current connection" for this to work.
In IBExpert you can execute multiple commands in single script via Tools->Script Executive (Ctrl+F12)
Shouldn't the normal query-delimiter work? Like:
Update stuff; Delete stuff; Update stuff;
You can do this with IBOConsole (download from www.mengoni.it). The SQL window allows you to enter a complete script with the usual ";" delimiter.