How to put pause in an SQL script.
I am using Oracle 11g. I run an sql script called Queries.sql. The script has a lot of create and insert statements. I want to put a few delays in the execution of the script (eg. 5 second delays) so that I can watch the output as the script is being executed. How to do this?
Hi,
EXEC dbms_lock.sleep (5);will pause for 5 seconds. You may not have EXECUTE privileges on dbms_lock; if not, log on as SYS and grant them, or ask your DBA to grant them to you.
Another thing you can do is the SQL*Plus command:
ACCEPT dmy PROMPT "Press [Enter] to continue ..."which will wait indefinitely for the user to press the [Enter] key before continuing.
Edited by: Frank Kulash on Apr 26, 2011 7:59 PM
Similar Messages
-
How to put Page break in SAP Script
Hi Experts,
Please tell me how to put page break in SAP Script. or give some sample code
looking forward for your reply..
Regards,
Kali PramodHi,
NEW-PAGE is used to insert a page break ,
it can be conditional if used between IF..ENDIF
e.g. /:IF &KNA1-NAME1& = 'XYZname'
/:NEW-PAGE
/:ENDIF
If u want to Page break after displaying certain records or after some condition you use NEW-PAGE
reward if useful. -
How to define variables in toad sql script editor - newbie
I have just pull out the script of a Function and want to run it on toad SQL editor.
I am little bit confused how to define the VARIABLEs here in toad SQL editor to run my script.
SELECT
NVL(SUM(debit), 0) - NVL(SUM(credit), 0)
INTO l_accountBalance
FROM
GLP_VoucherMaster vm
INNER JOIN GLP_VoucherDetail vd ON vm.GLP_VoucherMaster_ID = vd.GLP_VoucherMaster_ID
INNER JOIN GLP_ChartOFAccounts coa ON vd.GLP_ChartOfAccounts_ID = coa.GLP_ChartOfAccounts_ID
WHERE
vm.isActive = 'Y' AND vd.isActive = 'Y'
-- *** how to define variables in toad sql script editor ***
AND vm.voucherDate < p_cDate
AND coa.AccountCode LIKE p_accountCode || '%';
Thanks
w\Just prefix with a colon (:)
SELECT NVL (SUM (Debit), 0) - NVL (SUM (Credit), 0)
INTO L_accountbalance
FROM Glp_vouchermaster Vm
INNER JOIN
Glp_voucherdetail Vd
ON Vm.Glp_vouchermaster_id = Vd.Glp_vouchermaster_id
INNER JOIN
Glp_chartofaccounts Coa
ON Vd.Glp_chartofaccounts_id = Coa.Glp_chartofaccounts_id
WHERE Vm.Isactive = 'Y'
AND Vd.Isactive = 'Y'
AND Vm.Voucherdate < :P_cdate
AND Coa.Accountcode LIKE :P_accountcode || '%';
/:p -
How can I extract the full SQL script for a schema?
Hi,
How can I extract the full SQL script for a schema?
I am looking for some method that needs jus SQL*Plus and preferably doesn’t need any extra tool.
Thank you,
AlanHow can I extract the full SQL script for a schema?What are you looking for? PL/SQL code? DDL for objects?
-
How to accept user inputs from sql script
I want to create Tablespace useing sql script , but the location of the data file I need accept from user . (to get the location of the data file ) .
How can I accept user input from pl/sql .
Example :
CREATE TABLESPACE TSPACE_INDIA LOGGING
DATAFILE 'H:\ORACLE_DATA\FRSDB\TSPACE_INDI_D1_01.dbf'
SIZE 500M AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL;here I need to accept location of the datafile from user ie : 'H:\ORACLE_DATA\FRSDB\TSPACE_INDI_D1_01.dbf'Hi,
Whenenever you write dynamic SQL, put the SQL text into a variable. During development, display the variable instead of executing it. If it looks okay, then you can try executing it in addition to displaying it. When you're finished testing, then you can comment out or delete the display.
For example:
SET SERVEROUTPUT ON
DECLARE
flocation VARCHAR2 (300);
sql_txt VARCHAR2 (1000);
BEGIN
SELECT '&Enter_The_Path'
INTO flocation
FROM dual;
sql_txt := 'CREATE TABLESPACE SRC_TSPACE_INDIA LOGGING
DATAFILE' || flocation || ' "\SRC_TSPACE_INDI_D1_01.dbf" ' || '
SIZE 500M AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL ';
dbms_output.put_line (sql_txt || ' = sql_txt');
-- EXECUTE IMMEDIATE sql_txt;
END;
/When you run it, you'll see something like this:
Enter value for enter_the_path: c:\d\fubar
old 5: SELECT '&Enter_The_Path'
new 5: SELECT 'c:\d\fubar'
CREATE TABLESPACE SRC_TSPACE_INDIA LOGGING
DATAFILEc:\d\fubar
"\SRC_TSPACE_INDI_D1_01.dbf"
SIZE 500M AUTOEXTEND ON NEXT 1280K MAXSIZE
UNLIMITED
EXTENT MANAGEMENT LOCAL = sql_txt
PL/SQL procedure successfully completed.This makes it easy to see that you're missing a space after the keyword DATAFILE. There are other errrors, too. For example, the path name has to be inside the quotes with the file name, without a line-feed between them, and the quotes should be single-quotes, not double-quotes.
Is there some reason why you're using PL/SQL? In SQL, you can just say:
CREATE TABLESPACE SRC_TSPACE_INDIA LOGGING
DATAFILE '&Enter_The_Path\SRC_TSPACE_INDI_D1_01.dbf'
SIZE 500M AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL;though I would use an ACCEPT command to given a better prompt.
Given that you want to use PL/SQL, you could assign the value above to sql_txt. If you need a separate PL/SQL variable for flocation, then you can assign it without using dual, for example:
DECLARE
flocation VARCHAR2 (300) := '&Enter_The_Path';The dual table isn't needed very much in PL/SQL.
Edited by: Frank Kulash on Jan 10, 2013 6:56 AM -
How to use parameters in oracle SQL script????
Right now I am writing a SQL script to create a schema and build the objects of this schema....
I use a .net winform program to run sqlplus to parse this sql script ...
The problem is that the schema name and the tablespace's location and the sys password must be input by the user, so my SQL script should use these runtime input parameters instead of const parameters....
So, how to use parameter in SQL script ...........
Are there some example scripts in oracle home directory for me to refer to????Hi,
UNISTD wrote:
thanks .....
what's the difference between variable , define, accept in sqlplus ???VARIABLE declares (but does not assign a value to) a bind variable. Unlike substitution variables, bind variables are passed to the back end to be compiled, and they can only be values in certain data types. You can not use a bind vaiable in place of an identifier, so to do something like
CREATE USER &1 ...a bind variable won't work.
"DEFINE x = y" sets the substitution variable &x to have the value y. There is no user interaction (unless x or y happen to contain undefined substtiution variables).
"DEFINE x" shiows the value of the substitution variable &x, or, if it is undefined, raises a SQL*Plus error. I use this feature below.
ACCEPT sets a substitution variable with user interaction.
And if the user miss some parameters in “sqlplus /nolog ssss.sql par1 par2 par5 par6”, how to use default value of the miss parameters??Don't you need a @ befiore the script name, e.g.
sqlplus /nolog @ssss.sql par1 par2 par5 par6Sorry, I don't know of any good way to use default values.
The foloowing works, but, as you can see, it's ugly.
"DEFINE 1" display a message like
DEFINE 1 = "par1" (CHAR)if &1 is defined; otherwise,it will display a SQL*Plus error message like
SP2-035: symbol 1 is UNDEFINEDNotice that the former contains an '=' sign, but the latter does not.
The best way I know to use default values is to run the DEFINE command, save the output to a filee, read the file, and see if it's an error message or not.
So you can use a script like this:
-- This is DEFINE_DEFAULT.SQL
SPOOL got_define_txt.sql
DEFINE &dd_old
SPOOL OFF
COLUMN dd_new_col NEW_VALUE &dd_new
WITH got_define_txt AS
SELECT q'[
@got_define_txt
]' AS define_txt
FROM dual
SELECT CASE
WHEN define_txt LIKE '%=%'
THEN REGEXP_REPLACE ( define_txt
, '.+"
([^"]*)
, '\1'
ELSE '&dd_default'
END AS dd_new_col
FROM got_define_txt
{code}
and start your real script, ssss.sql, something like this:
{code}
DEFINE dd_new = sv1
DEFINE dd_old = 1
DEFINE dd_default = FOO
@DEFINE_DEFAULT
DEFINE dd_new = sv2
DEFINE dd_old = 2
DEFINE dd_default = "Testing spaces in value"
@DEFINE_DEFAULT
{code}
when this finishes running, the substitution variable &sv1 will either have the value you passed in &1 or, if you didn't pass anything, the default value you specified, that is FOO.
Likewise, &sw2 will have the value you passed, or, if you didn't pass anything, the 23-character string 'Testing spaces in value'.
Here's how it works:
Define_default.sql puts the output of the "DEFINE x" command into a column, define_txt, in a query. That query displays either the existing value of the substitution variable indicated by &dd_old or, if it is undefined, the default value you want to use, which is stored in the substitution variable &dd_default. The substitution variable named in &dd_new is always set to something, but that something may be its existing value.
Notice that the paramerters to define_default.sql must be passed as global varibales.
Why didn't I just use arguments, so that we could simply say:
{code}
@DEFINE_DEFAULT sv1 1 FOO
{code}
? Because that would set the substitution variables &1, &2 and &3, which are miost likely the very ones in which you're interested.
I repeat: there must be a better way, but I'm sorry, I don't know what it is.
I usually don't do the method above. Instead, I always pass the required number of parameters, but I pass dummy or plce-holder values.
For example, if I wanted to call ssss.sql, but use defulat vlaues for &1 and &3, then I would say something like:
{code}
@ssss ? par2 ?
{code}
and, inside ssss.sql, test to see if the values are the place holder '?', and, if so, replace them with some real default value. The use has to remember what the special place holder-value is, but does not need to know anything more, and only ssss.sql itself needs to change if the default values change. -
How to deal with multiple language SQL script?
Hi All,
We now want to create a SQL script that contains multiple languages(English, Chinese, Japanese), this script need to be run at there different database installed on different OS, for example, Oracle9i on Windows 2000 English Edition/Chinese Edition/Japanese Edition.
If I save the file as ANSI format, this file will only be recognized at local OS(e.g. the Chinese and Japanese character will not be normally displayed on other OS, if I run the script, the CH/JP characters will not be stored normally in DB).
If I save the file as Unicode format, this file can be recognized by all three OS, but Oracle SQL Plus will not recognize it, thus we can't run the script.
Who can tell me how to deal with this issue? Is it possible to save only one script that can run on different language OS?
Thanks,
SparkHi,
The ISQLplus supports multiple languages, but there will be following problems for my case:
1.ISQLplus don't support Unicode format script too, so I must save the file as ANSI format.
2.To display the characters normally depends on the database server's platform. I create a script contain three languages with ANSI format in Chinese OS, but if I want to load this script to database server installed on English OS via ISQLplus, the Chinese characters will not be displayed normally too.
PS:
So, I think this is not only related with Oracle but also the Windows OS, it is hard to create one file with ANSI format that can be displayed normally in different platforms.
Thank you all the same,
Spark -
How and where to run utlxplan.sql script?
Hi,
A basic question: where and how to run utlxplan.sql script? I'd like to know both in window and linux environment.
regards.....From sqlplus, you can connect as sys and run the utlxplan.sql. Then you need to grant privileges to other users and create synonyms...
-
How can I convert a mysql sql script to a oracle sql script
Hi,
We have a bunch of tables with data running on a mysql server.
This should now be moved to an oracle 9 db.
are there any tools to convert the import script of a mysql db
to a format of the sql script that work for oracle ?
Thanks
MichaelOracle has a tool called Migration Toolbench, which supports MySQL 3.22 and 3.23:
http://otn.oracle.com/tech/migration/workbench/content.html
On this same topic, I was wondering if anybody has tried migrating from PostgreSQL to Oracle 9i. The workbench doesn't seem to support it, and feeding a pg_dump file directly into SQL*Plus is not working. -
How to put pause in a multiplayer game on Texas Hold'em?
Anybody knows???
I don't know if you can pause the multiplayer game, you might have to start over. If the normal method of touching 2 corners doesn't work I expect there is no way.
-
How to put net line in SQL query?
Hi,
I am creating text file using utl_file and using new_line function. File is created on server side with linux platform. Then I email this txt file to user having windows on machine. On windows that new_line character does not appear and a box appears there instead. Any solution or hint for this?
Thanks,user12007410 wrote:
Hi,
I am creating text file using utl_file and using new_line function. File is created on server side with linux platform. Then I email this txt file to user having windows on machine. On windows that new_line character does not appear and a box appears there instead. Any solution or hint for this?
Thanks,As the previous answer says Windows uses CR (carriage return) and LF (line feed) characters (CHR(13)||CHR(10)) for newline characters, whereas unix based systems, such as your linux server, just uses LF (CHR(10)) to signify a new line.
If the file produced on a unix based server is FTP'd to a windows based system using ASCII format in the FTP program, then the FTP process will automatically convert LF to CR/LF and visa versa if you send them back the other way.
Because you are just emailing the file direct from your server to the windows client, it is being sent effectively in BINARY mode (i.e. as it was created) and as such the windows machine get's unix style newlines.
Either explcitly convert your newline characters to CHR(13)||CHR(10) when writing them out to the file or transfer your file using FTP in ASCII mode to cause the conversion to take place. -
Execute .sql scripts from a remote login
Hello,
1) How do I execute a remote sql script from sqlplus?
SQL>@remote_server:$HOME/test_sql.sql ...this did not work, which would work?
2) Another question, in sqlplus I can do...! echo testing123>$HOME/test123.txt.
How do I do this within a store procedure?
This does not work, which would work?
declare
v_test varchar2(300) := '! echo testing123>$HOME/test123.txt';
begin
execute immediate v_test;
end;
/Re Q2.
I take it that's an sqlplus feature on unix as it doesn't work on windows:
SQL> ! echo testing123>$HOME/test123.txt
SP2-0734: unknown command beginning "! echo tes..." - rest of line ignored.
SQL>Also the reason this isn't working from within PL/SQL is that the execute immediate statement is used to send SQL statements to the SQL engine. What you are attempting to do is to send sqlplus commands to the SQL engine which obviously knows nothing about sqlplus commands. Those commands are very specific to the sqlplus executable and will only work in that environment.
;) -
Hi,
How do you exit from an sql script?
e.g
DECLARE
VAR1 = VARCHAR2(10);
VAR2 = VARCHAR2(10);
BEGIN
VAR1 := 'hello';
VAR2 := 'world';
IF VAR1 != VAR2
THEN
DBMS_OUTPUT.PUT_LINE('Variables not equal');
## Exit here! <------- HOW?????
END IF;
END;
Cheers,
WarrenIf I understand correctly, you have a series of anonymous PL/SQL blocks in a script. If some test fails in one of them, then you do not want to run the rest of the script.
If exiting sqlplus is an acceptable means of failing, then you can do something like:
WHENEVER SQLERROR EXIT 1;
DECLARE
v1 VARCHAR2(20);
v2 VARCHAR2(20);
BEGIN
v1 := 'ABCDE';
v2 := 'FBCDE';
IF v1 <> v2 THEN
DBMS_OUTPUT.Put_Line('Variables Not Equal');
RAISE NO_DATA_FOUND;
END IF;
END;
DECLARE
v3 VARCHAR2(20);
BEGIN
v3 := 'Second Block';
END;
/in your script. As shown, the script will exit sqlplus without executing the second block. You can use any sql error instead of no data found.
Another possibility if exiting sqlplus is not acceptable would be to do something like this in your script:
VARIABLE failed NUMBER;
DECLARE
v1 VARCHAR2(20);
v2 VARCHAR2(20);
BEGIN
:failed := 0;
v1 := 'ABCDE';
v2 := 'FBCDE';
IF v1 <> v2 THEN
DBMS_OUTPUT.Put_Line('Variables Not Equal');
:failed := 1;
RETURN;
END IF;
END;
DECLARE
v3 VARCHAR2(20);
BEGIN
IF :failed = 0 THEN
v3 := 'Second Block';
END IF;
END;
/Note, the IF :failed = 0/END IF block should cover all the code in each subsequent anonymous block.
A third approach would be to re-write the series of anonymous blocks as a package, then create a small driver script to call each procedure in turn unless one returns an error.
TTFN
John -
Question about correctly EXIT on SQL Script
Hi there,
I have created a SQL script, every time when the raise_application error appears then of course the PL/SQL block ends but then still the external sql script is being executed, how can I prevent the External sql script from being executed after a raise application error is displayed?
Regards
RobH
DECLARE
BEGIN
IF start_date > stop_date
THEN
raise_application_error (-020110,
'Start Date can not be greater Stop Date. '
ELSE ..... do some selecting and inserting of data into temporary tables etc...
END IF;
END;
--And now a external SQL script should be started...
@c:\reports\test.sqlyou can trap your exception in the inner block using EXCEPTION block and from there propagate it to the external block to stop further processing. something like this...
DECLARE
l_deptno NUMBER;
BEGIN
FOR i IN (SELECT deptno FROM dept)
LOOP
BEGIN
FOR j IN (SELECT empno, ename FROM emp WHERE deptno = i.deptno)
LOOP
IF ( i.deptno = 20 ) THEN
RAISE_APPLICATION_ERROR(-20001, 'Error Raised');
ELSE
DBMS_OUTPUT.PUT_LINE('Dept = ' || i.deptno || ' EmpNo: ' || j.empno || ' EName: ' || j.ename);
END IF;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error Trapped Inside');
RAISE;
END;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error Trapped Outside');
END;
SQL> /
Dept = 10 EmpNo: 7782 EName: CLARK
Dept = 10 EmpNo: 7839 EName: KING
Dept = 10 EmpNo: 7934 EName: MILLER
Error Trapped Inside
Error Trapped Outside
PL/SQL procedure successfully completed. -
I know that OMWB can convert the store procedure to oracle but how can i convert a T-SQL script to oracle?
i know OMWB can eaily do it.
i can make the t-sql script to store procedure but i don't want this..
So is there any better way to change it?
AnilIm afraid the OMWB does not have support for scripts yet.
As noted you can cut and paste statements into the body of a stored procedure that is already captured by the OMWB and parse them. Unfortunately there is no other way to access the OMWB parser.
Regards,
Dermot.
Maybe you are looking for
-
Windows- No Disk error, HELP!
I have an ipod shuffle and when I connect it to the USB port, it loads up fine on itunes. Then as the music is synching, I get an error message that comes up reading "Windows-No Disk Exception Processing Message (then a whole bunch of numbers and let
-
Cs4 photoshop top 40, problem with #30 - actions
I was using the lynda.com tutorials on photoshop when I was watching Deke's top 40... on # 30 - actions, I hit a snag... I was following along with the video, and I made the new folder, and the new action, but got a "can't do" sign when I tried to ma
-
Macbook Pro USB port is not working
I have a Macbook Pro 15-inch mid 2010 running Mavericks 10.9.1, the problem is that one of de two USB ports stop working, does not recognize any USB divice. I already tried restarting the PRAM and the PMU and the problem persists. Please help!
-
Cant find the pictures I imported from my digital camera using iphoto
Hi, I have a macbook pro and imported part of some photos from my digital camera using Iphoto. When it prompted me whether the photos should be deleted from the camera, I chose 'yes'. It deleted the pictures from the camera, but I cant find them anyw
-
Ticks in Model Tree are reset on View change
How to avoid reseting ticks in the Model Tree when the user changes View of the model? I understand that this behavior is on purpose but I would like to turn it off. I have tried to add the ticks check into CameraEventHandler but it seems that Camera