Using &variable in stored procedure
Is there any way to use &variable or something like this in stored procedure.
I need procedure that is stored, called from SQLPlus and can read-get values through typical keyboard input.
Like this?
SQL> create or replace procedure getEmp (pEmpNo integer, pOutout out sys_refcursor)
2 as
3 begin
4 open pOutout for select * from emp where empno = pEmpNo;
5 end;
6 /
Procedure created.
SQL> var rc refcursor
SQL> exec getEmp(&empNo, :rc)
Enter value for empno: 1
PL/SQL procedure successfully completed.
SQL> print rc
EMPNO Employee Name JOB MGR HIREDATE SAL COM DEPTNO
1 SHYAM MANAGER 02-APR-13 12975 0 50
SQL>
Similar Messages
-
Pass BPC SSIS variable to stored procedure
Dear All
We have a ssis package in which there is data flow task. There
is a OLEDB source which uses “Data access mode” as sql command. We used OLEDB data source instead of execute sql task as the outuput is table format generated in Stored proc which is used in following task
This task calls a stored procedure with a input parameter which will be appset name. [EXEC ProcName '@BPCAPPSET']
The stored procedure is executing fine without any issues.But when I pass variable containing appset name to that stored procedure its not taking properly and package ending successful.
The variable is “BPCAPPSET” it contains appset name which
will be taken front end.
However to test if this value is taken by stored procedure
or not, I tried to hardcode and pass appset name to stored procedure. i.e exec
ProcName Appset1.
Appset1 is existing appset. It worked fine. But we want to
put this package in all land scapes, such that whenever it is triggered it will
take the appset as parameter and does the calculation in stored procedure.
Please advice how to pass this variable to stored
procedure.
regards
PrasadHi Roberto
Thanks for your mail.
I have tried, but I am getting error that @BPCAPPSET scalar
variable must be defined.
I believe that @BPCAPPSET is system defined variable which
will be passed from Data manager package. May be this is the reason it is not
recognizing this variable?
If so, should I define a variable in SSIS. How can we
assign value of @BPCAPPSET to the newly defined variable?
Please advise. Attached screenshot. -
BIND VARIABLES IN STORED PROCEDURES
I find out that the cause of the decreasing of the Shared_pool in my database is for the sql area.
1* SELECT * FROM V$SGASTAT where name like 'sql%'
SQL> /
POOL NAME BYTES
shared pool sql area 7671024
SQL> R
1* SELECT * FROM V$SGASTAT where name like 'sql%'
POOL NAME BYTES
shared pool sql area 8147424
SQL> R
1* SELECT * FROM V$SGASTAT where name like 'sql%'
POOL NAME BYTES
shared pool sql area 8262016
I flush the shared pool and it increases fastly.
According to my research I have to use bind variables in SQL Statement to avoid this and apart from that modify the init parameter CURSOR_SHARING.
Somebody can help me with a simple example about how to use bind variables in Stored Procedures.
thanksAccording to my research I have to use bind variables in SQL Statement to avoid this and apart from that modify the init parameter CURSOR_SHARING.I would not want to change the CURSOR_SHARING. As for use of bind variables in PL/SQL stored procedures, they come in naturally if you use pl/sql variables in your queries:
l_empno EMP.EMPNO%TYPE ;
SELECT <columns> INTO <local storage>
FROM emp
WHERE
empno = l_empno ; /* pl/sql automatically binds for you here */
.Please post a small sample of type of queries that you are submitting to the database from within these pl/sql blocks for us to see if there is a possibility of improvements. -
Subreport using the same Stored Procedure
I have a main report and a subreport that uses the same stored procedure. The stored procedure has 12 parameters and what I want to avoid is the user having to enter the same parameter values twice. When I created the subreport I put in the parameters + one field, the employee id field so that I could just test it on one employee.
After I entered the subreport into the main report, when I got to refresh the data, it's asking for params for BOTH reports. Is there any way to get around this? Because of the way the stored procedure returns the data, I had to create a subreport instead of just fitting it into one of the footers. I've looked at the subreport link and added the employee id as the key. When I ran it the first time, it returned the wrong date range on the sub.
Help! this thing is Way passed due!!Right click on the sub report and choose change sub report links
Top left pane contains your main report parameters use > to add
In the bottom left corner of that dialog then scroll down until you see the corresponding sub report parameter
Repeat for each parameter
This should then take the main report params and pass into the sub report -
How to find the columns and tables used in a stored procedure?
Hi,
Can someone suggest how to find the columns and tables used within a stored procedure?
Thanks
VBKFor example:
SQL> create or replace
2 procedure p1
3 is
4 cnt number;
5 begin
6 select count(*) into cnt from emp;
7 end;
8 /
Procedure created.
SQL> select referenced_owner,
2 referenced_name
3 from dba_dependencies
4 where owner = 'SCOTT'
5 and name = 'P1'
6 and referenced_type = 'TABLE'
7 /
REFERENCED_OWNER REFERENCED_NAME
SCOTT EMP
SQL> SY. -
Find all tables used in a stored procedure
Hi,
I have a requirement where i have to find all the tables used in a stored procedures from different databases.
Ex: i have a stored procedure where i use few tables from MASTER database and some from STAGE database.When i have written a query to find all tables used in the stored procedure, i am getting only those database table where i run the query and procedure
exists.
I have stored procedure SP1 in Master database, but i use the tables from both master and stage.
When i run this, i am getting the tables only from Master database but not from stage. i hope my requirement is clear.
I am trying to find all the tables from all databases used by a stored proc.
;WITH stored_procedures AS (
SELECT
o.name AS proc_name, oo.name AS table_name,
ROW_NUMBER() OVER(partition by o.name,oo.name ORDER BY o.name,oo.name) AS row
FROM sysdepends d
INNER JOIN sysobjects o ON o.id=d.id
INNER JOIN sysobjects oo ON oo.id=d.depid
WHERE o.xtype = 'P')
SELECT proc_name, table_name FROM stored_procedures
WHERE row = 1
ORDER BY proc_name
Please adviceYour question is not entirely clear. You need to run the query on different databases.
You may find this blog post helpful
How to get information about all databases without a loop
Check the last script in that blog post and modify to your particular purpose.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
Database updation using XML and stored Procedure?
Hello,
I want to perform updation in multiple tables using XML files.Please suggest can I do updation using xml and stored procedure.
If yes then which is more efficient and takes less time.
1.Updation using xml files only
2.Updation using xml files with stored procedure.
3.Stored procedure alone.
If direct xml and stored procedure communication is possible.then please write how.
Thanks in advance for any help.Here's a sample. The next code drop of the XSQL Servlet will make the easy-to-do from within XSQL Pages:
package package1;
import org.w3c.dom.*;
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.xml.sql.query.OracleXMLQuery;
public class Class1 extends Object {
public static void main( String[] arg ) throws Exception {
Connection conn = getConnection();
CallableStatement ocs = conn.prepareCall("begin ? := App.HotItems('PAUL'); end;");
ocs.registerOutParameter(1,OracleTypes.CURSOR);
ocs.execute();
ResultSet rs = ((OracleCallableStatement)ocs).getCursor(1);
OracleXMLQuery oxq = new OracleXMLQuery(conn,rs);
System.out.println(oxq.getXMLString());
oxq.close();
rs.close();
ocs.close();
conn.close();
public static Connection getConnection() throws Exception {
String username = "scott";
String password = "tiger";
String dburl = "jdbc:oracle:thin:@localhost:1521:xml";
String driverClass = "oracle.jdbc.driver.OracleDriver";
Driver d = (Driver)Class.forName(driverClass).newInstance();
return DriverManager.getConnection(dburl,username,password);
null -
Creating XML report using PL/SQL Stored Procedure
Hi Friends,
I am working on an xml report with the xml source as PL/SQL Stored Procedure.
I am referring the exercise shown in the following link to understand the process:
http://orclapp.blogspot.com/2012/02/developing-xml-publisher-report-using.html
In the example shown in the above link I could not understand the following:
1) In the following procedure, the out parameter 'retcode' is not used at all.
What is the importance of this parameter.
PROCEDURE REPORT (errbuf OUT VARCHAR2, retcode OUT VARCHAR2, p_product_id IN NUMBER)
2) After the xml data is prepared and put to 'l_result' Clob variable, the following
Loop is executed. I am not able to appreciate why the following loop is required.
LOOP
EXIT WHEN l_length = l_retrieved;
IF (l_length - l_retrieved) < 32000
THEN
SELECT SUBSTR (l_result, l_retrieved + 1) INTO l_xmlstr FROM DUAL;
l_retrieved := l_length;
fnd_file.put_line (fnd_file.output, l_xmlstr);
ELSE
SELECT SUBSTR (l_result, l_retrieved + 1, l_offset)
INTO l_xmlstr
FROM DUAL;
l_retrieved := l_retrieved + l_offset;
fnd_file.put_line (fnd_file.output, l_xmlstr);
END IF;
END LOOP;
3) In the example it is not explained how the concurrent program gets the xml data?
I assume it is written to a file using the following line of code:
fnd_file.put_line (fnd_file.output, l_xmlstr);
I would appreciate if anyone can throw some light into my above queries so that I can understand the process clearly.
Thanks & Regards
HawkerHi 32000 in the code is a 'safe' size smaller than the max available 32767, the loops purpose is to move through the entire thing in chunks that will be manageable in the limits of the data type.
Btw; if you are in Oracle e-business suite then you can also use Oracle reports very simply to create XML output.
If you have reports developer all you need to do is put raw sql (without any 'artifice' to create XML) in the report SQL and then set the reports output to XML in the program definition in Oracle e-business.
best regards,
Robert. -
How to use &APP_ID. inside stored procedure.
Hello, I have created one stored procedure. I am calling it from my process code. I want to use so many page variables like &APP_ID. I do not want to pass it as argument. Is it possible to use those variables without passing it in to procedure.? (&page_id. and also some application level variables )
Any help is appreciated.
Thank you.Ashif:
The APEX documentation describes in detail the various ways of referencing APEX session state.
http://download.oracle.com/docs/cd/E10513_01/doc/appdev.310/e10499/concept.htm#BEICHBBG
Local variables declared in your process block are not available in APEX' session state. Hence you cannot refence such variables in a stored procedure.
Varad -
Substitution variables in stored procedures
Help, anybody! I want to create a procedure that updates a column of a table, however I want that column and the new data specified at run time. I've tried writing a procedure that has substitution variables for the column and new_data values:
CREATE OR REPLACE PROCEDURE update_client(v_account_id IN VARCHAR2)
IS
v_column varchar2(50);
v_new_data varchar2(50);
last_name varchar2(20);
BEGIN
v_column:=&v_column;
if v_column=last_name then
UPDATE Client set last_name='&v_new_data' where account_id=v_account_id;
end if;
end;
but that's not working, and I also tried to pass v_column and v_new_data as parameters but that won't work either.
CREATE OR REPLACE PROCEDURE update_client (v_account_id IN VARCHAR2, v_column IN VARCHAR2, v_new_data IN VARCHAR2) AS
BEGIN
UPDATE client set v_column=v_new_data where v_account_id=account_id;
END;
I get the error: unable to resolve "V_COLUMN" as a column
Is there anyway at all to do this via a stored procedure? I'm all out of ideas.
ThanksIn Oracle8i you can use dinamic nebeded SQL. In previous versions you need DBMS_SQL.
Regards
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Lori Fortner ([email protected]):
Help, anybody! I want to create a procedure that updates a column of a table, however I want that column and the new data specified at run time. I've tried writing a procedure that has substitution variables for the column and new_data values:
CREATE OR REPLACE PROCEDURE update_client(v_account_id IN VARCHAR2)
IS
v_column varchar2(50);
v_new_data varchar2(50);
last_name varchar2(20);
BEGIN
v_column:=&v_column;
if v_column=last_name then
UPDATE Client set last_name='&v_new_data' where account_id=v_account_id;
end if;
end;
but that's not working, and I also tried to pass v_column and v_new_data as parameters but that won't work either.
CREATE OR REPLACE PROCEDURE update_client (v_account_id IN VARCHAR2, v_column IN VARCHAR2, v_new_data IN VARCHAR2) AS
BEGIN
UPDATE client set v_column=v_new_data where v_account_id=account_id;
END;
I get the error: unable to resolve "V_COLUMN" as a column
Is there anyway at all to do this via a stored procedure? I'm all out of ideas.
Thanks<HR></BLOCKQUOTE>
null -
User-defined datatypes as IN variables in stored procedures
Hello,
I'm trying to write a stored procedure which will accept a custom data type as an IN variable. Using the information here: http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/05_colls.htm I've set up a procedure which looks like this:
CREATE OR REPLACE PROCEDURE EDEPOSIT.merch_acct_proc_method_insert
arg_ALL_PROC_METHODS IN proc_array
IS
TYPE proc_array IS TABLE OF VARCHAR2 INDEX BY VARCHAR2;
BEGIN
arg_METHOD := arg_ALL_PROC_METHODS.first;
while (arg_METHOD is not null)
loop
--processing code
end loop;
END;
but I'm running into a problem where it seems that the data type needs to be defined before the parameters block (Error(3,27): PLS-00201: identifier 'PROC_ARRAY' must be declared), but a DECLARE block won't co-exist with the CREATE OR REPLACE command (PLS-00103: Encountered the symbol "CREATE" when expecting one of the following: begin function pragma procedure subtype type <an identifier>).
What am I missing?
Thanks in advance!Hi,
Welcome to the forum!
877369 wrote:
... CREATE OR REPLACE PROCEDURE EDEPOSIT.merch_acct_proc_method_insert
arg_ALL_PROC_METHODS IN proc_array
IS
TYPE proc_array IS TABLE OF VARCHAR2 INDEX BY VARCHAR2;
BEGIN
arg_METHOD := arg_ALL_PROC_METHODS.first;
while (arg_METHOD is not null)
loop
--processing code
end loop;
END;
but I'm running into a problem where it seems that the data type needs to be defined before the parameters block (Error(3,27): PLS-00201: identifier 'PROC_ARRAY' must be declared), but a DECLARE block won't co-exist with the CREATE OR REPLACE command (PLS-00103: Encountered the symbol "CREATE" when expecting one of the following: begin function pragma procedure subtype type <an identifier>).I'm not sure what you mean by "parameters block".
Whoever is going to call the procedure will have to create a proc_array first. If proc_array is defined inside the procedure, then it can't be referenced from outside the procedure.
A common way to define types is to do so in a package. Procedures normally belong to pacages anyway. You can define a TYPE and a procedure that uses it in the same package, like this:
CREATE OR REPLACE PACKAGE merch_acct_pkg
AS
TYPE proc_array IS TABLE OF VARCHAR2 (30) INDEX BY VARCHAR2 (30);
PROCEDURE merch_acct_proc_method_insert
arg_ALL_PROC_METHODS IN proc_array
END merch_acct_pkg;
SHOW ERRORS
CREATE OR REPLACE PACKAGE BODY merch_acct_pkg
AS
PROCEDURE merch_acct_proc_method_insert
arg_ALL_PROC_METHODS IN proc_array
IS
BEGIN
arg_METHOD := arg_ALL_PROC_METHODS.first;
while (arg_METHOD is not null)
loop
--processing code
end loop;
dbms_output.put_line ('Hello');
END merch_acct_proc_method_insert;
END merch_acct_pkg;
SHOW ERRORSYou can call the procedure like this:DECLARE
foo merch_acct_pkg.proc_array;
BEGIN
merch_acct_pkg.merch_acct_proc_method_insert (foo);
END;
/ -
SQL environment variable into a local variable in stored procedure ?
How do i set a SQL environment variable in a session ? How can i read an SQL environment variable into a local variable declared in my stored procedure ? Does any exceptions occur in the process ?
I need this very urgently, can anyone help ?
thanks
sriniYou can use a pipelined table function to return it, which is covered here:
http://blog.mclaughlinsoftware.com/plsql-programming/pipelined-functions-plsql-tables/
Alternatively, you can use a SQL Object type wrapped by a collection of that SQL object type inside a TABLE call. I've blogged on that too, here:
http://blog.mclaughlinsoftware.com/2009/03/23/object-record-collections/
If you need something more, leave a comment on the blog. I'm not here on the forum too frequently. Hope that helped. -
Use of a stored procedure in a select statement submitted to cx_oracle
Hi,
I am developping under python and I'm using the cx_oracle interface.
I've written a stored procedure that I've tested directly under sqlplus session : it's ok. I've also tested this stored procedure from python by using callproc routine : its also ok.
Now I need to use this procedure within a select statement that I submit to the execute statement of cx_oracle as :
s = "select a.airport_name,gmlpos.ExpLatLong(a.point_name) from airport"
self.db = oracledb('ops/opeope00@ACE2008B')
dbmsg = self.db.execute(s)
IF (dbmsg == "") :
An error occurs :
Message = request = select a.AIRPORT_NAME, gmlpos.ExpLatLong(a.point_name) from airport, errmsg = ORA-00904: "GMLPOS"."EXPLATLONG": invalid identifier
Noting that the execution of any other select (without stored procedure) order from python works fine.
Is anybody has a solution or workaround ?
thanks a lot for your helpThe result gives what is expected :
AIRP
GMLPOS.EXPLATLONG(A.POINT_NAME)
LFLL
-45.71666666666667 -5.08333333333333
As I said the stored procedure works fine.
Thanks for your expertise
PS : why change the login password until nobody says which machine or database is concerned ? -
Call Data in Variable in Stored Procedure for Partition Name
Hi,
Here is an excerpt from a Srored Proc I have written.
The aim here is to copy data from a partition of a table.
I first query the partition-name from the ALL_TAB_PARTITIONS table and store the same in a VARCHAR2 variable named partition_name_low.
I then try to select the data in this partition of the table by using the variable name.
PROCEDURE purging AS
partition_name_low VARCHAR2(25);
BEGIN
--+
-- Query for the Highest Value of the timestamp in the 1st partition in current table.
--+
SELECT PARTITION_NAME
INTO partition_name_low
FROM ALL_TAB_PARTITIONS
WHERE TABLE_NAME = 'TABLE1' AND PARTITION_POSITION IN
+(+
SELECT MIN(PARTITION_POSITION)
FROM ALL_TAB_PARTITIONS
WHERE TABLE_NAME = 'TABLE1'
+);+
COMMIT;
COMMIT;
DBMS_OUTPUT.PUT_LINE(partition_name_low ||' ********** ' || TO_char(sysdate, 'MM/DD/YYYY HH24:MI:SS')||' Starting Purging Data *********');
--+
-- Copy data from 1st partition to Archive Table
--+
INSERT /* APPEND */ INTO TABLE1_ARCHIVE+
SELECT * FROM TABLE1 PARTITION(partition_name_low);
However, I am facing an issue here since I keep on gettin an error that "ORA-02149: Specified Partition does not exist".
What I understand is that the Oracle query is picking up the literal string "partition_name_low", instead of the data inside it.
I tried with
&partition_name_low
AND
:partition_name_low
with no luck.
For the 2nd case I get the obvious exception "bad bind variable".
Can someone please suggest in which way I can handle this situation where I can use a variable refer the partition name in a select query?
Thanks in advance!!
Abhishek.Hi,
You have to use "execute immediate" to launch dynamic SQL command.
So you should write
execute immediate 'INSERT /* APPEND */ INTO TABLE1_ARCHIVE+
SELECT * FROM TABLE1 PARTITION('||partition_name_low||')' ;
Mike -
Different session used when calling stored procedure from form
after commiting data in a form to a table, a stored procedure is called that inserts the data written to the table into several other tables. Some columns in the original table are updated - no commit is issued in the procedure. On returning from the procedure the form is re-queried but the updated columns don't contain the updates. This seems to imply that the stored procedure is running as a different session to the one of the form.
Is this the case? Can we make the form and the stored procedure use the same session so that the data is available in both without having to commit in the procedure?No. They should be within one session unless you explicitly open a new session.
The reason why you dont see updates of the data block when you requery is probably the changes on the form never go to the back end. I think first you have to make sure data changes go to db table. You can do a commit_form before calling the stored procedure and open up another session (e.g. sqlplus) to check the data in the table changed or not.
Maybe you are looking for
-
VPN Problems ASA 5505 to 7206 Router MM_WAIT_MSG2
Hi Since I swapped a Pix Firewall for a Cisco ASA 5505 Firewall at one of our Sites the VPN Tunnel wont come up I'm getting this: asaXXXXX# sho crypto isakmp sa Active SA: 1 Rekey SA: 0 (A tunnel will report 1 Active and 1 Rekey SA during reke
-
Adobe premiere elements 12- can't find download
Hello, I purchased a new laptop, and am looking for the Adobe Premiere elements 12 download. My CD does not seem to work, and the website keeps pointing me to download the new adobe premiere elements version 13. please help.
-
Problem in Webservice-XI-JDBC scenario
Hi Experts, I am working on webservice - XI - JDBC Synchronous scenario. I have done with SLD, IR, ID, WSDL file creation. When I tried to test the scenario thro' Webservice Studio, I am getting the following error. This error comes, once I give the
-
Copying from Sapscript to Smart form with d same windows
I hav created my sapsccript till now i want to copy my sapscript windows n text elements n other attributes of that sapscript to smart forms.So please help me to copy sapscript to smart form,Please help me out. Thanks & regards santhosh kumar.
-
Wps HP printer to air port extreme for imac and mac air
Just purchased a HP C310c p/c/s/p/web . it has wps protection. air port extreme has wpa. how do i proceed?