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.
Thanks
In 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
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. -
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> -
Variables in stored procedures
Please help me I am trying to get some coding standards set up in the shop that I work in for the DBA group. The problem is that they feel that it is not important to put a prefix or a suffix to variable in a stored procedure.
What is important to me is having either a prefix or a suffix for variables that are passed in, out, and ones that are local to the stored procedure.
They do not feel it will be beneficial and want me to prove the importance. How I would like to prove this is by having as many people reply to this post as possible.
Please let me know what you think. The more replies I get the better the case that I can make to the other people in the group.
Thank you,I support you, Mr.().It is very important to have a well defined convention, if you want to escape from all those abuses while modifying the script.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Marco ([email protected]):
Hello unknown person,
The importance of a prefix (or a suffix) in my opinion is that you van tell by the name of the variable its type and origin (parameter, global, local etc) without the need to search for its definition. I find this usefull when you must change code that somebody else wrote cetainly if you work in an object oriented environment.<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;
/ -
Pass PL/SQL Record variable to Stored procedure in Java
Can some one please give me a code snippet for passing a Record Type variable returned by Stored Procedure. Following is the scenario.
A record type variable REC_VAR is made of three columns of a table as follows
EmpNo Number, Empname Varchar2(50), Zip_Code Varchar2(5).
I am populating this variable in Java code and passing it to Stored Procedure.
Can I referance Record Type variable in a Oracle package from Java code.
How would I define these variables as per tables column type and pass to SP in a java program.
Thanks,58838,
The following entry -- from the Ask Tom Web site may be helpful (assuming you haven't already seen it):
how to access variable
If it doesn't help, you can always search the site.
Good Luck,
Avi. -
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. -
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 -
Consider the following DDL:
CREATE OR REPLACE insert_requirement
requirement_name VARCHAR2
AS
INSERT INTO requirements (requirement_name) VALUES(requirement_name)
In SQL Server (TSQL), variable names had a @ prefix. In oracle, is there a prefix? In the above statement, will the value in the insert value list come from the variable or column?better if you post these type of threads in sql, pl/sql sub-functions.
-
Where does substitution variable meta data stored?
where does substitution variable meta data stored in the essbase folder?<BR>Thanks<BR>Arun
I believe substitution variables are stored in the Essbase.sec (Security file).
-
Hi,
I have a query like this,
select email as vEmail from users where id in (217211,217521,217641)
Now this query returns 3 email id's. I have to loop through the vEmail and assign them to different local variables in stored procedures.
like email for 217211 is stored in vEmail1
217521 in vEmail2
217641 in vEmail3
Can somehow help me in this looping?Hi,
Do you really need them in 3 separate variables, like vemail1, vemail2 and vemail3?
Would you be just as happy if they were in 3 separate members of a collection: vemail(1), vemal(2) and vemail(3)? If so, use BULK COLLECT. It will be a lot more efficient (though, if you're only fetching 3 rows, that won't amount to much).
The PL/SQL manual has a nice example:
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/tuning.htm#sthref1474 -
Get variable values from a stored procedure
I am using SQL 2008R2 and I want to replace a view inside a stored procedure with a new stored procedure to return multiple variable values. Currently I am using the code below to get values for 4 different variables. I would rather get the 4 variables
from a stored procedure (which returns all of these 4 values and more) but not sure how to do so. Below is the code for getting the 4 variable values in my current sp.
DECLARE @TotalCarb real;
DECLARE @TotalPro real;
DECLARE @TotalFat real;
DECLARE @TotalLiquid real;
SELECT @TotalCarb = ISNULL(TotCarb,0),
@TotalPro = ISNULL(TotPro,0),
@TotalFat = ISNULL(TotFat,0),
@TotalLiquid = ISNULL(TotLiq,0)
FROM dbo.vw_ActualFoodTotals
WHERE (MealID = @MealID);You can replace the view with inline table valued user-defined function:
http://www.sqlusa.com/bestpractices/training/scripts/userdefinedfunction/
See example: SQL create INLINE table-valued function like a parametrized view
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
Printing OUT variables from a Stored Procedure
Hi all,
I'm running an SQL command that calls a Stored Procedure and passes in some value. I've pasted in the important parts of it below. What I am trying to do is access the OUT variables that have been assigned to the DECLARED variables. I come from a SQL Server background and there we can do "SELECT @variable" which will print it to screen. I'm trying to do something similar here.
I need to access the contents of the three variables declared at the top of the script.
Thanks in advance.
DECLARE
l_error_value NUMBER;
l_error_product VARCHAR2 (10);
l_CE_DOC_ID number;
BEGIN
PEM.create_enquiry
( ce_cat => 'COMP'
, ce_class => 'FRML'
, error_value => l_ERROR_VALUE
,error_product => l_ERROR_PRODUCT
, ce_doc_id => l_ce_doc_id
END;Ah yes I see. Sorry I misunderstood what you were suggesting. I'm currently working on a test script that uses an approach similar to the one you mentioned, but I'm having trouble resolving foreign key relationships with test data.
I've no access to the tables or anything so it's proving to be a time consuming task!!
Is it required that all fields are given a value, even if they have a "DEFAULT" defined for them within the procedure. At the moment I'm using a rather cumbersome approach to this:
i.e.
With cmmAddRequest
.ActiveConnection = strConnect
.CommandType = adCmdText
.CommandText = strSQL
.Parameters(0).Direction = adParamInput
.Parameters(1).Direction = adParamInput
.Parameters(2).Direction = adParamInput
.Parameters(3).Direction = adParamOutput
.Parameters(4).Direction = adParamOutput
.Parameters(5).Direction = adParamOutput
.Parameters(0).Value = "COMP"
.Parameters(1).Value = "FRML"
.Parameters(2).Value = "1"
.Execute
WScript.Echo(.Parameters(5).Value)
End With -
URGENT: I want to pass a variable to a stored procedure at run time
Post Author: aruplabs
CA Forum: Data Connectivity and SQL
I work for a health care provider and I have reports that pull PHI (Protected Health Information) about patients that needs to be logged according to federal HIPAA regulations. One of the pieces of information that needs to be logged is the username of the person who ran the report. Since these reports will be run from our Crystal Enterprise server I can get this from the CurrentCEUserName variable but I am looking for a way to pass this value to a stored procedure that will not only return the records for the report, but also log the disclosure in our PHI disclosure tracking table. I know you can pass a parameter to a stored procedure but I dont know how, or if it is even possible, to pass a run time variable. This is an urgent problem that I need to find a solution for. Any help would be appreciated.
Thank you.Here it is. Right now, when i press te "Go" it runs for the specific time i've set and when its done the variable "Run" is set true. When i call this VI from another VI it waits for the loop to be finished before it will read the variable.
Regards
Viktor
Attachments:
Untitled 2.vi 26 KB
Maybe you are looking for
-
Hello experts, Is there anyway I can get filename and populate in the payload so I can see it as an additional tag in SXMB_MONI? This is from sender file adapter that I want to capture file name. If possible, I would also like to populate interface n
-
Mac Mini repeatedly refuses to wake from sleep
Please to anyone I really need your help. First let me preface you that I know my console log is incredibly long, and let me know if there is a way to make them more manageable and I will update. Also let me know which other logs or screen shots or a
-
Conflicts with ATI Radeon 5770?
Hello, I am using a Mac Pro 3.1, 2x2.8 quad core Xeon, with OSX 10.6.7. I recently upgraded to a ATI Radeon HD 5770 in slot 1 and put my original ATI Radeon 2660XT in Slot 4 to run an older DVI monitor. It ran ok for a while, but my computer starti
-
Thanks in advance. I have been reading various posts about this topic and thought I would ask again to see what works best. I work in animation and in the Avid, use Locators to put at the head of the scenes to identify all the shots. Then when I want
-
How to design FXML for all screen resolution
hello I am designing a page in FXML using scene builder,and I want that my fxml runs good on few screen resolutions,for that there is need for relative positioning but in FXML there is nothing like % and all. Please do any one have worked on this the