How to execute the parametered stored procedure in sql *plus ?
how to execute the parametered stored procedure in sql *plus ?
my storedprocedure format
CREATE OR REPLACE PROCEDURE SMS_SELECTMPLOYEE
(empDOB out date, empEmpName out varchar2)
thanks & regards
mk_mur
Oh, sorry... making many reading-too-fast mistakes today...
You can't declare date variables in SQL*Plus (seel help var), but you can cast to varchar2:
TEST> CREATE OR REPLACE PROCEDURE SMS_SELECTMPLOYEE (empDOB out date, empEmpName out varchar2) IS
2 d date := sysdate;
3 e varchar2(10) := 'bob';
4 begin
5 empdob := d;
6 empempname := e;
7 end;
8 /
Procedure created.
TEST> var d varchar2(30)
TEST> var n varchar2(30)
TEST> call SMS_SELECTMPLOYEE(:d,:n);
Call completed.
TEST> print d n
D
11/07/06
N
bobYoann.
Similar Messages
-
How to view a stored procedure from sql plus
Can anyone please tell what is the command for viewing the content of the stored procedure from sql plus ?
ThanksHi,
I use this simple script to retrieve.......
EDTRAD@T_E_S_9-->l
1 select text from all_source where name = 'GET_MAN' -- proc name here
2* order by line asc
EDTRAD@T_E_S_9-->/
TEXT
FUNCTION get_man (in_man SSBOSS.CLNTWORK.manager%type)
RETURN varchar2 IS
CURSOR get_man(in_man SSBOSS.CLNTWORK.manager%type) IS
SELECT name
FROM ssboss.clntwork
WHERE agency = 'TM'
AND manager = in_man
AND manager is not null
AND manager != '**OB**';
v_man SSBOSS.CLNTWORK.name%type := null;
BEGIN
OPEN get_man(in_man);
FETCH get_man INTO v_man;
IF get_man%notfound THEN
v_man := 'Manager Not Found !';
RETURN (v_man);
CLOSE get_man;
END IF;
RETURN (v_man);
CLOSE get_man;
END;
21 rows selected.
EDTRAD@T_E_S_9--> -
Testing stored procedure using sql plus
I'm attempt to create and test a stored procedure in sql plus.
I enter:
create procedure sp_getconfiguration(mygroup in char, myparameter in char, myvalue in out char) as begin select configvalue into myvalue from tblconfiguration where configgroup = mygroup and configparameter = myparameter; end;/
I get a procedure created. response by when I type:
variable myval char
call sp_getconfiguration('Language','Enabled', myval);
I get the following error:
error at line 1:
ora-06576: not a valid function or procedure name
I can go into DBA studio and see the procedure listed and can compile it and it says "valid". I have tried granting execute permission to public and trying it again under sql plus and nothing seems to help.
I'm also attempting to run this same procedure from VB and get an invalid column name error from there.
Thanks for any help in advance.
LeeThanks for all your help. What I actually called product support and they helped me solve it. But what I found out is that if using oracle 8.1.# you have to invoke the stored procedure without the "call " in front of the procedure name. For instance.
sp_getconfiguation()
In version 9.# it appears that you use the call in front of the procedure. Dah! So if anyone else is having this problem. That is the solution. Thanks anyway. -
SOS..How to execute an Oracle Stored procedure
Please help me.
I need to execute an oracle stored procedure from a JSP.
I'M using Jakarta Tomcat and I dont have the Oracle Jbo tags and no BC4j tags.
Anyone have an example using standar tags or directives???.
This an emergency call..!!!!!!To execute a stored procedure (Oracle or other), you must create a CallableStatement.
Here is the link to the API description:
http://java.sun.com/products/jdk/1.2/docs/api/java/sql/CallableStatement.html
You use it like a query but the the syntax is:
{call <procedure-name>[<arg1>,<arg2>, ...]} -
How to execute an Oracle stored procedure which returns many records?
I have two synchronous scenarios XI<->PI<->JDBC, where JDBC is receiver adapter.
Each scenario runs a different stored procedure in Oracle database.
The first stored procedure returns only one record, the second stored procedure returns many records, which come from a cursor.
In the first scenario I executed the stored procedure following the directions of Help SAP page and works perfectly.
Link: [http://help.sap.com/saphelp_nw70/helpdata/en/2e/96fd3f2d14e869e10000000a155106/content.htm]
<root>
<StatementName5>
<storedProcedureName action=u201DEXECUTEu201D>
<table>realStoredProcedureName</table>
<param1 [isInput=u201Dtrueu201D] [isOutput=true] type=SQLDatatype>val1</param1>
</storedProcedureName>
</StatementName5>
<root>
I have sought in the forums of SDN and cannot find the way to run the second stored procedure, and receive the information it returns.
Thank you for your help.
Rafael Rojas.Think It doesnt matter either cursor or result set. Try to get the response back from JDBC and see what are the fields it exactly populating.
In Procedure you can able to find the columns selecting in Cursors. Give those columns in the DT.
File - JDBC (Execute-- Procedure)
To get the response
JDBC_respose - File
Correct me if im wrong.
Regards
Ramg -
To execute the same stored procedure multiple times
Suppose I have this :
select distinct batch_id, submit_date from batch where date > xxx;
Gives me :
301
305
306
Currently, I have a stored procedure PROC_A that has 3 cursors all of which have a field called batch_id(which ofcourse exists in the above batch table). Hence, when I run as of today
EXECUTE PROC_A;
This could process an unpredictable set of batch ids. I am looking to avoid this.
What I am trying to achieve here is :
When I do,
select distinct batch_id from batch where date > xxx;
301
305
306
For each of the above values, I want to call the PROC_A exclusively. In other words, by one shot, I want this procedure to be invoked 3 times, each time processing just one batch_id one after another (rather than passing those 3 values to the procedure and having it execute just once !). I also want to avoid using the batch table anywhere inside the stored procedure PROC_A.
How do I achieve this ? If another stored procedure can call PROC_A, I am okay with including the batch table there.What about an executed_date field on the table and a "where rownum=1" in the cursor?
proc_a
begin
begin
select batch_id
into b_id
from batch ...
where date > xxx
and date > last_executed
and rownum = 1;
exception
when NO_DATA_FOUND then
return;
end;
exec(b_id);
update batch
set last_executed = sysdate
where bacth_id = b_id;
return;
end;Bye Alessandro -
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 get the correct stored procedure in oracle
Hi sir,
i am having one stored procedure which i converted from sql it's compiled successfully.
create or replace
PROCEDURE Spvalidateholiday1
v_pidate1 IN Date DEFAULT NULL ,
v_piEmpid IN VARCHAR2 DEFAULT NULL ,
v_pidate2 IN Date DEFAULT NULL ,
v_poRetVal OUT Number
--RETURN NUMBER
AS
v_date3 VARCHAR2(20);
v_date4 VARCHAR2(20);
v_date5 VARCHAR2(40);
v_date6 VARCHAR2(40);
v_scode VARCHAR2(10);
v_dayoff1 VARCHAR2(20);
v_dayoff2 VARCHAR2(20);
BEGIN
v_date5 := To_Char(To_Date(v_pidate1,'YYYY-MM-DD','D'));
v_date6 := To_Char(To_Date(v_pidate2,'YYYY-MM-DD','D')) ;
SELECT Shift_Code
INTO v_scode
FROM Employee
WHERE Emp_ID = v_piEmpid;
SELECT WeeklyOff1
INTO v_dayoff1
FROM Shift
WHERE Shift_Code = v_scode;
SELECT WeeklyOff2
INTO v_dayoff2
FROM Shift
WHERE Shift_Code = v_scode;
SELECT dayid
INTO v_date3
FROM Weekly
WHERE dayss = v_dayoff1;
SELECT dayid
INTO v_date4
FROM Weekly
WHERE dayss = v_dayoff2;
--select @date3=dayid from Weekly w join Site_Param s on w.dayss=s.WeeklyOff1
--select @date4=dayid from Weekly w join Site_Param s on w.dayss=s.WeeklyOff2
IF ( v_date5 = v_date3
OR v_date6 = v_date4
OR v_date4 = v_date5
OR v_date3 = v_date6 ) THEN
BEGIN
v_poRetVal := 0 ;
END;
ELSE
BEGIN
v_poRetVal := 1 ;
END;
END IF;
RETURN; --v_poRetVal;
END;
but getting error:
ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'SPVALIDATEHOLIDAY1' ORA-06550: line 1, column 7: PL/SQL: Statement
could u check the stored procedure?
thanksHi sir,
i am calling it my application
that is used like this
Dim hshParam As New Hashtable
hshParam.Add("Empid", '00000002')
hshParam.Add("date1", '2012-10-25')
hshParam.Add("date2", '2012-10-27')
intRetProc = objDataTier.ExecuteStoredProcedureWithReturnT("Spvalidateholiday1", hshParam)
and here is this method written:
Public Function ExecuteStoredProcedureWithReturnT(ByVal sStroredProcedureName As String, ByVal phshTbl As Hashtable) As Integer
Dim cmdCommand As OracleCommand
Dim prmParmOutput As OracleParameter
Dim pParam As IDictionaryEnumerator = phshTbl.GetEnumerator
Dim sKey As String, sValue As String
Try
ExecuteStoredProcedureWithReturnT = True
OpenDbConnection()
cmdCommand = New OracleCommand(sStroredProcedureName, conConnection)
cmdCommand.CommandType = CommandType.StoredProcedure
cmdCommand.CommandTimeout = 0
While pParam.MoveNext
sKey = "v_pi" & pParam.Key
sValue = pParam.Value
cmdCommand.Parameters.Add(New OracleParameter(sKey, sValue))
End While
prmParmOutput = New OracleParameter
cmdCommand.Parameters.Add(New OracleParameter("v_poRetVal", SqlDbType.Int)).Direction = ParameterDirection.Output
' If
cmdCommand.ExecuteNonQuery()
ExecuteStoredProcedureWithReturnT = CInt(cmdCommand.Parameters("v_poRetVal").Value)
Catch ex As Exception
ExecuteStoredProcedureWithReturnT = 2
Throw ex
End Try
End Function
now tell me is it correct? -
PLS-00201 error occurs when batching a stored procedure in SQL*Plus
I have a batch file to run a stored procedure and spool the results to file. When I enter the commands manually in sql*plus the output works fine and my results are spooled to the output file. But when I run the same commands in the batched script I get an error.
Any ideas?
Stored Procedure:
create or replace procedure MMP( p_cursor in out SYS_REFCURSOR)
as
begin
open p_cursorfor select name, id from table;
end;
batch file 1:
sqlplus -S user/pw@REPORTDV @sp_output_spooled.sql
script file sp_output_spooled.sql
Pasting these commands directly to the SQL*Plus command prompt spools the result set to file as expected.
set colsep '|'
set echo off
set feedback off
set termout off
set heading off
set linesize 9000
set pagesize 0
set trimspool on
set headsep off
spool output.TXT
var rc refcursor
execute MMP(:rc)
print rc
spool off
exit
The errors printed to output.TXT file after the batch is run and error occurs:
BEGIN MMP(:rc); END;
ERROR at line 1:
ORA-06550: line 1, column 8:
PLS-00201: identifier 'MMP' must be declared
ORA-06550: line 1, column 8:
PL/SQL: Statement ignored
ERROR:
ORA-24338: statement handle not executed
SP2-0625: Error printing variable "rc"Hi,
Your code worked fine for me.
Is MMP procedure owned by the same user that is running the batch file or does it have proper privileges and synonym?
vr,
Sudhakar -
How to change the default directory from within SQL*Plus ?
Hello,
I want to change the default directory directly from within SQL*Plus to be able to launch my command files with simple instructions like :
@my_command.sql
If I haven't launched SQL*Plus from the directory containing the file my_command.sql, how do I change the default directory to the directory of my command files ?
I've searched through the Oracle documentation, there's no SET DEFAULTDIR or something like that. When I do a SHOW ALL, there's no variable containing the default directory.
If you have an idea...
regards,
Jérôme.Hi Jérôme (Jé²´me ?),
You cannot directly do that, but you can use @@ instead of @ to run subscripts in the same directory as the superscript
# head /tmp/tl30/xxx/[xyz].sql
==> /tmp/tl30/xxx/x.sql <==
prompt call y
@y
prompt call z
@@z
quit
==> /tmp/tl30/xxx/y.sql <==
prompt i am in y
==> /tmp/tl30/xxx/z.sql <==
prompt i am in z
# pwd
/root
# sqlplus -s scott/tiger@lsc62 @/tmp/tl30/xxx/x.sql
call y
SP2-0310: Datei "y.sql" konnte nicht geöffnet werden
call z
i am in zKind regards
Laurent Schneider
OCM DBA -
Decrypt the Encrpted Stored procedure and views
Hi,
Anybody can help me, how to decrypt the encrypted stored procedure in SQL server.?They are not encrypted. They are obfuscated. ApexSQL can show you the source code with the wink of an eye.
But before you do that - if this is a vendor application, check your license agreement.
Erland Sommarskog, SQL Server MVP, [email protected] -
Executing an oracle stored procedure in xMII 11.5
Dear all,
I am facing problem executing an oracle stored procedure using sql query in MII. The SP does not have any input or output parameters & consists of only 2 insert statements. I tried to use Command Mode, FixedQuery & FixedQuery With output mode, but the SP doesn't run.
This is the error i get when i use :
execute InsertTest or exec InsertTest - A SQL Error has occurred on query, ORA-00900: invalid SQL statement
I read in one of the posts to use 'CALL' instead of 'exec' or 'execute'. Even with this i get error which states:
A SQL Error has occurred on query, ORA-06576: not a valid function or procedure name
The syntax i used is CALL InsertTest - 'InsertTest' is the SP name.
I also checked Sam's comment in one of the posts about jdbc driver. We are using oracle 9i, so i guess there is no problem with the version of DB.
The stored procedure is working fine in SQL Developer, How else can i invoke the SP in MII?
Any help would be greatly appreciated.
Thanks,
Sushma.Hi all,
for insert create procedure
CREATE PROCEDURE MII_TEST_INSUPD
(ID_IN IN NUMBER,
NAME_IN IN VARCHAR2)
IS
BEGIN
-- UPDATE ROW
UPDATE TEST SET
NAME = NAME_IN
WHERE
ID = ID_IN;
-- NOT RETURN INSERT NEW LINE IN TABLE
IF SQL%ROWCOUNT = 0 THEN
INSERT INTO TEST (ID, NAME) VALUES (ID_IN, NAME_IN);
END IF;
END;
In MII you create a query template
Mode - Command
FixedQuery - insert the code below
CALL MII_TEST_INSUPD ([Param.1],'[Param.2]')
for returns the grid using procedures in oracle you need create a package on oracle server
CREATE PACKAGE PKG_test IS
TYPE cursortype is ref cursor;
PROCEDURE test (mycursor in out cursortype);
END PKG_test;
CREATE PACKAGE BODY PKG_test IS
PROCEDURE test (mycursor in out cursortype) AS
BEGIN
open mycursor for select * from test;
END;
END PKG_test;
In MII you create a query template
Mode - FixedQueryWithOutput
FixedQuery - insert the code below
CALL PKG_TEST.TEST(?)
Danilo -
How to pass the parameter of a stored procedure to iReport
Hi... i don't know how to pass the parameter of the stored procedure to the iReport.
In the Report Query, i tried
1. sp_storedprocedure ' value'
2. sp_storedprocedure +''''+$P{parameter}+''''+
3. sp_storedprocedure +$V+$P{parameter}++$F($F is a variable having a value of ' (a single quote))may you enlighten us please? thank youFor M$ SQL server I find that it only works when U use the fully qualified name...
e.g. catalod.dbo.my_procedure_name 'variable'
My full query in the Report Query window is something like this:
EXEC arc.dbo.jasper_Invoice 1000
Note that you may find that selecting from VIEWS / TABLES fails for no apparent reason and iReport will prompt you with the usual very unhelpful (we have what we "pay" for) prompt, stating that "The document is empty".
To work around this issue, where a statement like "SELECT * FROM arc.dbo.acc_invoices WHERE Invoice_id=1000" does not work, simply create a PROC, something like:
CREATE PROC jasper_MyProc (@my_rec_id integer) AS
SELECT * FROM arc.dbo.acc_invoices WHERE Invoice_id= @my_rec_id integer
...to wrap your SELECT statement, then call the PROC
Edited by: Sylinsr on Apr 22, 2008 4:23 PM -
Hello,
I have a request to create a user login and restrict that user to only be able to execute a single stored procedure.
Is this possible using only TSQL commands?
Am i on the right track here?
USE MyDatabase
GO
CREATE LOGIN [mylogin] DEFAULT_DATABASE = [MyDatabase], CHECK_POLICY = OFF, CHECK_EXPIRATION = OFF
GO
CREATE ROLE exec_single_proc_role
GO
exec sp_addrolemember 'exec_single_proc_role', 'mylogin'
GO
CREATE SCHEMA [restricted] AUTHORIZATION mylogin
GO
GRANT EXECUTE ON SCHEMA::restricted TO exec_single_proc_role
GOThanks for the reply.
This particular user should need to be able to Alter, Execute, and View the stored procedure as well.
Here is what i ended up with: Any improvement are appreciated. Thanks
USE MyDatabase
GO
--DROP SCHEMA
IF EXISTS (SELECT * FROM sys.schemas WHERE name = N'restricted')
DROP SCHEMA [restricted]
GO
--DROP SERVER WIDE LOGIN
IF EXISTS (SELECT * FROM sys.server_principals WHERE name = N'MyUserLogin')
DROP LOGIN [MyUserLogin]
GO
--CREATE SERVER WIDE LOGIN
CREATE LOGIN [MyUserLogin] WITH PASSWORD = 0x0100F1CF6792E602EF40DFF55983FDE81A9 HASHED, SID = 0xC33B04EECE59DC4C95BE66ED9B15D13D, DEFAULT_DATABASE = [MyDatabase], CHECK_POLICY = OFF, CHECK_EXPIRATION = OFF
GO
--DROP ROLE
DECLARE @RoleName sysname
set @RoleName = N'exec_single_proc_role'
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = @RoleName AND type = 'R')
Begin
DECLARE @RoleMemberName sysname
DECLARE Member_Cursor CURSOR FOR
select [name]
from sys.database_principals
where principal_id in (
select member_principal_id
from sys.database_role_members
where role_principal_id in (
select principal_id
FROM sys.database_principals where [name] = @RoleName AND type = 'R' ))
OPEN Member_Cursor;
FETCH NEXT FROM Member_Cursor
into @RoleMemberName
WHILE @@FETCH_STATUS = 0
BEGIN
exec sp_droprolemember @rolename=@RoleName, @membername= @RoleMemberName
FETCH NEXT FROM Member_Cursor
into @RoleMemberName
END;
CLOSE Member_Cursor;
DEALLOCATE Member_Cursor;
End
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'exec_single_proc_role' AND type = 'R')
DROP ROLE [exec_single_proc_role]
GO
--DROP USER
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'MyUserLogin')
DROP USER [MyUserLogin]
GO
--CREATE USER AND ASSIGN DEFAULT SCHEMA
CREATE USER [MyUserLogin] FOR LOGIN [MyUserLogin] WITH DEFAULT_SCHEMA=[restricted]
GO
--CREATE SCHEMA
CREATE SCHEMA [restricted] AUTHORIZATION [MyUserLogin]
GO
--CREATE ROLE
CREATE ROLE [exec_single_proc_role] AUTHORIZATION [MyUserLogin]
GO
--ADD ROLE
EXEC sp_addrolemember 'exec_single_proc_role', [MyUserLogin]
GO
GRANT EXECUTE ON SCHEMA::[restricted] TO [exec_single_proc_role]
GO
GRANT EXECUTE ON OBJECT::[dbo].[MyStoredProcedure] TO [MyUserLogin]
GO -
How to execute the packaged procedure(having out param) in TOAD for Oracle
Hi.
Could you help me
How to execute the packaged procedure having out parameters in TOAD for Oralce..
Thanks..Use anonymous PL/SQL block to execute it.
Example.
DECLARE
<out variable name> <out variable data type>;
BEGIN
<package name>.<procedure name>(<out variable name>);
END;
Maybe you are looking for
-
What determines the price and tax for consignment stock?
Hi All, anyone knows how the price and tax are calculated for consignment stock? in other word, among the info record , contract or material master, what determines the price and the tax calculation for consignment stock? please advise, your input wi
-
My daughter downloaded the new safari update on her iMac and now it won't open without new os update
We downloaded the new safari update on my daughter's iMac and one it won't open without the new os. How do we go back to the previous safari? Thanks!
-
Hello there fellow Spryers, I'm trying to use the Accordion widget. I'm building its divs dynamically and they display fine in Firefox. But when i switch to IE6 , all panels are open and it doesnt work correctly. I have placed the accordion widget in
-
IPod CONTACTS doesn't show GROUPS
I just got a new iPod Video 80GB, partly because it can sync addresses from my Mac's Address Book. However, I have not been able to see GROUPS in the CONTACTS and have to scroll though a lot of addresses to find anyone. How can you set iPod preferenc
-
PG G4 struggling, can't get disk utility to start....
Any time i start itunes, or system preferences my computer just gives me the spinning beach ball for quite a time. Sometimes the app will launch, other times it won't. When i try to force quite applications, half the time it won't shut the app down..