sqlplus

how to increase sqlplus column output length?

白昼怎懂夜的黑 提交于 2019-12-02 17:15:07
I have some queries to find out the ddl of some objects from a schema. The result columns I am getting are truncated in the middle of the queries. How can I increase the width of the column? I tried with SET SERVEROUTPUT ON SIZE 1000000; SET LINESIZE 50000; set pagesize 50000; set long 50000; But I'm still getting the same result. I've just used the following command: SET LIN[ESIZE] 200 (from http://ss64.com/ora/syntax-sqlplus-set.html ). EDIT: For clarity, valid commands are SET LIN 200 or SET LINESIZE 200 . This works fine, but you have to ensure your console window is wide enough. If you're

Force index use in Oracle

别等时光非礼了梦想. 提交于 2019-12-02 17:05:50
I encountered this question in an interview and had no clue how to answer: There is a table which has a index on a column, and you query: select * from table_name where column_having_index="some value"; The query takes too long, and you find out that the index is not being used. If you think the performance of the query will be better using the index, how could you force the query to use the index? Rene You can use optimizer hints select /*+ INDEX(table_name index_name) */ from table etc... More on using optimizer hints: http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/hintsref

Why do C-style comments make insert statement run twice?

南楼画角 提交于 2019-12-02 12:43:46
问题 To make a long story short, I started getting ORA-00001 primary key violations and I tracked down the issue to the fact that some of my INSERT INTO statements were running twice. I then discovered that the offending commands had a C-style comment afterwards: WHENEVER SQLERROR EXIT FAILURE SET ECHO OFF SET HEADING OFF SET PAGESIZE 0 SET FEEDBACK OFF SET TIMING OFF SET TIME OFF SET TRIMSPOOL ON SET TRIMOUT ON SET LINESIZE 120 SET SQLBLANKLINES ON SET SERVEROUTPUT ON [...] INSERT INTO INF_FIELD

SQL Not A Single Group Group Function

妖精的绣舞 提交于 2019-12-02 11:59:12
Okay guys here is the question. I have to list the department ID, department name, count of sales reps, and average commission rate for each department. Also I need to Group by department, and sort by average commission rate in ascending order. I am receiving an error at line 1 under the De.Dept_ID saying that is not a group by expression Here is my code: SELECT DE.Dept_ID as DeptID, Dept_Name as DeptName, COUNT(SR.Sales_Rep_ID) as SalesRepCount, Comm_Rate as AvgCommRate FROM DEPT_arb DE, SALES_REP_arb SR, COMMISSION_arb C WHERE DE.Dept_ID = SR.Dept_ID AND Comm_Rate = (SELECT AVG(Comm_Rate)

How copy data from one database to another on different server?

元气小坏坏 提交于 2019-12-02 09:57:41
问题 I have 2 DB with the same schema on different servers. I need to copy data from table T to the same table T in test database in different server and network. What is the easiest way to do it? I heard that data can be dumped to flat file and than inserted into database. How does it works? Can this be achieved using sqlplus and oracle database? Thank you! 回答1: Use Oracle export to export a whole table to a file, copy the file to serverB and import. http://www.orafaq.com/wiki/Import_Export_FAQ

How to connect to Oracle as “SYS” from SQL*Plus in Java

房东的猫 提交于 2019-12-02 09:17:31
问题 I want to connect to Oracle as SYS from SQL*Plus in Java. But I am not able to connect. But I am able to connect as user named SCOTT . My code snippet is as follows: public static void test_script () { String fileName = "@t.sql"; //t.sql contains "show user" command String sqlPath = "D:\\"; String sqlCmd = "sqlplus"; // String arg1 = "scott/tiger@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=hostname)(Port=PORT ID))(CONNECT_DATA=(SID=SID)))"; String arg1 = "sys as sysdba/tiger@(DESCRIPTION=

Back to the sqlplus prompt

对着背影说爱祢 提交于 2019-12-02 08:19:37
I'm a beginner in PL/SQL, I'm trying some sql script but sometimes I have an error in my script and the prompt doesn't appear; I remain in input mode. How can I retrieve the prompt without shutting down the terminal? (p.s.: I used sql plus for oracle 11g under Ubuntu OS) From the documentation SQL*Plus treats PL/SQL subprograms in the same manner as SQL commands, except that a semicolon (;) or a blank line does not terminate and execute a block. Terminate PL/SQL subprograms by entering a period (.) by itself on a new line. You can also terminate and execute a PL/SQL subprogram by entering a

How to remove unnecessary line breaks in SQL Plus Spooling?

老子叫甜甜 提交于 2019-12-02 07:58:56
问题 I am spooling a package from a database and this is what I get: CREATE OR REPLACE PACKAGE BODY "CPI"."GIPI_WBOND_BASIC_PKG" AS FUNCTION get_gipi_wbond_basic (p_par_id gipi_wbond_basic.par_id%TYPE) RETURN gipi_wbond_basic_tab PIPELINED IS v_wbond gipi_wbond_basic_type; BEGIN FOR i IN (SELECT a.par_id, a.obligee_no, a.bond_dtl, a.inde mnity_text, a.clause_type, a.waiver_limit, a.contract_date, a.cont ract_dtl, a.prin_id, a.co_prin_sw, a.np_no, a.coll _flag, a.plaintiff_dtl, a.defendant_dtl, a

How to remove blank spaces from SQL*Plus query?

China☆狼群 提交于 2019-12-02 07:29:21
问题 My query below being called from sqlplus is returning lot of spaces in the end of each value, how can I remove it? See example below: * I substituted the values with x x ,x ,x ,x ,x,x x My query is: set linesize 1000 set trimspool on set trimout on set pagesize 0 set colsep , set feedback off spool /result.csv SELECT process_id, x1, x2, x3, x4, x5, x6, x FROM x WHERE x IN ('x'); 回答1: The simplest way is to concatenate the columns with the commas in between, rather than using colsep : select

DateDiff Function

懵懂的女人 提交于 2019-12-02 07:09:14
问题 I am trying some examples for DateDiff Function SELECT DATEDIFF(day,'2008-06-05','2008-08-05') AS DiffDate This statement gives me an error From keyword not found where expected. Why do I get this error and how can I solve it? Also, when I try this : SELECT DATEDIFF(day,datebegin,datestop) From table; I get this error "datediff" invalid identifier . How can I get day difference? 回答1: What database are you using? A google search gave me this: http://www.mssqltips.com/sqlservertip/2508/sql