Calling a remote procedure with db link - SQL Plus hangs
I am trying to call a procedure from a remote database with a db link, within a local procedure. The purpose of the calling the procedure is to get the server time from that database. When I try to compile this procedure on the local database SQL Plus hangs without giving any error message, I have to close SQL Plus. Below are my two procedures:
Local procedure:
CREATE OR REPLACE PROCEDURE get_server_time(p_remotetime IN OUT VARCHAR2)
IS
/*Grabs the system time from remote database .
l_remotetime varchar2(16) ;
BEGIN
get_remote_time(l_remotetime);
p_remotetime := l_remotetime;
END ;
Remote procedure:
CREATE OR REPLACE PROCEDURE get_remote_time(p_remotetime in out VARCHAR2)
IS
/* Grabs the system time from remote database and returns it to the
calling proc.
l_remotetime varchar2(16) ;
BEGIN
SELECT to_char(sysdate,'YYYYMMDDHH24MISS')
INTO l_remotetime
FROM dual ;
p_remotetime := l_remotetime ;
END ;
I personaly do not see anything unusall with the two procedures, but cant figure out what is making SQL*Plus hang.
Any help would be much appreciated.
Thanks In Advance
Hello
Are you able to run the procedure connected to the livetolocal database directly? It looks as if you either have a missing table or the permisions for the user associated with the database link are not sufficient.
As for calling the procedure, it would probably be more managable if you created a public synonym for it to hide the actual location. That way if you want to change the name of the DB link, or where it points to, no-one has to change their code, you just have to change the synonym.
HTH
David
Similar Messages
-
How do you run procedure with declare on sql plus
Hi i am a newbie in sqlplus so please forgive if my question sounds to0 silly as i was watching a tutorial on sqlplus procedures i know how to run a simple IN procedure like
create or replace procedure inparameter
p_name IN VARCHAR2
)AS
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello' || p_name);
end;
to run
start inparameter;
procedure created
set serveroutput on;
exec inparameter ('newbie');
hello newbie
procedure successfuly completed
but now i have a procedure with a declare
now wich from what i see on the video tutorial as two box to create procedure and on the next the declare i dont know if i am meant to put them together and run it as one this how it looks like
DO I RUN THE FIRST BOX AS MY PREVIOUS PROCEDURE DESCRIBED ABOVE (start procedure, then exec procedure)
then run the second box which is the declare as the same way or do i put the all code in one single box (start declare then exec declare)
BOX 1
Create or replace procedure addition
P_A IN NUMBER
,P_B IN NUMBER
,P_C OUT NUMBER
)AS
BEGIN
P_C := P_A +P_B;
END ADDITION
BOX 2
declare
x number;
addition (5,5,x);
dbms_output.put_line('the result is' || x);
end;
the tutorial can be seen on this youtube link
[http://www.youtube.com/watch?v=Vvn30o_ctpk&feature=related]
fastforward to about 9mins 18 to see the boxes that i mean
sorry in advance if its a stupid questionYou have to create the first procedure (addition), then run the pl/sql block:
SQL> Create or replace procedure addition
2 (
3 P_A IN NUMBER
4 ,P_B IN NUMBER
5 ,P_C OUT NUMBER
6 )AS
7 BEGIN
8 P_C := P_A +P_B;
9 END ADDITION;
10 /
Procedure created.
SQL> declare
2 x number;
3 begin
4 addition (5,5,x);
5 dbms_output.put_line('the result is' || x);
6 end;
7 /
the result is10
PL/SQL procedure successfully completed.The procedure is stored in the database, the pl/sql block is anonymous, it's not stored in the db.
Max -
T-sql 2008 r2 place results from calling a stored procedure with parameters into a temp table
I would like to know if the following sql can be used to obtain specific columns from calling a stored procedure with parameters:
/* Create TempTable */
CREATE TABLE #tempTable
(MyDate SMALLDATETIME,
IntValue INT)
GO
/* Run SP and Insert Value in TempTable */
INSERT INTO #tempTable
(MyDate,
IntValue)
EXEC TestSP @parm1, @parm2
If the above does not work or there is a better way to accomplish this goal, please let me know how to change the sql?declare @result varchar(100), @dSQL nvarchar(MAX)
set @dSQL = 'exec @res = TestSP '''+@parm1+''','' '''+@parm2+' '' '
print @dSQL
EXECUTE sp_executesql @dSQL, N'@res varchar(100) OUTPUT', @res = @result OUTPUT
select @result
A complicated way of saying
EXEC @ret = TestSP @parm1, @parm2
SELECT @ret
And not only compliacated, it introduces a window for SQL injection.
Erland Sommarskog, SQL Server MVP, [email protected] -
Calling Hana Store Procedure thorugh Eclipse link
Hi,
Anybody having idea of calling HANA store procedure through Eclipse Link JPA.
Procedure has Scalar IN Parameter and Table Type as OUT Param:
CREATE PROCEDURE tree_view (IN topicid BIGINT,OUT qtree tt_tree)
LANGUAGE SQLSCRIPT
READS SQL DATA AS
BEGIN
/// SQL Statements
END;
Currently i an calling the procedure as
entiyManager.getTransaction().begin();
java.sql.Connection connection = entiyManager.unwrap(java.sql.Connection.class);
connection.setAutoCommit(false);
CallableStatement cst = connection.prepareCall("call _SYS_BIC.\"workspace.procedures/tree_view\"(?,?)");
cst.setLong(1, identifier);
cst.execute();
ResultSet rs = cst.getResultSet();
entiyManager.getTransaction().commit();
But need more cleaned way like using StoreProcedureQuery or PLSQLStoredProcedureCall.Slightly missed the point.
The question was about providing an INPUT variable.
An in fact it is not possible to call a procedure with an table type input variable from the SQL console.
You have to build a wrapper to call such a procedure:
create type myusers as table (user_name nvarchar(60));
create procedure count_users (IN user_tab myusers, OUT user_count bigint )
language sqlscript
as
begin
select count(*) into user_count from :user_tab;
end;
call count_users (? , ?)
Could not execute 'call count_users (? , ?)' .
SAP DBTech JDBC: [7]: feature not supported:
Parameterized input table parameter is not allowed: line 1 col 19 (at pos 18)
A wrapper for this could look like this:
create procedure call_cu (out user_count bigint)
language sqlscript
as
begin
v_users = select user_name from users;
call count_users (:v_users, :user_count);
end;
call call_cu (?)
--> 28
Unlike SQL*Plus for PL/SQL, the SQL console of SAP HANA is not a SQL Script runtime shell.
- Lars -
Getting error while Calling Oracle Stored Procedure with output Parameter
HI All,
From long days i am working on this but i unable to solve it.
Even i have studied so many forums in SAP but i didn't find the solution.
I am calling Oracle Store procedure with 3 inputs and 1 output without cursor.
Store Procedure:-
CREATE OR REPLACE PROCEDURE PDS.send_rm
IS
proc_name VARCHAR2(64) := 'send_rm';
destination_system VARCHAR2(32) := 'RAWMAT';
xml_message VARCHAR2(4000);
status_code INTEGER;
status_message VARCHAR2(128);
debug_message VARCHAR2(128);
p_ret INTEGER;
BEGIN
DBMS_OUTPUT.PUT_LINE( proc_name || ' started' );
xml_message := '<RAW_MATERIAL>'||
'<BAR_CODE>10000764601</BAR_CODE>'||
'<MATERIAL>1101448</MATERIAL>'||
'<VENDOR_CODE/>'||
'<PRODUCTION_DATE>0000-00-00</PRODUCTION_DATE>'||
'<EXPIRE_DATE>0000-00-00</EXPIRE_DATE>'||
'<BATCH/>'||
'<PO_NUM/>'||
'<MATERIAL_DESCRIPTION>POWER SUPPLY</MATERIAL_DESCRIPTION>'||
'<SPEC_NAME/>'||
'<STOCK_CODE>BSW-JH</STOCK_CODE>'||
'<INSPECTION_LOT>00</INSPECTION_LOT>'||
'<USAGE_DECISION_CODE/>'||
'<MATERIAL_GROUP>031</MATERIAL_GROUP>'||
'</RAW_MATERIAL>';
dbms_output.put_line('XML '||xml_message);
-- vp_interface.load_rawmat@cnprpt1_pds(SYSDATE, destination_system,
-- xml_message, p_ret);
vp_interface.load_rawmat(SYSDATE, destination_system,
xml_message, p_ret);
dbms_output.put_line('Return Code '||p_ret);
COMMIT;
EXCEPTION
WHEN OTHERS THEN
status_code := SQLCODE;
status_message := SUBSTR(SQLERRM, 1, 64);
-- Extract_Error_Logger(proc_name, 'LOCAL', SYSDATE, -999,
-- status_message, 0, debug_message);
ROLLBACK;
END send_rm;
And while i am calling this Store procedure in MII, I am facing error.
I have tried different ways but didnt solved
In SQL Query, i kept mode as: FixedQueryOutput
Can anyone tell me or send code for calling above store procedure
And onemore thing, While creating store procedure in Oracle for MII. Do we need to Create output parameter as cursor or normal.
Thanks,
Kind Regards,
Praveen Reddy MHi Praveen
Our wrapper was created because we could not modify the procedure we call (it was not returning a cursor).
CREATE OR REPLACE PROCEDURE CHECK_PUT_IN_USE
(STRCMPNAME in varchar2,
STRSCANLABEL in varchar2,
RCT1 out SYS_REFCURSOR
AS
charDispo Char(1);
charStatus Char(1);
intCatNo Integer;
charCatDispo Char(1);
strCatQual VarChar2(2);
strCatDesc VarChar2(30);
strMsg VarChar2(128);
BEGIN
qa.check_put_in_use@AR(STRCMPNAME,
STRSCANLABEL,
charDispo,
charStatus,
intCatNo,
charCatDispo,
strCatQual,
strCatDesc,
strMsg);
OPEN RCT1
FOR Select charDispo,charStatus,charDispo,charStatus,intCatNo,charCatDispo,strCatQual,strCatDesc,strMsg from Dual;
END;
Hope this helps
Regards
Amrik
then with a FixedQueryWithOutput
call mixar.qasap.wrapper_update_put_in_use('[Param.1]','[Param.2]',[Param.3],?)
Hope this helps. -
Calling a package procedure with Date parameter only
Hi All,
Please help me to call a package procedure with Date parameter from sql prompt.
ArifCheck the below procedure.
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure procdate (p_date_in date)
2 is
3 p_date_out date;
4 begin
5 p_date_out := add_months(p_date_in,6);
6 dbms_output.put_line(p_date_out);
7* end;
SQL> /
Procedure created.
SQL> exec procdate('01-JAN-2010');
01-JUL-10
PL/SQL procedure successfully completed.
SQL> exec procdate(to_date('01/01/2010','DD-MM-YYYY'));
01-JUL-10
PL/SQL procedure successfully completed.
SQL> exec procdate('31-DEC-2010');
30-JUN-11
PL/SQL procedure successfully completed. -
How to call a Store Procedure with IN PARAMETER
Hi, im new using Oracle 10G with Oracle SQL Developer, my cuestion is how to call a Store Procedure with IN PARAMETER, I tried the following without results
SELECT * FROM procedure_name(parameter);
PROCEDURE procedure_name(parameter);
EXEC procedure_name(parameter);
CALL procedure_name(parameter);
Please help me....Hi,
As Beijing said,
EXEC procedure_name(parameter);
CALL procedure_name(parameter);work for me.
So does
BEGIN
procedure_name(parameter);
END;Can you be more specific about what you're doing? That is, are you testing it in SQL Developer? Where are you entering the commands? Where are you looking for output? Do you get error messages? Does anything else (like "SELECT SYSDATE FROM dual;") work? -
ORA-06553: PLS-908 when calling 10g remote procedure from 11g database
Hi,
I have 2 instances: 11g (11.1.0.7) and 10g (10.2.0.4). When I try to call 10g (remote) procedure from 11g database, there is errors:
ORA-04052: error occurred when looking up remote object CUSTOMER.PRL_PK2_GENERAL@CUSTOMER_LINK
ORA-06541: PL/SQL: compilation error - compilation aborted
ORA-06553: PLS-908: The stored format ofCUSTOMER.PRL_PK2_GENERAL@CUSTOMER_LINK is not supported...
But, if I call the same procedure from another 10g instance, it's OK.
How can I fix the problem?
Thx,
qtphamAs you can see ,it seems like the workaround that was mentioned there is currently the only way to remove this ORA.
Workaround: Remove the function call(s) from the called subroutine's
package's spec. -
Calling a stored procedure with a CLOB as input parameter
Hello,
I was unsuccessfully trying to call a stored procedure with a clob as input parameter from my C++ application using occi.
Anyone got a working example to look at?
I already checked the thread Invalid OCI handle when creating a Blob which didn't help.
The problem seems to be that I don't have a lob locator to write my data (xml file) to. I tried creating a temporary clob using the sys.dbms_lob package which only resulted in a major headache on my part...
I would appreciate any help.
Kind regards
Horst
my environment:
Visual Studio 2008, C++ application
Oracle 11gTo start using a blob you have to insert it into the database and then get it back. Sounds weird but that is how it is. Here is a very simple program to do this:
#include<occi.h>
#include <iostream>
using namespace oracle::occi;
using namespace std;
int main()
try
Environment *env = Environment::createEnvironment(Environment::OBJECT);
Connection *conn = env->createConnection("hr","hr","");
string stmt1 = "insert into blob_tab values (:1) ";
string stmt2 = "select col1 from blob_tab";
Blob blob(conn);
blob.setEmpty(conn);
Statement *stmtObj = conn->createStatement(stmt1);
stmtObj->setBlob(1,blob);
stmtObj->executeUpdate();
conn->commit();
Blob blob1(conn);
Statement *stmtObj2 = conn->createStatement(stmt2);
ResultSet *rs = stmtObj2->executeQuery();
while(rs->next())
blob1 = rs->getBlob(1);
string stmt3 = "begin my_proc(:1) ;end;";
Statement *stmtObj3 = conn->createStatement(stmt3);
stmtObj3->setBlob(1,blob1);
stmtObj3->executeUpdate();
catch (SQLException e)
cout << e.getMessage();
/* The tables and procedure are primitive but ok for demo
create table blob_tab(col1 blob);
create or replace procedure my_proc(arg in blob)
as
begin
-- just a putline here. you can do other more meaningful operations with the blob here
dbms_output.put_line('hello');
end;
}Hope this helps.
Thanks,
Sumit -
Calling a Stored Procedure with output parameters from Query Templates
This is same problem which Shalaka Khandekar logged earlier. This new thread gives the complete description about our problem. Please go through this problem and suggest us a feasible solution.
We encountered a problem while calling a stored procedure from MII Query Template as follows-
1. Stored Procedure is defined in a package. Procedure takes the below inputs and outputs.
a) Input1 - CLOB
b) Input2 - CLOB
c) Input3 - CLOB
d) Output1 - CLOB
e) Output2 - CLOB
f) Output3 - Varchar2
2. There are two ways to get the output back.
a) Using a Stored Procedure by declaring necessary OUT parameters.
b) Using a Function which returns a single value.
3. Consider we are using method 2-a. To call a Stored Procedure with OUT parameters from the Query Template we need to declare variables of
corresponding types and pass them to the Stored Procedure along with the necessary input parameters.
4. This method is not a solution to get output because we cannot declare variables of some type(CLOB, Varchar2) in Query Template.
5. Even though we are successful (step 4) in declaring the OUT variables in Query Template and passed it successfully to the procedure, but our procedure contains outputs which are of type CLOB. It means we are going to get data which is more than VARCHAR2 length which query template cannot return(Limit is 32767
characters)
6. So the method 2-a is ruled out.
7. Now consider method 2-b. Function returns only one value, but we have 3 different OUT values. Assume that we have appended them using a separator. This value is going to be more than 32767 characters which is again a problem with the query template(refer to point 5). So option 2-b is also ruled out.
Apart from above mentioned methods there is a work around. It is to create a temporary table in the database with above 3 OUT parameters along with a session specific column. We insert the output which we got from the procedure to the temporary table and use it further. As soon the usage of the data is completed we delete the current session specific data. So indirectly we call the table as a Session Table. This solution increases unnecessary load on the database.
Thanks in Advance.
RajeshRajesh,
please check if this following proposal could serve you.
Define the Query with mode FixedQueryWithOutput. In the package define a ref cursor as IN OUT parameter. To get your 3 values back, open the cursor in your procedure like "Select val1, val2, val3 from dual". Then the values should get into your query.
Here is an example how this could be defined.
Package:
type return_cur IS ref CURSOR;
Procedure:
PROCEDURE myProc(myReturnCur IN OUT return_cur) ...
OPEN myReturnCur FOR SELECT val1, val2, val3 FROM dual;
Query:
DECLARE
MYRETURNCUR myPackage.return_cur;
BEGIN
myPackage.myProc(
MYRETURNCUR => ?
END;
Good luck.
Michael -
Calling a stored procedure with RAW and SYS_REFCURSOR
How do you call a stored procedure with the following input and output parameters?
create or replace PROCEDURE test
v_col1 IN NUMBER DEFAULT NULL ,
v_col2 IN VARCHAR2 DEFAULT NULL ,
v_col3 IN RAW DEFAULT NULL ,
v_vol4 IN DATE DEFAULT NULL,
cv_1 IN OUT SYS_REFCURSOR
OPEN cv_1 FOR
SELECT
lv_tmp1 aaaa ,
lv_tmp2 bbbb,
lv_tmp3 cccc
FROM DUAL ;
END;
Edited by: 925963 on Apr 6, 2012 10:50 AMDid you try just declaring the vars?
untested
declare
myCur SYS_REFCURSOR;
myRaw RAW(4);
BEGIN
test (0, 0, myRaw, sysdate, myCur);
END; -
SQL*Plus hangs when connecting to remote DB (Solaris, 10gR2)
First of all the particulars:
Local System:
Solaris 8, Oracle 10.2.0.4, October CPU
Remote System:
Solaris 10, Oracle 10.2.0.4, July CPU
We are trying to initiate a connection from our local system to our remote system using a DB Link. After opening SQL*Plus, we log in with <user>@<dblink>, are asked for a password, and after entering the password, SQL Plus hangs indefinitely (we typically have to kill the sqlplus process to regain our session). Also, logging into the local system with a local account, and then querying using the db link (select * from dual@<link>) gives the same result.
From the remote system, we CAN log into the local system using the same process, and we can also query the local system. in other words, it works in one direction, but not the other.
We have checked all the usual suspects: tnsnames, sqlnet, db_domain, global_names, and all are set correct for our setup (although I of course welcome suggestions to check something else in the files). Also have confirmed validity of /etc/hosts entries, and permissions on those files for the 'oracle' user. A 'tnsping' and 'ping' are both successful in both directions, though I understand these only check the listener and hardware layer.
Our Sys Admin has checked firewall connections between the two systems, and stated that they're open on the listener port (1521).
Listener log files on the remote host, when the hang happens, show an established connection from the local host.
Does anyone have any suggestions as to what to check for next?
Thank you in advance for the assist!Whew, that truss output is enough to make your eyes bleed!
This system is on a closed network, so I cannot post the files here, nor would I wish reading those things on anyone nice enough to spend a minute here helping me out!@
But comparing the truss from the "broken" system, and the working one, the sqlplus that hangs returns a:
ERR #134 ENOTCONN on a getpeernam() thread.
The other truss (working side), does not throw that particular line, and the truss output varies widely after that line in the output fille.
After a few moments letting the sqlplus process "hang", I get:
ERR #62 ETIME
Outside of that, lust a lot of hex values! -
SQL*PLUS Hangs when I have the Listener running?
HI,
I have Oracle 8i Personal Edition running on Win 98. I am using the default starter database (Global Name: oracle, SID orcl).
If I connect via SQL*Plus with the listener running i.e. connect scott/tiger@oracle, and then try to compile or call a stored produre SQL*Plus hangs. If I connect without the listener running i.e. connect scott/tiger everything works fine.
Does anyone have any ideas why this is happening?
Thanks in advance
Marktry posting your code here, that way we might be able to help you more.
-
Calling remote procedure through database link
Hi,
I have a procedure in a package with a type I delcared as follows:
Database1 :
create or replace package p1
is
TYPE dependents_rec IS RECORD (
name VARCHAR2 (80),
dob date);
TYPE dependents IS TABLE OF dependents_rec
INDEX BY BINARY_INTEGER;
procedure proc1 (p_id in number,
p_dependents out dependents );
end;
On another database database2 i want to call the above procedure from within a procedure in a package that works as a wrapper package with similar structure.
I recieve the error "Wrong number or types of parameters" error because type dependents is not the same as within the package in database 1.
How can I call the procedure p1.proc1 over a database link ?
Thank youHi,
On database1:
CREATE OR REPLACE PACKAGE types_pkg is
TYPE dependents_rec IS RECORD (
NAME VARCHAR2 (80),
sex NUMBER (1),
birth_date DATE,
birth_place NUMBER (3),
status NUMBER (1),
unique_id VARCHAR2 (15)
TYPE dependents IS TABLE OF dependents_rec
INDEX BY BINARY_INTEGER;
end;
CREATE OR REPLACE PACKAGE wrapper_pkg_demo
AS
PROCEDURE read_person_no (
p_person_id NUMBER,
p_dependent_info OUT types_pkg.dependents
END;
CREATE OR REPLACE PACKAGE BODY wrapper_pkg_demo
AS
PROCEDURE read_person_no (
p_person_id NUMBER,
p_dependent_info OUT types_pkg.dependents
IS
BEGIN
person_pkg.read_person_no (p_person_id, p_dependent_info);
END;
END;
On database 2:
CREATE OR REPLACE PACKAGE person_pkg
AS
PROCEDURE read_person_no (
p_person_id NUMBER,
p_dependent_info OUT types_pkg.dependents@database1
END;
CREATE OR REPLACE PACKAGE body person_pkg
AS
PROCEDURE read_person_no (
p_person_id NUMBER,
p_dependent_info OUT types_pkg..dependents@database1
IS
BEGIN
null;
END;
END;
When compiling the package body on database 1
ORA-04052: error occurred when looking up remote object TYPES@MOI
ORA-00604: error occurred at recursive SQL level 1
ORA-02019: connection description for remote database not found
Noting that the database link are working properly and when compiling the package on database 2, it compile successfully
Thank you -
Calling Stored Procedure with TestStand to SQL 2000
When I run the Stored Procedure in the query analyzer it returns the recordset fine. I am not specifying any parameters. I am Using TestStand 2.01 and SQL Server 2000. I am using the OPEN SQL STATEMENT step to call the SP. When I run the SP in TestStand I get no data returned. If I run the SQL statment in TestStand I get the data that I am requesting. Does TestStand not support stored procedures.
Hi,
The instructions that I posted were for TestStand 3.0. In version 3.0 you can call stored procedures with input/output paramateres and to support this functionality the data operation step support several new modes.
TestStand 2.0.1 does not support parameters on stored procedures, but it does support calling stored procedures that do not take parameters. To be able to access the data back from the database you need to set the cursor location (in the Advanced tab of the Open SQL Statement step) to Client (http://digital.ni.com/public.nsf/websearch/0EF68BF97AB1A61F86256B8E007D70C0?OpenDocument).
By changing the cursor to Client I was able to succesfully call a stored procedure from TestStand 2.0.1 and to read back the recordse
t return by the database. Please let me know if you are still experiencing dificulties.
Best regards,
Alejandro del Castillo
National Instruments
Maybe you are looking for
-
How to read data in CATS DB?
Hello Experts, We are maintaing our time data in a thrid party system. And it is transfered to CATS DB. From there it is tranferred to IT 2001, IT 2002 and IT 2010. Now we have an issue, the data that is maintained in 3rd Party system is correct, but
-
Acrobat PDF plugin does not appear in Word 2013
After I installed Acrobat XI Pro, I do not see the Acrobat tab in the Word 2013 ribbon bar. If I use Word 2010, I do see the Acrobat tab. Is this a bug in Acrobat XI Pro that will be fixed for Word/Office 2013?
-
In Design Data merge into separate pdf files with variable data name
Hi all, thank you for taking the time to read this. Here's what I have. I've created a file in indesign using a 65 page document. With this document I've set it up to have specific data in certain areas with data merge. I have that part setup and it
-
Duplicate Document Numbering after Upgrade
Hi! Can anyone please help me to find-out a resolution for the Duplicate Document Numbering found after the SAP B1 upgrade from 2007 to 8.8? This report has been found from the Administration -> Utilities.
-
PCP - How to simulate upcoming months payroll data
Hi, I'm try to get plan personnel cost for the year 2008 using the payroll data of 2007. We only have the Jan-Jul 2007 payroll data in the system. I used the program RPCIPE00 with "Cost planning data" checked and "Name of payroll program" as "HTRCALC