sqlplus

Oracle query execution time

浪尽此生 提交于 2019-11-30 00:09:27
问题 I would like to get the query execution time in Oracle. I don't want the time Oracle needs to print the results - just the execution time. In MySQL it is easy to get the execution time from the shell. How can I do this in SQL*Plus ? 回答1: One can issue the SQL*Plus command SET TIMING ON to get wall-clock times, but one can't take, for example, fetch time out of that trivially. The AUTOTRACE setting, when used as SET AUTOTRACE TRACEONLY will suppress output, but still perform all of the work to

RAISE_ APPLICATION_ ERROR--之异常处理

百般思念 提交于 2019-11-29 19:09:43
平时用来测试的异常处理 我们都是通过dbms_output.put_line来输出异常信息,但是在实际的应用中,需要把异常信息返回给调用的客户端。 其实 RAISE_APPLICATION_ERROR 是将应用程序专有的错误从服务器端转达到客户端应用程序(其他机器上的SQLPLUS或者其他前台开发语言) raise_application_error(异常类型,传递信息) 异常类型:number 值域:-20000 到-20999 传递信息:varchar2(2000) DBMS_STANDARD包的RAISE_APPLICATION_ERROR过程,可以重新定义异常错误消息,它为应用程序提供了一种与ORACLE交互的方法。语法如下 RAISE_APPLICATION_ERROR(errorNumber,errorString) errorNumber是数值在-20000到-20999之间,errorString为自定义的错误信息。 如: update jobs set job_title = v_newJobTitle where job_id = v_jobid; if sql%notfound then RAISE_APPLICATION_ERROR(-20167,'update failure!'); end if; .......... 当在sqlpus中测试时

In SQL*Plus, how do I change the prompt to show the connected user and database?

我们两清 提交于 2019-11-29 18:32:23
问题 To show, for example.... USER@SID > I thought this was potentially helpful to a few people so I'm going to answer it too! 回答1: Amend your $ORACLE_HOME\sqlplus\admin\glogin.sql script - add: set sqlprompt "_user '@' _connect_identifier > " to the end of the file. In Oracle 10g this will change correctly each time you issue a "conn". For clients before 10g it won't change when you do a "conn" but will remain as the username/db you first connected to. You can also use _date for the current date

halt on compilation error in a sqlplus script

筅森魡賤 提交于 2019-11-29 17:31:00
I am deploying pl/sql code using several sql files that are called with @@file . If a package got a compilation error the script continues to the end. Is there a way to stop on every compilation error? I tried WHENEVER SQLERROR EXIT SQL.SQLCODE but the script still continues. No native sql*plus way I'm aware of. Only workarounds. Like this: 20:42:50 TEST@oars_sandbox> get scr 1 whenever sqlerror exit rollback 2 create or replace procedure my_failed_proc as 3 i number; 4 begin 5 select 1 into i from me_iz_not_exist; 6 end; 7 / 8 @check my_failed_proc 9 create or replace procedure my_correct

How do you pass an argument to a PL/SQL block within a sql file called using START in sqlplus?

与世无争的帅哥 提交于 2019-11-29 16:45:08
I have a bash script running several sql files via sqlplus: sqlplus $connectioninfo << end start file1.sql start file2.sql start file3.sql $variable quit end file3 has some PL/SQL: BEGIN DBMS_OUTPUT.PUT_LINE(&1); END; / But it just prints the literal "&1" instead of the value of $variable . I have also tried the following in file3: DEFINE var_a = &1; BEGIN DBMS_OUTPUT.PUT_LINE(var_a); END; / and also the following: DECLARE var_b VARCHAR2(64) := &1; BEGIN DBMS_OUTPUT.PUT_LINE(var_b); END; / and finally: DEFINE var_a = &1; DECLARE var_b VARCHAR2(64) := var_a; BEGIN DBMS_OUTPUT.PUT_LINE(var_b);

How to show errors in sqlplus

我们两清 提交于 2019-11-29 16:28:20
I would like to know how to show errors in sqlplus. try to compile a view alter view SYS.DBA_XML_SCHEMAS compile; I have the message : ERROR at line 1: ORA-04063 : view altered with compilation errors. I try : show errors; it says : No errors I try : show errors view SYS.DBA_XML_SCHEMAS it says : LINE/COL ERROR 0/0 ORA-00942 : table or view does not exist If I could compile with errors, the view must exist or it would tell me that the view does not exist. I dont know how to display the compilation errors of the view thank you You can query the dba_errors view, or the all_errors view, directly;

SQLplus decode to execute scripts

五迷三道 提交于 2019-11-29 15:58:28
I am writing a script to be run in sqlplus 11. I have a user defined variable called compression. If this is true then I want to run the script CreateTablesCompression, otherwise run. I have the following: decode(compression,'true',@@CreateTablesCompression,@@CreateTables); However,when I run this I am thrown the error: unknown command beginning "decode... Am I missing something here, I can't see why SQLPlus wouldn't recognise decode? Decode is not a SQL*PLUS command, you cannot use it directly in sql*plus only inside a pl/sql block or a query. So here is an example of how a conditional

Simple Oracle query: literal does not match format string

为君一笑 提交于 2019-11-29 15:47:59
I want to execute a simple function in Oracle. The signature is defined as follows: CREATE OR REPLACE FUNCTION NewCaseListForValidation ( p_fromDate in DATE, p_toDate in DATE, p_rowCount in INT ) RETURN SYS_REFCURSOR IS return_value SYS_REFCURSOR; ... I should be able to execute it with: var rc refcursor exec :rc := newcaselistforvalidation('2010-01-01','2011-01-01',100); print :rc But when typing "newcaselistforvalidation('2010-01-01','2011-01-01',100)", I get: ERROR at line 1: ORA-01861: literal does not match format string ORA-06512: at line 1 I googled a bit and it seems I can't figure out

Remove Column Header into the Output Text file

假装没事ソ 提交于 2019-11-29 13:07:28
I want to create a flat file (text file) of my query from Oracle SQL Developer. I have successfully created the text file using SPOOL, thru a script text file, but i want to remove the header of each column into my output. I am getting this output: Header000001 Header000002 ------------ ------------ Adetail1 Bdetail1 Adetail2 Bdetail2 Adetail3 Bdetail3 But, I want to get this output: Adetail1Bdetail1 Adetail2Bdetail2 Adetail3Bdetail3 I already tried the command "set heading off", but a message says: "SQLPLUS COMMAND Skipped: set heading off". These are the inputs I've issued: spool on; spool C

SQLPLUS command line with Windows batch file

只愿长相守 提交于 2019-11-29 10:43:25
I want to create a batch file which will open the SQLPLUS [CLI] and will execute some stored sql file and will also store the output to text file. So I've created this batch file [which does not work]. These SQL file contains SQL which returns the max number from a table. sqlplus scott/tiger@DB @sql1.sql>data1.txt @sql2.sql>data2.txt The problem is it does not executes the SQL files after opening the SQLPLUS Windows XP Oracle 9i What about native Sql*plus spooling? run.bat: sqlplus hr/hr@sandbox @d:\run.sql run.sql: spool d:\run.log set echo on select * from dual / exit run.log: 01:50:20 HR