hello I'm new to SQL I'm attempting to create a database and am having an issue running this code in cmd sqlplus
execute 'CREATE BIGFILE TABLESPACE "COMPANY_DATA" DATAFILE 'c:\software\COMPANY_data_tablespace' SIZE 1G AUTOEXTEND ON NEXT 1024M MAXSIZE UNLIMITED LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;'
I am receiving this error
Error at line 1:
ORA-06550: line 1, column7:
PLS-00103: encountered the symbol execute 'CREATE BIGFILE TABLESPACE "MG_DATA" DATAFILE when expecting the following:
(begin case declare exit for goto if loop mod null pargma
raise return select update while with <an identifier>
<adouble-quoted delimited-identifier><a bind variable><<
continue close current delete fetch lock insert open rollback
savepoint set SQL execute commit forall merge pipe purge
I'm not sure what I missing in the syntax I know this is a noobie question but kinda stumped thanks
Your syntax error is caused by the fact that you enclose the entire CREATE statement in single quotes, but the statement itself has embedded single quotes. So the parser sees the first quote, and terminates that string when it sees the next. And that occurs when you hit the file name. You'd need to escape the embedded quotes.
Or much better, as #GMB said, just submit the CREATE statement directly. Why did you think you needed quote it and submit it with EXECUTE in the first place?
Related
I am trying to insert entries into a table:
CREATE TABLE MYTABLE (ID INT);
BEGIN
DECLARE CNT INT DEFAULT 0;
WHILE CNT<100 DO
INSERT INTO MYTABLE(ID) VALUES(CNT);
SET CNT = CNT + 1;
END WHILE;
END
What's wrong with the loop? It won't run. The error it shows is:
Error : an unexpected token "End of starement" was found following "re cnt int default 0". Expected tokens may include "psm_semicolon>" sqlcode=-104 sqlstate=42601, driver=3.67.27
Error occured in:
BEGIN
DECLARE CNT INT DEFAULT 0
This is a frequently asked question, you could have found it with search.
You need to tell whatever tool you use to submit the SQL statement that there is an alternative statement terminator (also known as statement separator), and then use that alternative statement terminator at the end of the SQL block , and any standalone non-compound statements.
Many people use # to indicate the end of the block, different tools often suggest different characters.
For squirrel sql, some versions have a "Statement Separator" property on the SQL tab of 'New Session Properties' which you can set to #, and this is effective the next time you open the session. Your code would then have # at the end of the create table statement, plus # once after the end of the block (in the case that you have two statements, one of which is a compound block). If you have more than two statements each compound-block needs its own # terminator at end of block, and each standalone statement (non compound) needs its own #.
The background is that when you have a compound (multi-statement) SQL block in Db2, the semi-colon is the terminator for statements inside the block, but you need a different terminator to indicate the end of the whole block. Without that terminator, you will get an SQL exception.
Different tools have different ways to specify the alternative statement terminator.
Your question does not mention the tool you use to submit the SQL, or your Db2-server platform, which can be relevant sometimes.
If you submit the SQL using the Db2 command-line-processor (at the shell command line on Windows, Linux/Unix), then you can specify the alternative statement terminator either on the db2 command line ( -td#) , or on the fly inside the file (as long as that file is submitted by the db2 CLP) that contains the SQL statements by having a line that reads --#SET TERMINATOR # . You can use this as often as you like inside a file sent to the CLP, each with a different terminator if necessary and if impacts only the subsequent statements after that line until the next terminator is specified. This method is not usually applicable to java based tools such as squirrel sql, so use the statement separator property for that.
I am creating a stored procedure for db2. But it is giving an error saying that
"SQL Error [42601]: An unexpected token "END-OF-STATEMENT" was found
following "SS_TOKEN_BAK". Expected tokens may include: " END IF"..
SQLCODE=-104, SQLSTATE=42601, DRIVER=4.23.42".
Following is my stored procedure.
CREATE OR REPLACE PROCEDURE TOKEN_CLEANUP_SP
BEGIN
DECLARE batchSize INTEGER;
-- ------------------------------------------
-- CONFIGURABLE ATTRIBUTES
-- ------------------------------------------
SET batchSize = 10000; -- SET BATCH SIZE FOR AVOID TABLE LOCKS [DEFAULT : 10000]
-- ------------------------------------------------------
-- BACKUP IDN_OAUTH2_ACCESS_TOKEN TABLE
-- ------------------------------------------------------
IF EXISTS (SELECT TABLE_NAME FROM TABLES WHERE TABLE_NAME = 'IDN_OAUTH2_ACCESS_TOKEN_BAK')
THEN
DROP TABLE IDN_OAUTH2_ACCESS_TOKEN_BAK;
END IF;
END/
Is anyone face this type of issue. Any help on this would be much appreciated.
Verify that you have the end-of-statement delimiter configured correctly for whatever tool submits the 'CREATE OR REPLACE' procedure. Different tools have different ways to configure the block terminator (alternatively known end of statement delimiter). For command line scripts, use --#SET TERMINATOR / at the start of the file, other ways are possible.
Your code sample shows / as the block terminator, so you might want to use that character as the block delimiter. The semi-colon terminates statements inside the block.
Separately you should see that your code won't compile if the specified table does not exist in the implied schema at compilation time, because you are using static SQL. You may want to use dynamic SQL instead for the drop table statement (search for 'EXECUTE IMMEDIATE' examples).
I am attempting to run a simple compound statement within the Query Editor of DB Solo 4.2.2
It appears I am unable to properly change the end of line delimiter. I am using DB2. Here is a simple example that gives the error:
--#SET TERMINATOR #
BEGIN ATOMIC
DECLARE id INT;
SET id = 10;
END #
--#SET TERMINATOR ;
Error is:
An unexpected token "INT" was found following "N ATOMIC DECLARE id". Expected tokens may include: "END-OF-STATEMENT"
Thanks in advance
DB2 only allows the semicolon to be used as a delimiter in Compound SQL. The syntax you are using appears to only be valid when using the db2batch utility (which comes with DB2 Linux/Unix/Windows).
Here is some relevant information from the Information Center (this is from the z/OS IC):
How to code multiple statements in an SQL procedure
Use a semicolon
character to separate SQL statements within an SQL procedure.
The procedure body has no terminating character. Therefore, if the
procedure contains only one statement, you do not need to put a
semicolon after that statement. If the procedure consists of a set of
nested statements, you do not need to put a semicolon after the
outermost statement.
I have a .sql file that contains below statements:
SET LINESIZE 2000
WHENEVER SQLERROR EXIT 1 ROLLBACK
WHENEVER OSERROR EXIT 1 ROLLBACK
SET PAGESIZE 0
SET HEADING ON
SET FEEDBACK OFF
SET VERIFY OFF
INSERT INTO TABLE_A
--get some value from TABLE B that will be added in Table A....
COMMIT;
EXIT;
When I run this SQL in my SQL Editor (TOAD/SQL Navigator etc.) , it works fine. I see some messages though when SQLNavigator execute this command:
SQL*Plus command ignored.
Processing ...
WHENEVER SQLERROR EXIT 1 ROLLBACK
SQL*Plus command ignored.
Processing ...
WHENEVER OSERROR EXIT 1 ROLLBACK
SQL*Plus command ignored.
Processing ...
SET PAGESIZE 0
When I run this SQL through JDBC, i get an exception:
Caused by: java.sql.SQLException: ORA-00922: missing or invalid option
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:955)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1168)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3368)
I'm assuming this error is because JDBC is not able to understand SQLPlus statements and failing. Is there a way I can tell JDBC to ignore those statements and just run the main SQL? Or to resolve this I just need to modify the SQL file by removing the SQLPlus statements?
You'll need to remove the SQL*Plus commands from the file.
JDBC is intended to be a database-agnostic interface so it is designed to work the same with a variety of different database engines. SQL*Plus commands are designed to work just with SQL*Plus connecting to an Oracle database (though other tools that support Oracle databases will often support a subset of SQL*Plus commands as well). It wouldn't make sense for JDBC to know about what constitutes a SQL*Plus command so it has no way to figure out what is a SQL*Plus command or to filter them out.
Beyond that, simply removing the SQL*Plus commands will change the semantics of the script. The WHENEVER SQLERROR and WHENEVER OSEROR commands instruct SQL*Plus to issue a rollback in the event of an error (which it sounds like your script generates). You'd need to code that logic into your JDBC application if you want to match the behavior.
When you run these statements through TOAD, etc. they usually parse the text either by a delimiter (e.g. semi-column) or by line feed and run the statements separately. However, when you send the whole text to JDBC, it's probably trying to run it all at once, hence the error. You may have to parse the statements and separate them properly before sending to JDBC.
This MySQL script installs multiple triggers.
It works on one machine running MySQL 5.0.51b-community. On another machine running MySQL 14.12 Distrib 5.0.45, for redhat-linux-gnu (i386) it fails, with this error message, which seems to be related to the DELIMITER // ... // DELIMITER; syntax :
ERROR 1064 (42000) at line 272: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER; DROP TRIGGER IF EXISTS trigger_name; DELIMITER' at line 1
The script syntax (summarised) is:
DROP TRIGGER IF EXISTS trigger_name;
DELIMITER //
CREATE TRIGGER trigger_name BEFORE UPDATE ON table
FOR EACH ROW BEGIN
-- Trigger logic goes here
END //
DELIMITER;
-- More trigger drop/create statements follow
What is wrong with the script, and how can I correct it?
Try
DELIMITER ;
not
DELIMITER;
You're actually specifying ; as an argument to the DELIMITER command, so not having the space there may be confusing it.
You need a space between 'DELIMITER' and ';'
DELIMITER ;
# not:
DELIMITER;
Just as an add-on, for someone else:
The delimiter is required to enable the entire definition to be passed to the server as a single statement.
Try the below.
I am sure it should solve the purpose.
DELIMITER +
CREATE TRIGGER STUDENT_INSERT_TRIGGER BEFORE INSERT ON FSL_CONNECTIONS
FOR EACH ROW BEGIN
INSERT INTO STUDENT_AUDIT
SET STUDENT_ID = NEW.STUDENT_ID,
MAC_ADDRESS = NEW.MAC_ADDRESS,
IPADDRESS = NEW.IPADDRESS,
EMAIL_ID = NEW.EMAIL_ID ,
START_TIME=NEW.START_TIME,
END_TIME=NEW.END_TIME,
STATUS=NEW.STATUS;
END; +
From the above when we use a DELIMITER. It should be in the form of
DELIMITER +
--
BLOCK OF SQL WHATEVER YOU WANT TO MENTION
--
+
In the version of MySql I use the same error occurs when using the delimiter command, but this version handles the delimiter ";" for statements and delimiter "|" for stored procedures and functions, which i think solves the problem; try this:
DROP TRIGGER IF EXISTS trigger_name;
CREATE TRIGGER trigger_name BEFORE UPDATE ON table
FOR EACH ROW BEGIN
-- Trigger logic goes here
END |
-- other statements or functions here
Hmm I'm having similar problems. I do a mysqldump from Debian Lenny running 5.0.51 and try importing to OpenSolaris running 5.0 and get the same error. And I have DELIMITER ;
Version conflict?