Can't load an SQL dump into Oracle 11g - sql

I was given an SQL dump from an Oracle 11g database. It contains all of the statements to reproduce the database. Unfortunately, it fails at the very first one
CREATE SEQUENCE "XXX"."YYY"
INCREMENT BY 1
START WITH 129004
MAXVALUE 1000000000000000000000000000
NOMINVALUE
NOCYCLE
CACHE 20
NOORDER
GO
With the error SQL command not properly ended. If I throw out the GO at the end, the error user or role '' does not exist. What am I doing wrong? I tried this both in sqlplus command line client and in Oracle SQL developer.
Needless to say, I'm very new to Oracle, so please be easy on me :D.

Related

ORA-01403: no data found ORA-06512

This question has been asked here before so please forgive me for asking again; the answers did not resolve my issue.
I'm working on a report interface that will run stored procedures from an Oracle database through my .NET application. We have 2 oracle database instances: Dev and Stage. I can connect to both Oracle databases from SQL Developer app and run stored procedures successfully.
The problem exists when I try to run report from the web UI that calls the DEV database. It breaks and returns Oracle errors telling me there are no records, but when I run the same report using the same Dev stored procedure and the database pointing to the STAGE, it returns data with no issues.
BEGIN
-- <logic>Get current role</logic>
SELECT GRANTED_ROLE
INTO L_GRANTED_ROLE
FROM USER_ROLE_PRIVS
WHERE GRANTED_ROLE LIKE 'XYZ_%';
-- <logic>Retrieve the employee id</logic>
L_EMPLOYEE_ID := XYZ.UTILS.GET_EMPLOYEE_ID;
-- <logic>Load course profile</logic>
XYZ.UTILS.LOAD_EMP_TEACHING_PROFILE (P_COURSE_ID, NULL);
So it is very simple. In stage db you must have data returned in following query and in dev, there is no data with following query:
SELECT GRANTED_ROLE
--INTO L_GRANTED_ROLE
FROM USER_ROLE_PRIVS
WHERE GRANTED_ROLE LIKE 'XYZ_%';
Execute above query and you will find the issue by yourself.
You need to change the logic of your proc to handle such cases.
Cheers!!

SQL command not properly ended error : Error: ORA-00933

Here is the query i am trying to execute..
CREATE SEQUENCE "GARY"."TABL_PROD_DWH_SEQ"
MINVALUE 1 MAXVALUE 99999999999999999999999999999999
INCREMENT BY 1 START WITH 21 CACHE 20 NOORDER NOCYCLE NOPARTITION;
Error starting at line : 1 in command -
CREATE SEQUENCE "GARY"."TABL_PROD_DWH_SEQ"
MINVALUE 1 MAXVALUE 99999999999999999999999999999999
INCREMENT BY 1 START WITH 21 CACHE 20 NOORDER NOCYCLE NOPARTITION;
Error report -
SQL Error: ORA-00933: SQL command not properly ended 00933. 00000 - "SQL command not properly ended"
'Cause:
'Action:
What version of Oracle are you using? NOPARTITION doesn't ring a bell. It might only be available on more recent versions.
You can also use NOMAXVALUE. That seems more intuitive than your arbitrary value.
Explanaton
Please see the following question/answer: Oracle 12.2 - Replacement of NOPARTITION feature
Your problem is NOPARTITION.
It is a non-documented unsupported feature after a version of Oracle (I think 12).
Also see: https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:9523071800346490539
Test
http://sqlfiddle.com/#!4/1afa88 (Oracle 11g R2)
The below does work:
CREATE SEQUENCE "TABL_PROD_DWH_SEQ"
MINVALUE 1 MAXVALUE 99999999999999999999999999999999
INCREMENT BY 1 START WITH 21 CACHE 20
NOORDER NOCYCLE
;
You've already been told most of the things. Let me add a few more words.
Your problem looks like the one that happens when people use parameters they don't quite understand. I apologize if I sound impolite, but - that's my impression. Why? Because of the look of that CREATE SEQUENCE statement.
No living person I know has ever manually written it
using double quotes around uppercase owner and sequence name,
nor have they used such a MAXVALUE (heck, it is indefinite anyway),
nor they want to explicitly remind Oracle that default increment is 1,
as well as cache (which is 20 by default)
not to mention other options that are default anyway
Apart from start with, everything else is default anyway so you could have used
SQL> create sequence tabl_prod_dwh_seq start with 21;
Sequence created.
SQL> select tabl_prod_dwh_seq.nextval from dual;
NEXTVAL
----------
21
SQL> select tabl_prod_dwh_seq.nextval from dual;
NEXTVAL
----------
22
SQL>
and get the same result. So ... have a look at documentation related to your database version, try to follow it, don't do what's not allowed (or undocumented), keep it as simple as possible and you'll be good.

SQL Server Add Column then Update Column Error

I'm writing a sql script that modifies multiple tables after importing them. In one table I don't have a 'RCVDDATE' column but I do in another related table. I'm adding the new table with this command:
ALTER TABLE TEST.CASES.ADDRESS
ADD RCVDDATE DATE;
And then I'm running this command to bring in the correct values:
UPDATE TEST.CASES.ADDRESS
SET RCVDDATE = c.RCVDDATE
FROM TEST.CASES.CALLS c
Where TEST.CASES.ADDRESS.CALL_NUMBER = c.CALL_NUMBER;
Individually they work fine. But when I execute them in a script it throws an error:
Msg 207, Level 16, State 1, Line 5
Invalid column name 'RCVDDATE'.
Am I having a problem with Intellisense or is it something else? If you have any suggestions on how I can get the script to run in SQL Server, please advise.
You need a GO statement to separate your batches. From https://learn.microsoft.com/en-us/sql/t-sql/language-elements/sql-server-utilities-statements-go?view=sql-server-2017
SQL Server applications can send multiple Transact-SQL statements to an instance of SQL Server for execution as a batch. The statements in the batch are then compiled into a single execution plan. Programmers executing ad hoc statements in the SQL Server utilities, or building scripts of Transact-SQL statements to run through the SQL Server utilities, use GO to signal the end of a batch.

Pro*C can't force parallel DML while sqlplus can?

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)

Phantom column name in MS SQL Table, what is it?

I am trying to write an MS SQL statement to fetch a row.
SELECT otherfields, phantom_col FROM mytable WHERE id=5
The above SQL fails with error:
Msg 207 Level 16 Stage 1, Line XX
invalid column name 'phantom_col'.
I loaded SQL Management Studio 2008 R2 and connected to the said database and table and did a "select top 1000 rows" to get the auto generated SQL. It shows:
SELECT TOP 1000 [otherfields], [phantom_col] FROM [mydatabase].[dbo].[mytable]
I then deleted the part that reads [mydatabase] and immediately SQL Management Studio tells me [phantom_col] is invalid.
What special kind of column is that phantom_col? Strictly speaking, if I omit the lengthy [].[] notation, is my SQL syntax still correct?
EDIT: I looked finally looked closely enough and realised there is an error message. edited as above.
Your syntax is correct.
The error, because you haven't connect to the myDatabse
you can use this too
USE mydatabase
GO
SELECT TOP 1000 phantom_col
FROM myTable
When a SQL Server login connects to SQL Server, the login is
automatically connected to its default database and acquires the
security context of a database user. If no database user has been
created for the SQL Server login, the login connects as guest. If the
database user does not have CONNECT permission on the database, the
USE statement will fail. If no default database has been assigned to
the login, its default database will be set to master.
the quote is taken from here