Hot answers tagged

87

sqlplus user/pass@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=hostname.network)(Port=1521))(CONNECT_DATA=(SID=remote_SID))) Maybe, and this might be dependant on the command line environment you're using, you need to quote the string, something like sqlplus "user/pass@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=hostname.network)(Port=1521))(CONNECT_DATA=(SID=...


81

did you try sqlplus username/password@host:port/service sqlplus x/y@c:a/b modern versions of sqlplus (version 11 or newer) understand this syntax and you don't need a tnsnames.ora file.


61

It is not enough to force sqlplus not to wrap lines. It is also necessary to tell the viewer that you use to view the spool file not to wrap lines. If your viewer is less then -S the option you have to use according to https://superuser.com/questions/272818/how-to-turn-off-word-wrap-in-less . On Unix/Linux you can use head -1 output.txt to get the first ...


37

You can use easy connect for this: sqlplus usr/pass@hostname.network/remote_service_name To enable easy connect on your machine, you need to add it to the NAMES.DIRECTORY_PATH in sqlnet.ora, e.g.: NAMES.DIRECTORY_PATH=(EZCONNECT) If your listener is on a non-default port use ...@hostname.network:port/.... Actually it seems you have to supply a service ...


19

There is nothing like PostgreSQL's set search_path in Oracle. The closest thing I can think of would be a logon trigger for the user that run's an ALTER SESSION SET CURRENT_SCHEMA ... CREATE OR REPLACE TRIGGER LOGON_TRG AFTER LOGON ON SCHEMA BEGIN EXECUTE IMMEDIATE 'ALTER SESSION SET CURRENT_SCHEMA = foobar'; EXCEPTION when others then ...


18

Create a copy of the tnsnames.ora file in a directory that you can write to, modify the file accordingly, then set the TNS_ADMIN environment variable to the location of that directory. eg: cp $ORACLE_HOME/network/admin/tnsnames.ora /tmp/tnsnames.ora # edit the /tmp/tnsnames.ora file to add your entries # Set the $TNS_ADMIN environment variable so that ...


15

Several ways. You can set the EDITOR environment variable before running SQL*Plus (Assuming Unix), to allow use of an external text editor (vi, by way of example): export EDITOR=vi Then type ed in SQL*Plus to edit the previous query in the vi editor. Of course, you may prefer nano, pico, emacs, vim etc etc. If you don't wish to set an environment ...


12

The most simple is to use tnsnames.ora file to connect to the database. For that edit it and add a new entry: This file normally resides in the $ORACLE HOME\NETWORK\ADMIN directory. myDb = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(Host = c)(Port =a)) ) (CONNECT_DATA = (SERVICE_NAME =b) ) ) and then you could connect to ...


12

After two hours, I figured it out. Oracle's documentation for the error didn't seem terribly descriptive at first: ORA-24454: client host name is not set Cause: The network host name in files like /etc/hosts was not set. Action: Set the host name and try again. Now, the command worked on my machine (Ubuntu laptop), but it didn't work on EC2. I ...


11

This is a known bug (description is not public unfortunately): Bug:4396234 ET10.2OREDEF: NULLABLE COL OF *_TAB_COLUMNS TABLE NOT UPDATED AFTER ONLINE REDEF The NOT NULL constraints are copied as NOVALIDATE, and you have to set them to VALIDATE state manually, e.g: ALTER TABLE t84_redefenition ENABLE VALIDATE CONSTRAINT constraint_name; The primary key ...


9

Metalink bug 9103343 states: This is expected behaviour. SQL*Plus is written in oci and oci has a default prefetch value of 1 row. However prefetch upon a fetch (as opposed to upon an execute) only takes place when you are not performing an array fetch, so when arraysize is 1. Regardless of arraysize the first fetch in the trace is always 1 ...


8

You can do most of this by using a login.sql. login.sql is executed during - surprising - login and is loaded from your SQLPATH or current directory. For the examples you gave, your really chose the worst case. Problem is the sqlterminator. Whatever you put in there, the forward slash is maintained as a free sqlterminator. Next to that, sqlplus first scans ...


8

To original poster... in the first option you missed a closing parenthesis Incorrect: (Your string) sqlplus x/y@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=c)(PORT=a))(CONNECT_DATA=(SID=z)(SERVER=DEDICATED)))' Correct: sqlplus x/y@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=c)(PORT=a))(CONNECT_DATA=(SID=z)(SERVER=DEDICATED))))'


8

On your Windows client, you need to specify the TNS alias @ORCL, or else it assumes you're trying to connect to a local database running on your Windows client, which there isn't one. Also, system as sysdba generally isn't used, not even sure if that makes sense. SYS as sysdba and just plain system are used. Enter user-name: system@ORCL Enter password: ...


8

You have to use Service Names to connect to Pluggable Databases in 12c. It's just one of those things that can trip you up, I guess! SQL Plus connecting OK probably threw you.


8

You need to terminate the SQL statement with a semicolon (;) or a put a slash (/) in the new line instead of hitting Enter. For example: select * from dual;. Otherwise SQLPlus will believe you have not finished your SQL statement, and it starts counting the lines. 2 is actually a line number, it is the 2nd line of your SQL statement. If you type nothing here ...


8

This answer based on a1ex07 comment: given the folowing detailes: user name: demo password: Pass1234 ip: 1.2.3.4 listener port: 1521 oracle SID: orcl pdb service name: pdborcl connect to core db from db host as sysdba: without need of password: sqlplus / as sysdba password manually: sqlplus sys as sysdba password in command: sqlplus sys/Pass1234 as ...


7

Yup, this is Bug 2391334 which has been around for long time, and probably will not be fixed in the near future. One way of working around this is "know" the path for scripts without actually hard coding that path. To do this in SQLPlus requires a trick - if you try to run a non-existent file, then you'll get an error message that includes the path name. ...


7

When your OS user is from a DBA group, you can connect AS SYSDBA with OS authentication: Two special operating system groups control database administrator connections when using operating system authentication. These groups are generically referred to as OSDBA and OSOPER. The groups are created and assigned specific names as part of the database ...


7

SYSDBA is not a user, it is a system privilege. When you connect as / you are connecting to the SYS user. You don't need a password when you connect as you are - as long as it's a local connection from an OS account in the DBA group. You haven't said what happens when you try to connect, or why you think you need a password; possibly that is that failing (...


7

These variables are a feature of SQL*Plus. psql, the equivalent program in the PostgreSQL world, also has variables. Use \set variable 'value' and insert into mytable(mycolumn) values (:variable);


7

DROP and TRUNCATE are Data Definition Language commands and thus cannot be rolled back. However, in Oracle you can use the following technologies to recover your table: Flashback Drop Flashback Database Tablespace Point in Time Recovery Table-Level Recovery From Backups (new in 12c) Flashback Drop If the Recycle Bin is enabled in your database, you can ...


7

C:\Users\balaz>sqlplus bp/bp@orcl SQL*Plus: Release 12.1.0.2.0 Production on Wed Sep 28 15:51:40 2016 Copyright (c) 1982, 2014, Oracle. All rights reserved. Last Successful login time: Wed Sep 28 2016 15:51:30 +02:00 Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production With the Partitioning, Automatic Storage ...


6

NLS_LANG can't be changed from inside a session, however other settings can. You can't change the character set once a database connection has been established (ie: the 2nd part of NLS_LANG), but you can change the language with: alter session set NLS_LANGUAGE=SPANISH ... and the territory with: alter session set NLS_TERRITORY=SPAIN


6

In Oracle Database, you can use Database Resource Manager (DRM) to manage memory, CPU, time and other resources. Usually your workflow is as follows: Create a resource plan Create the resource consumer groups Create the resource consumer group mappings Create the resource-plan directives You create a plan with the DBMS_RESOURCE_MANAGER.CREATE_PLAN ...


6

You need to set the below: SET WRAP OFF


6

Because you are not logged in as the user system. When you execute conn system/password as sysdba, Oracle won't even check the user and password (--> from the local systeem where the db is running on). If you enter the system/password as sysdba and then execute 'show user', you'll notice you are logged in as user 'SYS'. So you are actually entering the wrong ...


6

Get all privileges from AAA SELECT DBMS_METADATA.GET_GRANTED_DDL('ROLE_GRANT','AAA') FROM DUAL; SELECT DBMS_METADATA.GET_GRANTED_DDL('SYSTEM_GRANT','AAA') FROM DUAL; SELECT DBMS_METADATA.GET_GRANTED_DDL('OBJECT_GRANT','AAA') FROM DUAL; Change the DDL commands with the user 'BBB' and execute.


6

When you use sqlplus userName/myPassword@"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=asdasdasd.com)(PORT=1524))(CONNECT_DATA=(SID=AARCER1)))" then you don't need any tnsnames.ora file. Your entry in tnsnames.ora file should be like this: AARCER1 = (DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST= asdasdasd.com)(PORT=1524)) (CONNECT_DATA = (SID = ...


5

This seems to be a quirk of SQL*Plus and arraysize rather than pipelined functions - the following demonstrates the same effect: create or replace function pause return integer as begin dbms_lock.sleep(2); return 1; end; / select pause from dual connect by level<10; You can (sort of) workaround the issue by selecting the rows twice and discarding ...


Only top voted, non community-wiki answers of a minimum length are eligible