How to "end" function definition in SQL plus?
I am using Oracle 11g and SQL plus.
I am trying to define a function and get back to the SQL prompt, but it is just not exiting the function definition.
SQL> create function dept_count (dept_name varchar(20))
2 returns integer
3 begin
4 declare d_count integer;
5 select count (* ) into d_count
6 from instructor
7 where instructor.dept_name = dept_name
8 return d_count;
9 end
10 ;
11
12
13
14
15
16 ;;;
17 end dept_count;
18 ;
19
20 ; <--- I was expecting the SQL> prompt here but it doesn't appear.
What should I do? Please help. Thanks.
And, to answer probably the most frequently asked question when I was an Oracle instructor ...
If you are saving this statement in a file to execute later, after the "/" at the bottom, hit return, so that your file contains a line feed after the /, rather than your file ending with the /
Otherwise you get the annoying, but completely harmless, error message "Input truncated after (number) characters" when you compile the program.
Similar Messages
-
How to retreive this file in SQL*Plus
If I upload files which name is KOREAN, name of files is invisible.
I dont't know cause of this problem.
How is keeping korean name of file from breaking?
Also, answer how to retreive this file in SQL*Plus
Thanks
silverbellTo access ifs data from SQL, you need to (officially) setup a 'user view'. Refer to the Java API documentation on how to do this. Once you have created the user view, then you may access this view using any SQL tool.
-
How to Generate Trace Files in SQL*Plus
Hi Friends ,
How to Generate Trace Files in SQL*Plus ?
i have no idea
thanks
rajWhat trace files would you like to generate?
Are we talking SQL trace files?
ALTER SESSION SET sql_trace = TRUE;This will be generated in the user_dump_dest on the server.
show parameter dump -
How to find session information in sql plus
Can someone please tell me how to find session information in sql plus? I specifically want to know my privileges for the current session. Thanks in advance.
SELECT * FROM session_privs;
SELECT * FROM session_roles; -
How to invoke multiple sessions of sql*plus thru pl/sql program
Hi
How to invoke multiple sessions of sql*plus thru pl/sql program.
ThanksHow to invoke sql*plus in a procedure?????
I have to invoke more pl/sql sessions?????No you don't "have to".
Look at what you are trying to do.
You have a program running inside the PL/SQL engine. This is running nicely inside the Oracle database and is perfectly capable of issuing other SQL statements, PL/SQL programs etc. inside it's nice cosy Oracle environment.
You are asking for this PL/SQL to shell out to the operating system, run an external application, for which it will have to supply a username and password (are you planning on hard coding those into your PL/SQL?), and then that external application is supposed to run more SQL or PL/SQL against the database.
a) Why hold all this code external to the database when it can quite happily reside on the database itself and be executed through jobs or whatever.
b) Consider what would happen if someone were to replace the external application with their own program of the same file name... they'd be able to capture the username and password for connecting to the database, therefore a major security flaw.
The whole idea of doing what you want through external calls to SQL*Plus is ridiculous. -
How to return a value from sql plus activity
Hi,
I want to return a value from sqlplus activity to a processflow variable.
SQL PLUS activity has a property :"RESULT_CODE", whenever i run the process flow this value is always reurned as 0.
in sqlplus activity i have written some pl/sql block....
for example
begin
end;
exit
i want to do something like
begin
if v=100 then
return 1
else
return 0;
end if;
end;
exit
can some please tell me how can i return value from this pl/sql block to proessflow.
Regards,
RD_RBStable ==> function
input param from table to function. ==> input mapping paramter to store the output from the mapping.
Will this now work. -
Need to find out View definition by SQL PLUS
Hi,
I have a view VW_XXX, I want to know by which table this view has created. But need to use only SQL PLUS not any tool.
Please let me know how cani see the full definitio of the view by SQL PLUS.
Regs,
brijYes, it will work for both 9i and 10g. Just run the commands, and you will get the output.
These are not "Dangerous Commands!!!"
Regards
Girish Sharma
Edited by: Girish Sharma on Dec 26, 2011 5:19 PM
To solve these issues Oracle9i has introduced the DBMS_METADATA package which can be used to retrieve object definitions as DDL or XML. There are a number of ways to use the API, but I suspect the majority of people will only ever use the following functions.
Source:http://www.oracle-base.com/articles/9i/MetadataAPI.php
Edited by: Girish Sharma on Dec 26, 2011 5:36 PM
And here it is doc link :
http://docs.oracle.com/cd/A91202_01/901_doc/appdev.901/a89852/d_meta11.htm#1024701 -
How to cancel a search in SQL*Plus
Once a search is initiated in SQL*Plus Worksheet, how can you stop it? I am on Windows NT. The normal Ctrl-C, Ctrl-Break, Esc don't work. I found an obscure reference in the SQL*Plus documentation about a cancel function, but it didn't give the keystrokes.
I actually managed to crash an 8.0.5 database by hitting Ctrl-C in the middle of a query.
Oracle Support advised me that this was a known bug. The solution?
Don't hit Ctrl-C in the middle of a query!
null -
How to run multiple scripts in sql*plus?
I would like to run 2 scripts in sql*plus, how do I do this? I tried the following, but it won't run.
create table student_new
AS
select *
from student
insert into student_new
(last_name, first_name
values
(Crop, Jenny)
The above are the two scripts I want to run, what am I doing wrong.
ThanksDo you have a solution to run multiple scripts continuosly, one after the other as one script.
Say I have file1.sql file2.sql, file3.sql.
I want to create a script run.sql, where this will run file1.sql,file2.sql,file3.sql one after other without any one running one after the other like follows:
run.sql should have
begin
@file1.sql
@file2.sql
@file3.sql
dbms_output.put_line(select sysdate from dual);
end;
If I run run.sql all the three scripts should be executed successfully and then display the current time . All these files have update statements(50,000 updates each file).
Very urgetn. Can some one hlpe, please.
Thanks in advance. -
How execute this stored procedure from SQL PLUS???
Hello folks....
Help me please...
I have this procedure....
CREATE OR REPLACE PROCEDURE TEST(COD OUT VARCHAR2, NUM OUT
VARCHAR2, ID OUT VARCHAR2)
AS
BEGIN
END;
SO, I4D LIKE TO EXECUTE IT FROM SQL PLUS::
BUT, I DONT KNOW HOW TO DO..PLEASE SEND ME A SAMPLE..
THANK UThank u man!!!
look, my error before was :
SQL> set serveroutput on
SQL> declare
SQL> cod varchar2(100);
SQL> num varchar2(100);
SQL> id varchar2(100);
SQL> begin
SQL> TEST( cod, num, id );
SQL> EXEC DBMS_OUTPUT.put_line( cod || ' ' || num || ' ' ||
id );
SQL> end;
SQL> /
i put the EXEC....
thank u!!! -
How to bind DATE variables in SQL*Plus
I have a stored procedure in a package that has a DATE OUT parameter
myPackage.myProcedure( outDate OUT DATE )
I am trying to test this from SQL*Plus
How do I specify a Bind variable for the outDate? The VARIABLE command does not allow DATE types?
If this was a CHAR type I could have done
VARIABLE myChar CHAR
BEGIN
myPackage.myProcedure( :myChar )
END;
PRINT myChar
How do I do this with DATE data types instead? I am using Oracle 8.1.7.you should use VARCHR2 type with the minimum length that can store a value defined by your NLS_DATE_FORMAT
string. The returned date will be converted to a VARCAHR2 type and the size and format will depend on
your NLS_DATE_FORMAT setting.
=============================================================================
SQL> variable dt VARCHAR2(20)
SQL> create or replace procedure ret_date(dt OUT DATE) is
2 begin
3 dt := SYSDATE ;
4 end ;
5 /
Procedure created.
SQL> exec ret_date(:dt) ;
PL/SQL procedure successfully completed.
SQL> print dt
DT
13-OCT-02
SQL> select sysdate from dual ;
SYSDATE
13-OCT-02
SQL> alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS' ;
Session altered.
SQL> exec ret_date(:dt) ;
PL/SQL procedure successfully completed.
SQL> print dt
DT
13-OCT-2002 10:43:23
SQL>
================================================================ -
How to compile a procedure from Sql*Plus?
Dear friends,
I couldnt find the way how to compile my invalid procedure through sql*Plus.
I know this is very awkward,but I m in need of that command only.
Thanks
Ritesh SharmaPls check it --
SQL>
SQL>
SQL> @C:\RND\Oracle\Function\a.sql;
11 /
Function created.
SQL>
SQL>
SQL> start C:\RND\Oracle\Function\a.sql;
11 /
Function created.
SQL> Regards.
Satyaki De. -
How to control logic flow in SQL Plus script
Hi
I have the requirement below:
Before I start running an SQL script, I need to ensure that I am connecting as a particular user. If I am not that user, then the script should show a msg "Error - Invalid User - Log in as <<username>>"
Let's say i am executing a script A.sql.
SQL > @<path>a.sql
But before this script is executed -- i shall check for the user:
block begins...
select user into var1 from dual
if upper(var1) != 'ABCUSER' then
-- display the error message and stop execution of this script
else
@<path>a.sql (*it executes what i want :) )
end if;
block ends...
How do I write this code using an SQL script ? Pls suggesHi,
As Centinul said, SQL*Plus is poorly equipped to deal with problems like this. If possible, try to do what you want outside of SQL*Plus.
If you really have to do it in SQL*Plus, here are two ideas:
(1) run a script conditionally
(2) deliberately raise an error
(1) Using SQL*Plus substitution variables, you can decide which of several scripts to run as a sub-script, based on the results of some query.
For example, if a.sql is the script that only user ABCUSER is allowed to run, then write two other very short scripts:
(a) warning.sql, such as the following:
-- warning.sql
PROMPT You are not authorized to do this.
QUIT(b) step_1.sql, which decides whether a.sql or warning.sql should be run, and does it:
-- step_1.sql - Decide whether a.sql or warning.sql is to be run next, and do it.
-- (a) decide:
COLUMN script_name_col NEW_VALUE script_name
SELECT CASE
WHEN USER = 'ABCUSER'
THEN 'a.sql'
ELSE 'warning.sql'
END AS script_name_col
FROM dual;
-- do:
@&script_nameYou may want to use @@, or specify a complete path name.
(2) Deliberately raise an error, either in a separate script or in a.sql itself, like this:
WHENEVER SQLERROR EXIT
SELECT CASE
WHEN USER = 'ABCUSER'
THEN NULL
ELSE TO_NUMBER ('This will raise ORA-01722')
END AS "Welcome!"
FROM dual;
WHENEVER SQLERROR NONE
-- continue with the original a.sql -
How to get Arabic dates in SQL*Plus?
I want to do a very simple thing.
I want to type in Arabic and Display dates in Arabic.
Instead i get ????? ??????? ????? ??????? ? ? ???????, ????? for this?
Why is this?
I then changed my Windows XP "Regional and Language Options" all to Arabic. Now, I get AR (Arabic) in my language selection bar at the bottom of the Desktop. When I choose AR I can type Arabic in Notepad. ُ
Even HERE I can type in Arabic: فغحث غخعق ةثسسشلث اثقث
But in Sql*PLus I get ????? ??????? ????? ??????? ? ? ???????, ?????
If I choose AR in SQL Plus and type in Arabic I get garbage characters?
How to get Arabic in Sql*Plus?
SQL> SHOW USER
USER is "ARABDTEST"
SQL> SELECT * FROM v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
PL/SQL Release 11.1.0.6.0 - Production
CORE 11.1.0.6.0 Production
TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
NLSRTL Version 11.1.0.6.0 - Production
SQL> SELECT * FROM nls_session_parameters;
PARAMETER VALUE
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
17 rows selected.
SQL> ALTER SESSION set NLS_DATE_LANGUAGE = 'ARABIC';
Session altered.
SQL> SELECT TO_CHAR(SYSDATE, 'RRRR/MM/DD YEAR MONTH DAY MON DY AM PM DL') FROM dual;
TO_CHAR(SYSDATE,'RRRR/MM/DDYEARMONTHDAYMONDYAMPMDL')
2013/04/08 TWENTY THIRTEEN ????? ??????? ????? ??????? ? ? ???????, ????? 08, 2013
SQL> ALTER SESSION set NLS_DATE_LANGUAGE = 'AMERICAN';
Session altered.
SQL> SELECT TO_CHAR(SYSDATE, 'RRRR/MM/DD YEAR MONTH DAY MON DY AM PM DL') FROM dual;
TO_CHAR(SYSDATE,'RRRR/MM/DDYEARMONTHDAYMONDYAMPMDL')
2013/04/08 TWENTY THIRTEEN APRIL MONDAY APR MON PM PM Monday, April 08, 2013
SQL> SELECT * FROM nls_database_parameters;
PARAMETER VALUE
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET WE8MSWIN1252
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_RDBMS_VERSION 11.1.0.6.0
20 rows selected.I am not sure SQL*Plus in character mode can display Arabic characters on Windows. OTN NLS_LANG FAQ http://www.oracle.com/technetwork/products/globalization/nls-lang-099431.html#_Toc105389288 says:
>
if you are testing with "special" characters please DO use the GUI and not the "DOS box" sqlplus.exe !
>
SQL*Plus GUI is not available with 11G: you should use SQL Developer. -
How to detect client OS from SQL*Plus script
Sometimes in a SQL*Plus script I need to execute OS commands e.g.
host rm tempfile.bufHowever of course Windows has no "rm" command by default, so I have to edit the script to use
host del tempfile.bufNow if I could define &DELETE (for example, "cat"/"type" is another) as a substitution variable, I could just use
host &DELETE tempfile.bufMaybe I need more coffee but all I could come up with was something like this:
def rm=rm
def cat=cat
spool sqlplus_windows_defs.cmd
prompt echo def rm=del
prompt echo def cat=type
spool off
host .\sqlplus_windows_defs > sqlplus_windows_defs.sql
@sqlplus_windows_defs.sql
host &rm sqlplus_windows_defs.cmd
host &rm sqlplus_windows_defs.sqlthe idea being that you first define the variables for nix ("rm" and "cat"), then attempt to create and execute a Windows command file containing DOS versions ("dele" and "type"), which does not run under nix. Unfortunately the OS failure message (".sqlplus_windows_defs: not found" in Unix) appears on the screen despite SET TERM OFF, so I'm back where I started.
I know there are various ways to get the server OS, and you can get the SQL*Plus version with &_SQLPLUS_RELEASE and so on, but I can't see a way to determine the client OS. Any suggestions?Thanks guys. This seems to work in Windows XP - will try on Unix when I get a chance:
col DELETE_COMMAND new_value DELETE_COMMAND
col LIST_COMMAND new_value LIST_COMMAND
def list_command = TYPE
def delete_command = DEL
SELECT DECODE(os,'MSWIN','TYPE','cat') AS list_command
, DECODE(os,'MSWIN','DEL','rm') AS delete_command
FROM ( SELECT CASE WHEN UPPER(program) LIKE '%.EXE' THEN 'MSWIN' END AS os
FROM v$session
WHERE audsid = SYS_CONTEXT('userenv','sessionid') );
host &LIST_COMMAND xplan_errors.lst
host &DELETE_COMMAND xplan_errors.lstIf the user doesn't have access to v$session it will just default to the Windows commands.
http://www.williamrobertson.net/code/xplan.sql
Maybe you are looking for
-
Best way to configure a network comprising WLSE and many APs ?
Hi the Cisco NetPro community, I would like to have a discussion with you on the best way to configure a network containing a WLSE and a large amount of Access Points. The network I want to configure comprises some subnetnorks, each comprising about
-
Why would my iMac go into sleep mode while Apple TV is accessing content from it? Does it not recognize this action as "in use" and therefore sticks to its original sleep setting?
-
2 users on the same computer. Full iTunes shows up on only one
There are 2 users on this computer. Only the iTune downloads appear on one. How can I get the full iTunes library on the other?
-
Blank drop-downs when using LOV with static VO
Hello, I am using JDeveloper 11.1.2.3.0 I have set some attributes to display as LOV. The attributes that are connected with Entity Based VO are fine but those that are connected with Static List VO not. In the second case I am getting drop-downs wit
-
Best Practices for Keeping Library Size Minimal
My library file sizes are getting out of control. I have multiple library's that are now over 3TB in size! My question is, what are the best practices in keeping these to a manageable size? I am using FCPX 10.2. I have three camera's (2x Sony Handyca