Can we do non-mandatory parameter of stored procedure?
Can we make a parameter in the stored procedure as a non-mandatory? so that we can call the stored procedure with parameters?Assign a default value, for example
p_someparameter IN INTEGER DEFAULT 0
or
p_someparameter IN INTEGER := 0
Tags: Database
Similar Questions
-
Can get us data back from a stored procedure in a select query?
Hello
Suppose I have a function GetSum(x,y) that returns the sum of two numbers x and y. We can call this function from a function sql like this:
But it's possible thanks to a stored procedure? for example, can I call a stored procedure from a select query, as I did above code?select GetSum(4,5) SUM from dual;
bootstrap wrote:
Hello
Suppose I have a function GetSum(x,y) that returns the sum of two numbers x and y. We can call this function from a function sql like this:select GetSum(4,5) SUM from dual;
But it's possible thanks to a stored procedure?
NO!
-
How to accept the array as a parameter of stored procedure
Hi, this is the scenario
the java team send me a table of numbers as an input for my procedure.
the size of the array can be dynamic... I do not know the size
what I have to do is
I have to write a procedure that must accept this table as parameter
crosses of the first element of the array too the end of the array to each value in the table
and get on a table for this value and remove this line in the table
How can I do?
Please suggest
concerning
REDA
Published by: raj_fresher on May 7, 2009 11:42Raj,
Here is the code
--This is you will create create or replace type TYP_PHONES as table of Varchar2(15) ; / --- This will be your procedure create or replace procedure give_me_an_array1( p_array in TYP_PHONES ) as begin -- Do whatever you want to with the data you get for i in 1 .. p_array.count loop dbms_output.put_line( p_array(i) ); end loop; end; /
Tell your guy java to define this table as below
String[] intArray= {"john","miller","scott"}; ArrayDescriptor descriptor =ArrayDescriptor.createDescriptor( "TYP_PHONES", conn ); ARRAY array_to_pass = new ARRAY( descriptor, conn, intArray );
* [Full active code | http://db-oracl.blogspot.com/2009/05/passing-arrays-from-java.html] *.
SS
-
script can be invoked only from a java stored procedure
I made a java procedure and called via a sql procedure that accepts a string input:
the string is passed to Runtime.getRuntime () .exec ("myString");
If this string is:
RM-f /test/test22.log
proc = Runtime.getRuntime () .exec ("rm-f /test/test22.log");
the test22.log file that is located in the test folder is deleted
but when I place the order. /test/batchstart.ksh to run a script, the script does not run.
proc = Runtime.getRuntime ().exec(".) (' / test/batchstart.ksh ");
received the permissions of files and also the rights of the executables.
If some bobdy can say why the script is not running which will be a great helpHello
I had the chance to do something like the following without using oraenv
ORACLE_SID = GNVDEV
ORACLE_HOME=/U21/app/Oracle/product/10.2.0/Db_1/PATH = / usr/local/bin: $ORACLE_HOME/bin: $PATH
export PATHIn some cases affecting LD_LIBRARY_PATH to include the libs oracle was also necessary.
Another option is to simply use the full paths everywhere for example use
$ORACLE_HOME/bin/sqlplus instead of just sqlplus.Hope this helps,
Ravi. -
Spend multiple values with parameter of stored procedure
CREATE TABLE VTEST_INSERT)
NUMBER OF MY_ID,
COLUMN1 VARCHAR2 (50)
);
-SELECT * FROM VTEST_INSERT;
INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (1, 'TEST1');
INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (2, "TEST2");
INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (3, "TEST3");
INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (4, "TEST4");
INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (5, 'TEST5');
INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (1, "TEST6");
INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (2, 'TEST7');
INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (3, "TEST8");
INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (4, 'TEST9');
INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (5, "TEST10");
CREATE OR REPLACE
PROCEDURE VTEST_INSERT_SP (vid in VARCHAR2, vname IN VARCHAR2)
AS
BEGIN
DELETE FROM VTEST_INSERT WHERE MY_ID IN (vid);
INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (vid, vname);
END;
/
EXEC VTEST_INSERT_SP(1,'TEST999');
This set works well above. But I want to be able to pass multiple values VNAME. so, something like:
EXEC VTEST_INSERT_SP(1,'TEST999','TEST888','TEST777');
any help is appreciated. Thank you.
This would make many inserts each with the same vid and values of different VNAME.
Try something like this
- SET SQLBLANKLINES
- ALTER SESSION SET PLSQL_WARNINGS = ' ENABLE: ALL ';
- DROP TABLE vtest_insert;
- CREATE TABLE vtest_insert (vid NUMBER, vname VARCHAR2 (20));
- INSERT ALL
- IN vtest_insert (vid, vname) VALUES (1, "yyyy")
- IN vtest_insert (vid, vname) VALUES (1, "bb")
- IN vtest_insert (vid, vname) VALUES (1, "cccccc")
- IN vtest_insert (vid, vname) VALUES (2, "ddd")
- IN vtest_insert (vid, vname) VALUES (2, 'ee')
- SELECT * FROM .dual 'PUBLIC '.
- SELECT * FROM vtest_insert;
- CREATE or REPLACE TYPE vnames_tab_ty IS TABLE OF VARCHAR2 (20)
- /
- DISPLAY ERRORS;
- CREATE OR REPLACE PROCEDURE vtest_insert_sp
- (
- p_vid IN vtest_insert.vid%TYPE,
- p_vnames IN vnames_tab_ty
- )
- DEFINE AUTHID
- IS
- BEGIN
- DELETE FROM vtest_insert WHERE the vid = p_vid;
- FORALL idx IN p_vnames. FIRST... p_vnames. LAST
- INSERT INTO vtest_insert (vid, vname) VALUES (p_vid, p_vnames (idx));
- END vtest_insert_sp;
- /
- DISPLAY ERRORS;
> - DECLARE
- Vnam vnames_tab_ty;
- vid vtest_insert.vid%TYPE.
- BEGIN
- BK.vid: = 1;
- BK.vnames: is vnames_tab_ty ('vn-01', 'vn-02', 'vn-03');.
- vtest_insert_sp (p_vid-online bk.vid, p_vnames-online bk.vnames).
- COMMIT;
- BK.vid: = 2;
- BK.vnames: is vnames_tab_ty ('vn-04', 'vn-05', 'vn-06', 'vn-07');.
- vtest_insert_sp (p_vid-online bk.vid, p_vnames-online bk.vnames).
- COMMIT;
- END;
- /
- SELECT * FROM vtest_insert;
Which produces the following output
Table created.
5 rows created.
VNAME VID
---------- --------------------
1-aaaa
1 bb
1 cccccc
2 ddd
2 EA
Type of creation.
No errors.
Created procedure.
No errors.
PL/SQL procedure successfully completed.
VNAME VID
---------- --------------------
1 VL-01
1 VL-02
1 VL-03
2 vn-04
2 vn-05
2 vn-06
2 vn-07
7 selected lines.
SQL >
Kind regards
Dariyoosh
-
Good morning guys,
How can I view the log of a stored procedure when it is called by an application?
Thank youFor example: the number of records deleted, updated, insert and so on...
You could create a log_table and insert the SQL value % ROWCOUNT (with appropriate details) respective after the DML statements in your procedure is performed.
Insert other details as you wish. This journal would be a procedure that is declared as a stand-alone transaction, as already mentioned. -
Passing the params in mysql stored procedure
Makes no mistake, but when I hard code the values in the stored procedure, I get results, I leave as params - if not.
Something must be a miss with how I said, but I can't understand that:
Can anyone help? details below:
: the stored procedure:
Create procedure keyword_getBySource (in sourceRecordName varchar (20), in sourceRecordId varchar (50))
Start
Select
tblkeyword.*
Of
tblkeyword,
tblrecordlink
where
tblrecordlink.sourceRecordName = @sourceRecordName
and
tblrecordlink.sourceRecordId = @sourceRecordId
and
tblrecordlink.linkRecordName = 'keyword'
and
tblkeyword.keywordId = tblrecordlink.linkRecordId
;
end
: cfm:
"< cfstoredproc procedure ="keyword_getBySource"datasource =" "username =" "password =" ">
< cfprocparam type = 'in' cfsqltype = "CF_SQL_VARCHAR" dbvarname = "sourceRecordName" value = "Log" / >
< cfprocparam type = 'in' cfsqltype = "CF_SQL_VARCHAR" dbvarname = "sourceRecordId" value = "0d8a6d3e-cf1e - 19(d) 5-2b9fc8ee1de01ad0" / >
< name cfprocresult = resultset "getBySource" = "1" / >
< / cfstoredproc >@... seems mysql does not use these to designate the params in a stored procedure
Take them out - it works.
-
Extraction of the DDL (Code) of the stored procedures only
DB Version: 11 g
I have a list of stored procedures (about 250) whose code IE. Statements to CREATE or REPLACE STORED PROCEDURE I want to extract a file.
Is there an option in imp or impdp where I can extract only the code of these stored procedures?
Apart from the imp/impdp, is there another way to do this?Is there an option in imp or impdp where I can extract only the code of these stored procedures?
Impdp, Yes. Write the contents of a file, the option SQLFILE.
DUMPFILE = exp.dmp
LOGFILE = exp.log
SCHEMAS = TEST
INCLUDE = PROCEDURE: 'IN ("SP") '.
SQLFILE = sp... SQLOr use dbms_metadata.get_ddl
set long 99999 set pagesize 0 SELECT DBMS_METADATA.GET_DDL(object_type, object_name, owner) FROM DBA_OBJECTS WHERE OBJECT_TYPE = 'PROCEDURE' and OWNER='OWNER';
HTH
-André -
Run the stored procedure of c#
Hi, im new to the use of stored procedures and I have the following stored procedure...
CREATE OR REPLACE PROCEDURE DRL_PROCEDURE2 (var_SOURCE_OBJECTID IN varchar2, var_NEW_OBJECTID OUT varchar2)
AS
BEGIN
SELECT MAX (NEW_OBJECTID)
IN var_NEW_OBJECTID
OF DRL_CONVERSION
WHERE SOURCE_OBJECTID = var_SOURCE_OBJECTID;
END;
I want to be able to call this procedure from my windows form application and display the result of the stored procedure in a label... could someone please help me! Thanks in advance!http://www.csharpfriends.com/articles/getarticle.aspx?articleid=78
You can find out how to call the stored procedure (in the link above you will find an example of SQL Server 2005 that also work for you from your oracle stored procedure) in c#.HTH
Girish Sharma -
How to pass the content of the table as OUT of the stored procedure parameter
Hi all
I am writing a stored procedure where he must accept date as one of the parameters IN and it must interrogate the table of database on this criterion and should address data in a temporary table.
in the end, he must send all the data from the temporary table as the OUT parameter.
How to get there? should I create a new TYPE with all the columns in the Temp table and use this Type as a parameter? or SYS_REFCURSOR is the best option.
Thanks in advance.
Hello
The best way to do what you want depends on what you want. Start by describing what you need to do. It is best to post some data examples (CREATE TABLE and INSERT statements), and what results you want from this sample data. (See the FAQ forum: https://forums.oracle.com/message/9362002)
If you have any ideas on how to do the work (for example, populating a temporary table) it may be useful to include those who, too, but a clear distinction between WHAT you do and HOW you do it.
Bencol suggested, a SYS_REFCURSOR may be the best way to transmit the results.
Since you only post your table, or even describe what you wanted to do with it, I will illustrate using scott.emp, which is probably on your system.
Say you want a procedure that takes a DATE as an argument, then returned a certain designated columns (empno, ename, and hiredate in the example below) for all employees hired from the given DATE. You can write a procedure like this:
CREATE OR REPLACE PROCEDURE hired_since
(IN start_date DATE
out_data ON SYS_REFCURSOR
)
AS
BEGIN
OPEN FOR Out_data
SELECT ename, empno, hiredate
FROM scott.emp
WHERE hiredate > = start_date;
END hired_since;
/
DISPLAY ERRORS
You can test it in SQL * more like this:
VARIABLE c REFCURSOR
EXEC hired_since (DATE ' 1982-01-01',: c);
PRINTING: c
The output I received this test was:
ENAME, EMPNO, HIREDATE
---------- ---------- ---------
7788 SCOTT APRIL 19, 87
7876 ADAMS MAY 23, 87
7934 MILLER JANUARY 23, 82
-
Is it possible to move an Oracle null input parameter to a stored procedure
I have a stored procedure taking 3 inputs and 1 output of donne. I use the Oracle parameter to add all the input parameters 3 as follows:
OracleParameter = cmd inobj. Parameters.Add ("wid", OracleDbType.Int32, 50);
inobj. Direction = ParameterDirection.Input;
inobj. Value = _employeeID;
and the addition of the setting of output as follows:
OracleParameter outobj is _cmd. Parameters.Add ("w_first", OracleDbType.Varchar2, 50);
outobj. Direction = ParameterDirection.Output;
On the side of the user interface, the user has the option of providing 1 entry or all inputs or any 2 based on his interest. Stored proc looks like this:
SP (inp1 in parameter, inp2 in inp3 in parameter, parameter, out parameter output1)
If I just get 1 or 2 entries of the user, it is very good query output data using the same stored procedure or do I create stored procedures for each scenario (combination of different entries)?
I get an error in pl/sql which indicates the invalid number of arguments?Maybe I can be more clear with c# code. :)
void SaveSomethingInOracle(int param1, string param2 = null, decimal? param3 = null) { // Set up your oracle connection and query here OracleParameter inobj = _cmd.Parameters.Add("w_id", OracleDbType.Int32,50); inobj.Direction = ParameterDirection.Input; inobj.Value = param1; OracleParameter inobj2 = _cmd.Parameters.Add("name", OracleDbType.Varchar2,50); inobj2.Direction = ParameterDirection.Input; inobj2.Value = param2; OracleParameter inobj3 = _cmd.Parameters.Add("quantity", OracleDbType.Decimal,50); inobj3.Direction = ParameterDirection.Input; if (param3.HasValue) { inobj3.Value = param3.Value; } else { inobj3.Value = null; } }
This c# method takes 3 parameters. The first is necessary, the other two are optional. If you do not set them, they take the value default null and passing it to the database. If you want to set the first and third only, you can still pass null as the other. If you have this piece of code to call the stored procedure any combination of parameters that you use, and the proc will get values or NULL values properly.
Hope he says. You need only one together code to do what you want to do. :)
Published by: Tridus on December 19, 2012 12:10
-
A stored procedure with input &; output parameter as XML
Hello
I have a requirement in which I need to have a stored procedure accepts with huge XML from Java and MS a process all the records in the XML file and return the output with a few messages inside XML.
CurrentY, I have a stored procedure to process the xml code stored in the Oracle database.
I am using the following SQL statement to read data from the XML column.
I want to run similar queries to retrieve data from the XML passed as parameter of entry of JAVA.select xmltest1.id,xmltest1.name from xmltest, XMLTABLE( XMLNamespaces(default 'syncpsna/schemas'), '/XMLTestRequest/insert/row' PASSING xmltest.data_xml COLUMNS "ID" number(10) PATH 'id', "NAME" varchar2(50) PATH 'name') xmltest1 where xmltest.id = 2;
If I could get some examples to read the XML and return the xml to the calling program.
ConcerningI can run the query to extract the different sections in the xml file when the XML is stored in a table column. How can do the same thing on XML passed as an input parameter.
Pretty much the same path, using the clause of PASSAGE.
Assuming that the input XML is passed as parameter 'p_inputXML', you can do:SELECT x.id , x.name FROM XMLTable( XMLNamespaces(default 'syncpsna/schemas'), '/XMLTestRequest/insert/row' PASSING p_inputXML COLUMNS "ID" number(10) PATH 'id', "NAME" varchar2(50) PATH 'name' ) x ;
-
When we change the non-mandatory field in the form, it is not updated
Hello... I have a question here...
If I required fields in a custom form, and when I ask the form and change the value in the non-mandatory field and click on save, then it does not save. It is said ' no changes to save "." But it is not the same for the non-compulsory fields.
Can you please suggest me?
-vrdidaIf you have an element with an assigned LoV it much difference if you change the value of points (assuming that you have either the property 'Validate list', the value yes or you have a WHEN-VALIDATE-POINT-trigger who performs the search ID fk of the given text) or if you visit the 'empty' field, or NULL. In this case, you must create a WHEN-VALIDATE-trigger POINT on the element, which "cleans" the Fk - id as
IF :BLOCK.LOKUP_ITEM IS NULL THEN :BLOCK.FK_ID:=NULL; eNd IF;
-
The Null value as the default value for an input to a stored procedure parameter
Hello
How can we set the default values with the NULL value for the parameter in a stored procedure.
As described above if I want to delete only the functioningcreate or replace procedure emp_proc ( p_test_input in varchar2 p_emp_id in number, p_emp_name in varchar2, p_manager_id in number ) as begin if ( upper ( p_test_input ) = 'I' ) then insert into emp values ( p_emp_id ,p_emp_name ,p_Manager_id,sysdate ); elsif ( upper ( p_test_input ) = 'D' ) then delete from emp where emp_id = p_emp_id; else dbms_output.put_line ( 'Please input ''A'' for ADD or ''D'' Delete EMPLOYEE' ); end if; end;
I want to call this procedure without pass additional parameters.
Published by: Rede on May 28, 2010 12:21EXECUTE emp_proc('D',1010);
Published by: Rede on May 28, 2010 12:22create or replace procedure emp_proc ( p_test_input in varchar2, p_emp_id in number, p_emp_name in varchar2 default null, p_manager_id in number default null )
-
stored - procedure parameter problem table
Hello
I have the Oracle database version: 11.1.0.7
I downloaded ojdbc5.jar for this version.
and...
I have stored procedure:
As you can see the most interesting parameters are param7 and param8.PROCEDURE procedure_name ( param1 IN table1.objectid%TYPE, param2 IN table1.objecttype%TYPE, param3 IN table2.tariffid%TYPE, param4 IN DATE, param5 IN DATE, param6 IN table3.saleschannelid%TYPE, param7 IN rulemasteridtable, param8 OUT ruleid_table, param9 OUT INT ); type SCHEMA.RULEMASTERIDTABLE as table of number(15 ,5) TYPE ruleid_table IS TABLE OF table4.rulemasterid%TYPE INDEX BY BINARY_INTEGER;
I want to call this procedure using JDBC. I tried this way:
When I run this code I get an exception:OracleCallableStatement stmt = (OracleCallableStatement)connection.prepareCall( "CALL SCHEMA.PKG.procedure_name(?, ?, ?, ?, ?, ?, ?, ?, ?)"); stmt.setLong("param1", new Long(27167)); stmt.setString("param2", new String("SOME_STRING")); stmt.setLong("param3", new Long(27167)); java.util.Date date = new java.util.Date(); stmt.setDate("param4", new Date(date.getTime())); java.util.Date date2 = new java.util.Date(); stmt.setDate("param5", new Date(date2.getTime())); stmt.setLong("param6", new Long(1)); ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor("SCHEMA.RULEMASTERIDTABLE", connection); stmt.setArray("param7", new ARRAY(descriptor, connection, new Long[]{})); stmt.registerOutParameter("param8",OracleTypes.PLSQL_INDEX_TABLE); stmt.registerOutParameter("param9", Types.INTEGER); stmt.executeUpdate();
I don't know why I get this exception. Could you explain to me what's wrong with my code?Exception in thread "main" java.sql.SQLException: Missing IN or OUT parameter at index:: 8 at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70) ....
I think OracleTypes.PLSQL_INDEX_TABLE for my param8 is ok. If I use different type I get Exception: number or types of evil...
Please help me and thank you in advance.
HubertI've never seen an OracleTypes.PLSQL_INDEX_TABLE in action before. Documentation:
http://download.Oracle.com/docs/CD/E11882_01/Java.112/e10590/typesupp.htm
"Note: there is a PLSQL_INDEX_TABLE type, but it does not appear to be used outdoors."
You could look at using a registerIndexTableOutParameter.
For an example, see:
http://www.Oracle.com/technology/sample_code/tech/Java/sqlj_jdbc/files/Oracle10g/plsqltables/Readme.html
Maybe you are looking for
-
The right side and express USB card reader does not work
Hello The USB 3.0 right on my rMBP does not work. I have can´t to connect any device to this side. No connection or power. Express card reader doesn't work or the other. Finder or disk utility will not show map of mountain. I can´t find the card expr
-
What exact motherboard has Satellite Pro L650 - 15 c
Hello I searched for a long time and I have not found anything on this topic. What exact motherboard has the L650 - 15 c?H55 or P55? Because on the H55, it would be possible to use the graphicchip on the I3 which is not if the P55 is used in the L650
-
Not possible to remove the front panel control, for vi created in LV7 to LV09
Hi all... I'm trying to remove some controla blockdiagram as FP, but it is not possible to delete... not even possible to resize... already check, they are all unlock..., I enclose my vi. with screenshot... Regard´s, Kumar
-
EXPULSAR ST9250827AS ATA Device
In mid tower appears k TR deseo y Expulsar ST9250827AS ATA Device not be como hacer para quitar ese message u option
-
I was wondering what the various parameters are defined for eachim a home user, but I don't want to share files between the compositions.