Execute stored procedure throu function
I have table which has list of all the procedures. I need to run them thru a function. I have written the code to fetch the values from table, but I am not sure how the function will execute them. Can someone pls help? Here is my code. c2.function_name contains the procedures name.
DECLARE
p1 tbl_func_list.seq%TYPE;
BEGIN
for c2 in (select function_name, seq from tbl_func_list order by seq)
loop
dbms_output.put_line('EXEC '||c2.function_name||' /');
end loop;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END;
Throws an error:
Error at line 1
ORA-06550: line 10, column 7:
PLS-00103: Encountered the symbol "END" when expecting one of the following:
* & = - + ; < / > at in is mod remainder not rem return
returning <an exponent (**)> <> or != or ~= >= <= <> and or
like LIKE2_ LIKE4_ LIKEC_ between into using || bulk member
SUBMULTISET_
The symbol ";" was substituted for "END" to continue.
Similar Messages
-
How to customize events, execute stored procedures using JSF and ADF BC
As a java beginner, I started with developing simple web application using JSF and ADF business component through visual and declarative approach. I need to know how to customize events, execute stored procedures, invoke functions on triggering events associated with rich controls. for eg. how to write customized functions on button click or checkbox click events to achieve business requirement and can be modified whenever required.
Edited by: 792068 on Aug 31, 2010 9:40 PMWhich business layer is prefered to create interactive data model: 1. ADF business components or 2. Enterprise JavaBeans using Java persistance API (JPA) or 3. Toplink 4. Portlets
which minimizes writing low level codes and how much OOPS knowledge is required for creating above business layer binding data to viewcontroller layer? -
Diif between Stored procedure and function
HI
I want all the differences between Stored procedure and function.
Even the basic diff is Procedure does not return any value and Function must be...
Thansk In advance...1) Functions are used for computations where as procedures can be used for performing business logic That's an opinion on usage not an actual difference.
3) You can have DML(insert,update, delete) statements in a function. But, you can not call such a function in a SQL query.Not true. As User defind functons limitations we can use a function that issues DML in a SELECT statement, if it uses the PRAGMA AUTONOMOUS_TRANSACTION.
4) Function parameters are always IN, no OUT is possibleEasily refutable...
SQL> CREATE OR REPLACE FUNCTION my_f (p OUT NUMBER) RETURN DATE
2 AS
3 BEGIN
4 p := to_number(to_char(sysdate, 'DD'));
5 RETURN sysdate;
6 END;
7 /
Function created.
SQL> var x number
SQL> var d varchar2(18)
SQL> exec :d := my_f(:x)
PL/SQL procedure successfully completed.
SQL> print d
D
18-NOV-05
SQL> print x
X
18
SQL>
Stored Procedure :supports deffered name resoultion Example while writing a stored procedure that uses table named tabl1 and tabl2
etc..but actually not exists in database is allowed only in during creationNot sure what this one is about...
SQL> CREATE PROCEDURE my_p AS
2 n NUMBER;
3 BEGIN
4 SELECT count(*) INTO n
5 FROM tab1;
6 END;
7 /
Warning: Procedure created with compilation errors.
SQL> sho err
Errors for PROCEDURE MY_P:
LINE/COL ERROR
4/4 PL/SQL: SQL Statement ignored
5/9 PL/SQL: ORA-00942: table or view does not exist
SQL>
7) A procedure may modifiy an object where a function can only return a value.An ounce of test is worth sixteen tons of assertion...
SQL> CREATE OR REPLACE FUNCTION my_f2 RETURN VARCHAR2
2 AS
3 BEGIN
4 EXECUTE IMMEDIATE 'CREATE TABLE what_ever (col1 number)';
5 RETURN 'OK!';
6 END;
7 /
Function created.
SQL> exec :d := my_f2
PL/SQL procedure successfully completed.
SQL> desc what_ever
Name Null? Type
COL1 NUMBER
SQL> I think there are only two differences between a procedure and a function.
(1) A function must return a value
(2) because of (1) we can use functions in SQL statements.
There are some minor difference in allowable syntax but they are to do withj RETURN values.
Cheers, APC -
How can I execute Stored Procedures in PARALLEL and DYNAMICALLY ?
Hi
I have a stored procedure. It can be executed like this
exec test @p = 1;
exec test @p = 2
exec test @p = n;
n can be hundred.
I want the sp being executed in parallel, not sequence. It means the 3 examples above can be run at the same time.
If I know the number in advance, say 3, I can create 3 different Execution SQL Tasks. They can be run in parallel.
However, the n is not static. It is coming from a table.
How can I execute Stored Procedures in PARALLEL and DYNAMICALLY ?
I think about using script task. In the script, I get the value of n, and the list of p, from the table, then running a loop with. In the loop, I create a threat and in the threat, I execute the sp like : exec test @p = p. So the exec test may
be run parallel. But I am not sure if it works.
Any idea is really appreciated.Hi nam_man,
According to your description, you want to call stored procedures in parallel, right?
In SSIS, we can create separate jobs with different stored procedures, then set the same schedule to kick the jobs off at the same time. In this way, we should be careful to monitor blocking and deadlocking depending on what the jobs are doing.
We can also put all stored procedures in SSIS Sequence container, then they will be run in parallel.
For more information about SSIS job and Sequence container, please refer to the following documents:
http://www.mssqltips.com/sqlservertutorial/220/scheduling-ssis-packages-with-sql-server-agent/
https://msdn.microsoft.com/en-us/library/ms139855(v=sql.110).aspx
If you have any more questions, please feel free to ask.
Thanks,
Wendy Fu
Wendy Fu
TechNet Community Support -
In JDBC Sender Adapter , the server is Microsoft SQL .I need to pass current date as the input column while Executing stored procedure, which will get me 10 Output Columns. Kindly suggest me the SQL Query String , for executing the Stored Procedure with Current date as the input .
Hi Srinath,
The below blog might be useful
http://scn.sap.com/community/pi-and-soa-middleware/blog/2013/03/06/executing-stored-procedure-from-sender-adapter-in-sap-pi-71
PI/XI: Sender JDBC adapter for Oracle stored procedures in 5 days
regards,
Harish -
Java Stored Procedure via Function Give 0RA 600 from SQL Workshop and App
Hi,
Anyone experienced stored procedures or functions failing when called from APEX app or SQL Workshop ( ora 600 ) yet they work fine when called from SQLPlus?
Sqlplus connected as my apex workspace schema owner:
select net_services.test_db_connection_via_ldap(
'APEXPRD1', 'test1', 'test1', null ) as result from dual;
RESULT
The database connection attempt was SUCCESSFUL
From Apex Sql Worshop:
select net_services.test_db_connection_via_ldap(
'APEXPRD1', 'test1', 'test1', null ) as result from dual;
ORA-00600: internal error code, arguments: [16371], [0x434B08150], [0], [], [], [], [], [], [], [], [], []
NOTE: Same result when run in response to button push on page in application.
Apex Version: 3.2.1.00.10
Oracle Version: 11.1.0.7.0
NOTE: I am using the embedded plsql gateway; was going to try NOT using it to see if it was shared server related (seemed to be from trc files)
Any ideas?
Since the code works from sqlplus, I know that it's good: Here some snippets
-- ========================================================================================
public class NetServices extends Object {
public static String doTestDbConnectionViaLdap
String piDbConnUrl,
String piUserName,
String piUserPassword
String vResult = null;
try
Connection conn = null;
OracleDataSource ods = new OracleDataSource();
ods.setUser( piUserName );
ods.setPassword( piUserPassword );
ods.setURL( piDbConnUrl );
conn = ods.getConnection();
conn.close();
vResult = "The database connection attempt was SUCCESSFUL";
} catch ( SQLException e )
int vErrCode = e.getErrorCode();
String vErrMsg = e.toString();
if ( vErrCode == 1017 ) {
vResult = "The database connection attempt FAILED! Incorrect Username or Password";
} else if ( vErrCode == 17433 ) { // Null Username or Password
vResult = "The database connection attempt FAILED! You must provide both a Username and a Password";
} else if ( vErrCode == 17002 ) {
vResult = "The database connection attempt FAILED! Net Service Name was Not Found";
} else if ( vErrCode == 17067 ) { // NULL Net Service Name
vResult = "The database connection attempt FAILED! You must provide a Net Service Name";
} else {
vResult = "The database connection attempt FAILED! Error " + vErrCode;
return vResult;
} // method: doTestDbConnectionViaLdap
-- ========================================================================================
function do_test_db_connection_via_ldap
pi_db_conn_url IN VARCHAR2,
pi_user_name IN VARCHAR2,
pi_user_password IN VARCHAR2
return VARCHAR2
is -- PRIVATE to the net_services package
language java -- NOTE: See cr_java_class_NetServices.sql for actual java implementation
name 'NetServices.doTestDbConnectionViaLdap
( java.lang.String, java.lang.String, java.lang.String ) return java.lang.String ';
-- ========================================================================================
function test_db_connection_via_ldap
pi_net_service_name IN VARCHAR2,
pi_user_name IN VARCHAR2,
pi_user_password IN VARCHAR2,
pi_search_base IN VARCHAR2
return VARCHAR2
is -- PUBLIC procedure
v_url VARCHAR2(256);
begin
g_err_source := 'NET_SERVICES.test_db_connection_via_ldap';
g_err_action := 'build_jdbc_conn_url_using_oid';
/* NOTE: We don't want to assert the parameters because we don't want to raise
an exception;
-- Get the jdbc connection url that uses oid info
v_url := build_jdbc_conn_url_using_oid( pi_net_service_name, pi_search_base );
return( do_test_db_connection_via_ldap( v_url, pi_user_name, pi_user_password ) );
end test_db_connection_via_ldap;
-- ========================================================================================
Thanks in advance for your consideration.
TroyTroy:
You could be right in your guess that the error is related to MTS. Search Metalink for '16371'. Why not switch your APEX app to use OHS and test whether the error persists. ?
varad -
Without calling stored procedure or functions from database
Hi,
I am using Jdeveloper 11.1.1.5.0.
=>How to do PL/SQL procedures and functions in ADF without calling stored procedure or function from DB?S, PL/SQL procedures and functions are done in Application Module class or in managed bean..By calling the stored procedures or functions from DB.
But I am asking how to do if DB doesn't have any procedures,triggers and functions. -
Found a bug in "Execute Stored Procedure..." command
Hi...I've found one interesting "feature": if I do click "Execute Stored Procedure"on SP, which contains an XML parameter (doesn't matter if it's input or output), Management Studio generates script without declaring datatype of that
parameter. But if I click "Generate Script" everything works fine. This situation can be observed in SQL Server 2005-2012.Hello,
Please submit a product feedback on Microsoft Connect:
https://connect.microsoft.com/sqlServer/
Thank you for sharing what you have discovered.
Regards,
Alberto Morillo
SQLCoffee.com -
Create stored procedure or function of pl/sql in jdeveloper
How can we create a stored procedure or function of pl/sql in jdeveloper 11.1.2.1.0? And how it will be called? Please help me?
Edited by: mrs on 4 Jul, 2012 3:07 AMI am a beginner to jdeveloper and adf so please give a step by step method for how to create a stored procedure of pl/sql in jdeveloper 11.1.2.1.0
-
Problem in executing Stored Procedure from Trigger
Hi,
Case1.
I am executing a stored procedure form a trigger. The stored procedure is not executing fully.
Case 2.
But when when I execute Stored Procedure alone it is executing.
CREATE OR REPLACE TRIGGER mhubadmin.call_proc_ratesheet_new
after INSERT OR delete ON mhubadmin.pvt_br_ratesheet
FOR EACH ROW
declare
var_orgid number;
begin
if inserting then
select org_child_id into var_orgid from business_relationship where br_id=:new.br_id;
mhubadmin.proc_ratesheet_new(var_orgid);
else
select org_child_id into var_orgid from business_relationship where br_id=:old.br_id;
mhubadmin.proc_ratesheet_new(var_orgid);
end if;
end;
CREATE OR REPLACE PROCEDURE proc_ratesheet_new(var_orgid in number)
IS
cursor c3 is select distinct(purs.user_id) from hubuser hu
inner join PVT_USER_RATESHEET purs on hu.USER_ID=purs.USER_ID
where hu.ORG_ID=var_orgid;
cursor c1(varUser_id number) is select purs.user_id,purs.ratesheet_id from hubuser hu
inner join PVT_USER_RATESHEET purs on hu.USER_ID=purs.USER_ID
where hu.ORG_ID=var_orgid and purs.USER_ID=varUser_id;
cursor c2(varUser_id number) is select hu.user_id,pbr.ratesheet_id from HUBUSER hu
inner join BUSINESS_RELATIONSHIP br on hu.ORG_ID=br.ORG_CHILD_ID
inner join PVT_BR_RATESHEET pbr on br.BR_ID=pbr.BR_ID
where hu.user_id in(select distinct(purs.USER_ID) from hubuser hu
inner join PVT_USER_RATESHEET purs
on hu.USER_ID=purs.USER_ID
where hu.ORG_ID=var_orgid) and hu.user_id=varUser_id;
foundFlag boolean;
incrFound integer;
insertFound integer;
deleteFound integer;
str varchar2(4000);
BEGIN
incrFound:=0;
insertFound:=0;
for c3var in c3 loop
for c2var in c2(c3var.user_id) loop
insert into test values ('Step3:'||c2var.user_id);
foundFlag:=false;
for c1var in c1(c3var.user_id) loop
if c2var.ratesheet_id=c1var.ratesheet_id then
foundFlag:=true;
incrFound:=incrFound+1;
exit;
end if;
end loop;
if foundFlag=False then
--insert into pvt_user_ratesheet (username_ratesheet_id,user_id,ratesheet_id) values (SEQ_USER_RATESHEET.nextval,c3var.user_id,c2var.ratesheet_id);
dbms_output.put_line('Inserted for user :'||c3var.user_id||' is - ratesheet :'||c2var.ratesheet_id);
insertFound:=insertFound+1;
end if;
end loop;
end loop;
commit;
incrFound:=0;
deleteFound:=0;
for c3var in c3 loop
for c1var in c1(c3var.user_id) loop
foundFlag:=false;
for c2var in c2(c3var.user_id) loop
if c1var.ratesheet_id=c2var.ratesheet_id then
foundFlag:=true;
incrFound:=incrFound+1;
exit;
end if;
end loop;
if foundFlag=False then
--delete from pvt_user_ratesheet where user_id=c3var.user_id and ratesheet_id=c1var.ratesheet_id;
--dbms_output.put_line('Deleted for userid:'||c3var.user_id||' for ratesheet :'||c1var.ratesheet_id);
deleteFound:=deleteFound+1;
end if;
end loop;
end loop;
commit;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line (SQLCODE||' '|| SQLERRM);
END;
Regards,
MathewIn general, I would suggest that you only catch errors that you can handle reasonably. If you know that a SELECT INTO might return 0 rows for example, handle the NO_DATA_FOUND exception. Having a WHEN OTHERS, particularly without re-raising the exception, only serves to hide the source of the problem. I would much rather that my code fail quickly and explicitly than hope that I see an error message in the output and that other code doesn't start failing because the system wasn't left in an appropriate state.
As Mark suggests, you may choose to implement a comprehensive logging framework using autonomous transactions, in which case a WHEN OTHERS would be reasonable, but you would still want to propagate exceptions you cannot handle.
If you see a WHEN OTHERS clause and there is no RAISE, you probably have an error waiting to happen.
Justin -
Execute stored procedure as sysadmin
Hi,
I am running powershell script to execute stored procedure on SQL server. Powershell script is run with low privilege user account on SQL server, but SP is restoring databases and requires sysadmin permissions. How can I execute SP with sysadmin permissions?
Could this be done proxy account? without additional users creation. Any links? ThanksYou can create the sp using a sysadmin account (or in dbo schema) and use EXECUTE AS OWNER inside it
Then give the powershell account execute access to the procedure and it will run under context of dbo user (or owner account) which will have necessary permission to do the data base restore etc
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Could not execute stored procedure in oracle
hello experts,
Problem: I can not execute stored procedures stored in Oracle data base. Error Message: Portal request failed. Could not execute stored procedure.
My steps:
i connected my locally installed Oracle data base to the VC. I mapped the data base user to my VC user. I tested connection and it is fine. Further I see the db alias in Visual Composer and i can drop stored procedures to my story board. I can define parameters, but when I am executing procedures I get the error message.
Further I installed MS SQL Server lokally and connected to the VC and it is working fine. I can do everything.
Why it is not working for Oracle DB?
DriverName: com.sap.portals.jdbc.oracle.OracleDriver
Connect-URL: jdbc:sap:oracle://ip:port;sid=XE
Any comment is highly appreciated.
anton.Hi,
Also you can follow this link which explains you the procedure to configure BI JDBC system for visual composer.
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/6209b52e-0401-0010-6a9f-d40ec3a09424
Regards
Inder
Do reward points if helpful. -
Stored procedure and function - return table type
Hello again :)
I have one simple question :) Maybe on this forum the question was asked, but I found only similar question and they didn't help me.
It's possible return in Stored Function (with StoredProcedureFunction) as result return TABLE type? Or return table type with output parametr with Stored Procedure? Or instead of the table return the db object, but it is similar problem:)
Now, I can using db types TABLES or DB OBJECTS as INPUT parameters with call stored functions or procedures, for example:
I have this simple db object:
create or replace type BUFFER_DATA_R as object( detail VARCHAR2(4000 ))
And this simple table:
CREATE OR REPLACE TYPE BUFFER_DATA_T IS TABLE OF BUFFER_DATA_R
I create simple domain class object:
*public class DMBufferDataStruct {*
public String bufferData;
And I mapped in java with ObjectRelationalDataTypeDescriptor:
ObjectRelationalDataTypeDescriptor descriptor = new ObjectRelationalDataTypeDescriptor();
descriptor.setJavaClass(DMBufferDataStruct.class);
descriptor.setTableName("BUFFER_DATA_T");
descriptor.setStructureName("BUFFER_DATA_R");
descriptor.setPrimaryKeyFieldName("DETAIL");
descriptor.addFieldOrdering("DETAIL");
descriptor.addDirectMapping("bufferData", "DETAIL");
and join to server session ...
Well, i using this doimain class object as input parametr wih stored procedure call:
ObjectRelationalDatabaseField ordf = new ObjectRelationalDatabaseField("");
ordf.setSqlType(Types.STRUCT);
spCall.addNamedArgument(key, key,
Types.ARRAY,
"BUFFER_DATA_T",
ordf);
query.addArgument(key);
args.add(paramsInputs.get(key));
in paramsInputs is Vector of DMBufferDataStruct...
Well, this work fine!
But I can not figure, how to return this table from output parameters of stored procedure or as a return value from stored function?
Example of exceptions:
The number of arguments provided to the query for execution does not match the number of arguments in the query definition. - return as output parameter
PLS-00382: expression is of wrong type - used as result from stored function
So, my question is: Is possible return this table type from stored procedure or function? And if YES, how can I set output argument for call?
Thx advance!
Sorry for my English! :)
Best regards, KLDYour question is: what is faster PL/SQL or PL/SQL? And the answer is: it is PL/SQL of course!
As a general rule, you use a function when you return exactly one result: a number or a string or (more complex) instance of an object type or REF CURSOR or PL/SQL collection.
You use a procedure when:
a) you just do the job and return no result
b) you return multiple results - you can use multiple IN/OUT or OUT parameters
Imagine you have to write a program unit that performs a partitioned table maintenance by adding a partition.
You can implement this unit:
a) if you want return a "status code" (0 on successful completion or non-zero in case of error) then you should use a function
b) if you want no "status code" (in case of error an exception is raised that is handled outside of the program unit) then you should use a procedure
c) if you want "status code", name of tablespace where a partition was created (assume you program is so complex that it can choose different tablespaces based on metadata and free space available) and free space in that tablespace after the creation of a new partition then you should use a procedure with 3 OUT parameters.
But these are good programming practices that can be applied to (almost) any 3rd generation programming language, not only PL/SQL. -
How can I get a list of values (one or more) used in the WHERE filter of stored procedures and functions in SQL Server?
How can get a list of values as shown (highlighted) in the sample stored procedure below?
ALTER PROC [dbo].[sp_LoanInfo_Data_Extract] AS
SELECT [LOAN_ACCT].PROD_DT,
[LOAN_ACCT].ACCT_NBR,
[LOAN_NOTE2].OFCR_CD,
[LOAN_NOTE1].CURR_PRIN_BAL_AMT,
[LOAN_NOTE2].BR_NBR,
INTO #Table1
FROM
dbo.[LOAN_NOTE1],
dbo.[LOAN_NOTE2],
dbo.[LOAN_ACCT]
WHERE
[LOAN_ACCT].PROD_DT = [LOAN_NOTE1].PROD_DT
and
[LOAN_ACCT].ACCT_NBR = [LOAN_NOTE1].ACCT_NBR
and
[LOAN_NOTE1].PROD_DT = [LOAN_NOTE2].PROD_DT
and
[LOAN_NOTE1].MSTR_ACCT_NBR = [LOAN_NOTE2].MSTR_ACCT_NBR
and
[LOAN_ACCT].PROD_DT = '2015-03-10'
and
[LOAN_ACCT].ACCT_STAT_CD IN
('A','D')
and
[LOAN_NOTE2].LOAN_STAT_CD IN
('J','Z')
LenfinkelHi LenFinkel,
May I know what is purpose of this requirement, as olaf said,you may parse the T-SQL code (or the execution plan), which is not that easy.
I have noticed that the condition values in your Stored Procedure(SP) are hard coded and among them there is a date values, I believe some day you may have to alter the SP when the date expires. So why not declare 3 parameters of the SP instead hard coding?
For multiple values paramter you can use a
table-valued parameter. Then there's no problem getting the values.
If you could elaborate your purpose, we may help to find better workaround.
Eric Zhang
TechNet Community Support -
Entity Framework - Execute Stored Procedures
I want to execute stored procedure using entity framework.
I am using entity framework 6.
The stored procedure has SELECT and RETURN statement.
How can I read the output from SELECT and RETURN statements using
dbContext.Database.ExecuteSqlCommand or dbContext.Database.SqlQuery statement ?Hello Sumit Kadam,
>> The stored procedure has SELECT and RETURN statement.
For the select statement, Entity Framework would support natively:
http://www.entityframeworktutorial.net/stored-procedure-in-entity-framework.aspx
For the return statement, we could use the dbContext.Database.SqlQuery statement as below to fetch the value:
var returnCode = new SqlParameter();
returnCode.ParameterName = "@ReturnCode";
returnCode.SqlDbType = SqlDbType.Int;
returnCode.Direction = ParameterDirection.Output;
// assign the return code to the new output parameter and pass it to the sp
var data = db.Database.SqlQuery<Order>("exec @ReturnCode = ProGetOrder", returnCode);
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.
Maybe you are looking for
-
How to add a field for multiple file upload in WebApps ?
I am creating a WebApp for user to save some information with multiple pitcures. I can only see a single uploader. How can I add multiple image uploader and How can I create a custom file upload field rather than image upload ?
-
S_ALR_87012085 out Put modification
Hai , There is a standard report S_ALR_87012085 which is used to generate the vendor Aging Analysis , I need to change the out put format without using an enchacement I am not aware exactly about imlicit and explicit enchancement if any body
-
Hi, I have created a Form with a Tab containing few fields and two Buttons(AddTab, Delete Tab), 1) My problem is when ever i click on 'Add Tab' button, a new tab should get added to the existing tabs with the same fields as main tab. 2) When ever i c
-
Hi, I'm getting the below error while starting my application. It was running for long time & while bouncing today, it throws the below error 2012-10-19 09:09:01,616 ERROR net.sf.ehcache.store.DiskStore - com.hbo.cs.soap.xmaster.model.SomTypeCache: F
-
Can't open the application "EPSON Scan.app"
I have an iMac running OS X Mavericks 10.9.1, connected by USB wire to an Epson WF-3540 All-in-One. Under Mountain Lion, all of the Epson's functions worked by clicking on the Epson icon. Subsequent to the Mavericks update, the Epson programs, parti