Since a couple of days I can't execute CREATE and TRUNCATE SQL statement using Oracle 12 and Toad 12, ONLY if I terminate my statements with a semicolumn. I've always used the same connections, user and tables, but now I receive these errors while querying:
CREATE TABLE W_TEST_01
AS SELECT *
FROM CFG_FLOW
WHERE 1 = 2;
ORA-00933: SQL command not properly ended
CREATE TABLE W_TEST_01 (PIPPO NUMBER);
ORA-00922: missing or invalid option
TRUNCATE TABLE W_TEST_01;
ORA-03291: Invalid truncate option - missing STORAGE keyword
Can someone please help me?
Try with parentheses, like this:
CREATE TABLE W_TEST_01
AS (SELECT * FROM CFG_FLOW WHERE 1 = 2);
And if it still does not work, try to see the CTAS Tips
I advise you to take a look at the following link
Hope this can help!
Related
I'm trying to alter a table in Azure Databricks using the following SQL code.I would like to add a column to the existing table 'logdata' and being unsuccessful.
ALTER TABLE logdata
ADD sli VARCHAR(255)
Error message:
Error in SQL statement: ParseException: no viable alternative at input 'ALTER LOGDATA'(line 1, pos 6)
I tried searching online, but couldn't find what's causing this. Could anyone please help this beginner please?
For Azure syntax be like : ALTER TABLE table_name ADD COLUMNS (col_name data_type)
So your query must be like :
ALTER TABLE logdata
ADD COLUMNS (sli VARCHAR(255))
Unsure what syntax the error is referring to at this statement :-
Use MyDatabase
CREATE TABLE TestTable
AS (SELECT * FROM dbo.MyTable);
Any help is appreciated!
The dbo suggests that you are using SQL Server. The syntax error is that this syntax is not supported.
The equivalent syntax in SQL Server is:
SELECT *
INTO TestTable
FROM dbo.MyTable;
You need to use like below. The one you are using is Oracle syntax.
Use MyDatabase
Go
SELECT * INTO TestTable FROM dbo.MyTable
GO
SELECT tab1.column1 FROM DB2.Schema.table1 tab1;
I try to execute this above query from Database 1. The table1 exist in DB2 database. It showing following error.
ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
No need to mention database name in your select statment. See below:
SELECT tab1.column1 FROM Schema.table1 tab1;
DB Link Usage:
CREATE DATABASE LINK sales.hq.acme.com
CONNECT TO scott IDENTIFIED BY tiger
USING 'sales';
Once this database link is created, you can query tables in the schema SCOTT on the remote database in this manner:
SELECT *
FROM emp#sales.hq.acme.com;
You can also use DML statements to modify data on the remote database:
INSERT INTO accounts#sales.hq.acme.com(acc_no, acc_name, balance)
VALUES (5001, 'BOWER', 2000);
UPDATE accounts#sales.hq.acme.com
SET balance = balance + 500;
DELETE FROM accounts#sales.hq.acme.com
WHERE acc_name = 'BOWER';
You can also access tables owned by other users on the same database. This statement assumes SCOTT has access to ADAM's DEPT table:
SELECT *
FROM adams.dept#sales.hq.acme.com;
The previous statement connects to the user SCOTT on the remote database and then queries ADAM's DEPT table.
Note: Dblinks are used using '#' symbol.
You don't need to prefix the db. Just make sure you are in the right schema using:
ALTER SESSION SET current_schema = schemaname;
Does anyone know if this is possible?
Example:
CREATE TABLE XPTO (
this_is_an_error_because_there_is_no_data_type
);
Query Result:
"**Error starting at line X in command:
blablabla
SQL ERROR: ORA-02263**"
Is it possible to save the query result in a table?
I'm making an "installation" script with CREATE tables/procedures, GRANT's simple stuff, but I want to know if it's possible to save in a table the errors that may popup during the installation of my tables or whatever it is in there (in my install file .sql).
Any help, ideas, work around/s, would be appreciated. Thanks guys!
In SQL*Plus this can be done with SQL*Plus error logging.
Enable error logging:
SQL> set errorlogging on
Run the script:
SQL> CREATE TABLE XPTO (
2 this_is_an_error_because_there_is_no_data_type
3 );
this_is_an_error_because_there_is_no_data_type
*
ERROR at line 2:
ORA-00972: identifier is too long
At the end, all errors are stored in the table SPERRORLOG.
SQL> select * from sperrorlog;
USERNAME
------------------------------------------------
TIMESTAMP
------------------------------------------------
SCRIPT
------------------------------------------------
IDENTIFIER
------------------------------------------------
MESSAGE
------------------------------------------------
STATEMENT
------------------------------------------------
JHELLER
25-JAN-16 01.43.13.000000 PM
ORA-00972: identifier is too long
CREATE TABLE XPTO (
this_is_an_error_because_there_is_no_data_type
)
As Tony Andrews said in the comment, SPOOL is the most common method for doing this. But that's because very few SQL*Plus scripts are fully automated. If you are aiming for true automation you'll need something like SQL*Plus error logging or whenever sqlerror exit failure to detect errors.
How can rows be inserted into a table from a table in a remote database?
We currently have a stored procedure which does this using a database link. However, we are having to delete the link because our company policy doesn't allow their usage.
begin
...
execute immediate 'insert into '|| table_name
|| ' (select * from schema_name.'|| table_name ||'#link)';
...
end;
I'm unable to use the COPY command as it appears to be not recognized.
COPY FROM username/pwd#SID
insert into table_name using (select *
from table_name);
Error report:
SQL Error: ORA-00926: missing VALUES keyword
00926. 00000 - "missing VALUES keyword"
*Cause:
*Action:
According to this SQL Plus page, COPY command is now obsolete.
Your Query syntax is slightly wrong, and you just need to specify INSERT/REPLACE/CREATE .. and INTO is NOT needed.
COPY is not obsolete, but it ends up with some encoding issues.
You would use the line continuation character to get around that.
COPY
FROM username/pwd#SID
TO username/pass#SID2
insert
table_name
using
select * from schema_name.table_name;
You can also, download the table data into a text file, and use SQL*Loader to load the data into the another Database.
I prefer the SQL*Loader option! Since maintenance is easy!
For download,
- you can either use SPOOL with delimiter option as mentioned Here
- Write a ProC/PLSQL to output the data into a File (Method 4 in ProC, OR select column names from dba_columns))