Use the bind variable in example of a clause giving questions
create or replace procedure pr_mbk (p_val in number)is
CROR type is ref cursor;
REF CROR;
type numbertype is the table of index number of pls_integer;
numtype numbertype.
v_str varchar2 (2000): = 'select empno from emp sample(:val) ";
Start
Open ref for v_str using p_val;
Close ref;
end;
/
Successfully compiled.
But when I run the same
Exec pr_mbk (10);
ERROR on line 1:
ORA-00933: SQL not correctly completed command.
ORA-06512: at "SCOTT. PR_MBK', line 9
ORA-06512: at line 1
My question is can use us Bind variables within a sample clause.
Receive your answer.
Thank you
Madhu K.
I guess that SAMPLE is considered as a special case, and is not considered as something that takes a 'value' in the same way as values in where clause or values in the query itself.
Let's face it, the SAMPLE is not the standard SQL syntax and is probably something Oracle implements in a separate thread for processing SQL itself i.e. engine Oracle saying to herself... "I will remember this bit of the sample until I questioned the data using the SQL engine, so I'll take a suitable sample of the results," but it's the SQL engine treats the binding of values and the Oracle process that awaits the results taste, knows nothing of the binding values in it's special EXAMPLE of keyword.
Tags: Database
Similar Questions
-
Variable adjustment of linking VO using the session variable
Hello
I need get/set variable binding VO using the class ApplicationModuleImple or ViewObjectImple. Does anyone know how to do?
I have a VO based on the query like "select name from users where password =: password". " I had a variable binding him also. now I want to put it to a session scope variable. I can do using ADFContext.getCurrent () .getSession ().get('username');? but somehow, I am not able to obtain the knowledge that is to say where to put the variable binding. Help, please.User, please tell us your version of jdve!
You write a public method in your VO, who has the number of parameters you need (username and password), set the variables in this method binding by using the bind variable setters, expose the method in the interface of the client of the vo. So you see the method in the control of data when you open the VO drag. the method on a page and drop it to count. Then you have the input fields to bind variables and the Send button to execute the method in the VO.
Timo
-
The use of bind variables (in &; out) with sql dynamic
I have a table that contains code snippets to make postings on a set of pl/sql database. what the code does is basically receives an ID and returns a number of errors found.
To run the code, I use dynamic sql with two bind variables.
When codes consists of a simpel query, it works like a charm, for example with this code:
However when I get to post more complexes that must perform calculations or run several queries I run into trouble.BEGIN SELECT COUNT (1) INTO :1 FROM articles atl WHERE ATL.CSE_ID = :2 AND cgp_id IS NULL; END;
I have boiled down the problem into that:
This code is not really make sense, but it's just to show you what is the problem. When I run this code, I get the errorDECLARE counter NUMBER; my_id NUMBER := 61; BEGIN EXECUTE IMMEDIATE (' declare some_var number; begin select 1 into some_var from dual where :2 = 61; :1 := :2; end; ') USING OUT counter, IN my_id; DBMS_OUTPUT.put_line (counter || '-' || my_id); END;
ORA-6537 ON bind variable linked to a position IN
The error doesn't seem wise,: 2 is the only one IN bind variable and it is only used in a where clause clause.
As soon as I remove this where clause, the code works again (giving me 61-61, in case you want to know).
Any idea what goes wrong? I just use bind variables in a way that you're not supposed to use it?
I'm using Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bitCorrection. With immediate execution , the binding is in position, but binds do not need to be repeated. My statement above is incorrect...
You must link only once - but bind by position. And the connection must correspond to the use of the variable binding.
If the connection never variable assigns a value in the code, link by in.
If the binding variable assigns a value in the code, link as OUTPUT.
If the binding variable assigns a value and is used a variable in another statement in the code, link as IN OUT.
For example
SQL> create or replace procedure FooProc is 2 cnt number; 3 id number := 61; 4 begin 5 execute immediate 6 'declare 7 n number; 8 begin 9 select 10 1 into n 11 from dual 12 where :var1 = 61; --// var1 is used as IN 13 14 :var2 := n * :var1; --// var2 is used as OUT and var1 as IN 15 :var2 := -1 * :var2; --// var2 is used as OUT and IN 16 end; 17 ' 18 using 19 in out id, in out cnt; --// must reflect usage above 20 21 DBMS_OUTPUT.put_line ( 'cnt='||cnt || ' id=' || id); 22 end; 23 / Procedure created. SQL> SQL> exec FooProc cnt=-61 id=61 PL/SQL procedure successfully completed. SQL>
-
Ensure this soft analysis the use of Bind variables
Hi Experts,
I have a request when the query is prepared dynamically in Java code and if I take the query and run it from SQL Navigator, it takes a long time to prepare the statement and then execute it quickly. I think we can use dynamic SQL statements and bind variable to improve performance here. However, I tried to do a PDS to check my understanding. I created 2 procedures
1. mode of operation
2. mode of operationCREATE OR REPLACE PROCEDURE sp_static (id IN NUMBER, name in VARCHAR2) IS TYPE r_curs_type is REF CURSOR; C1 r_curs_type; BEGIN OPEN C1 FOR SELECT * FROM TABLE WHERE columname = id CLOSE C1; END;
To my amazement, there is no difference in the duration of execution of these procedures when I ran the with multiple entries.CREATE PROCEDURE sp_dyanmic (id IN NUMBER, name in VARCHAR2) IS TYPE r_curs_type is REF CURSOR; C1 r_curs_type; BEGIN OPEN C1 FOR 'SELECT * FROM TABLE WHERE columnanme = :U1' USING ID; CLOSE C1; END;
Please note-
1. I have not access to trace files :-(
2. I want to just make sure there will be improved performance before starting the real work, given that some efforts provided by moving the logic of all its activities inside and the use of bind variables.
If you can suggest a strategy to ensure performance gains, it will be extremely useful...
Thanks in advance!
ConcerningHello
(1) it's true, procedure 1 also uses a variable binding
(2) you seem to be confused about the very basic concepts hereDynamic SQL is something like this:
create or replace FUNCTION f (l_table_name VARCHAR2) RETURN NUMBER IS l_result NUMBER; BEGIN EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ' || l_table_name INTO l_result; return l_result; END;
In this example, since you do not know the name of the table to the execution table, everything you can
is dynamic SQL. As you can see, neither of your two procedures is like that.Dynamic SQL is used when you do not know what columns you want to select, or who
etc. to the execution table. You can also use dynamic SQL statements to force analysis. You can not use
to avoid parsing, binding or not binding.Best regards
Nikolai -
Get the bind variables name string SQL or the cursor
Hello
Is there way to get of the bind variables name string SQL or the cursor?
Example of
What I mean with the SQL string:DECLARE l_sql VARCHAR2(2000); desctab DBMS_SQL.DESC_TAB; curid PLS_INTEGER; BEGIN l_sql := 'SELECT * FROM emp WHERE mgr = :X and deptno = :Y'; curid := dbms_sql.open_cursor; dbms_sql.parse(curid, l_sql, dbms_sql.NATIVE); .... END;
I love to get using some functions from above code variable l_sql all the bind variable.
In this case the function should return array where is for example: X and: Y
Back to bind the cursor variable names, I mean same but rather string I pass number of cursor.
Y at - it sucks ready function or some may share a code customized for this purpose?
Thanks
Kind regards
Jari
http://dbswh.webhop.NET/dbswh/f?p=blog:Home:0Regards,
Published by: jarola December 19, 2011 02:44
I found there are wwv_flow_utilities.get_binds of the function not documented in APEX packages that do what I want.
Usage example
But I would not use these functions without papers as those who can change or there is no future versions APEX.set serveroutput on DECLARE binds DBMS_SQL.varchar2_table; BEGIN binds := wwv_flow_utilities.get_binds('select :P1_TEST from dual'); FOR i IN 1 .. binds.count LOOP dbms_output.put_line(binds(i)); END LOOP; END; / anonymous block completed :P1_TEST
Is there a documented function or the custom function that do the same thing as wwv_flow_utilities.get_binds?Some old basic example code of my friends. Also the media getting the bind variable of PL/SQL code blocks anon.
SQL> create or replace function GetBindVariables( statement varchar2 ) return TStrings is 2 --// bind variables names are terminated by one the following special chars 3 SPECIAL_CHAR constant TStrings := TStrings(' ',')','+','-','>','<','*',',','=',';',CHR(10),CHR(13)); 4 5 --// max size of a bind var name 6 MAX_VARSIZE constant integer := 100; 7 8 pos integer; 9 pos1 integer; 10 occur integer; 11 varName varchar2(100); 12 varList TStrings; 13 begin 14 varList := new TStrings(); 15 16 --// looking for the 1st occurance of a bind variable 17 occur := 1; 18 19 loop 20 pos := InStr( statement, ':', 1, occur ); 21 exit when pos = 0; 22 23 varName := SubStr( statement, pos, 100 ); 24 25 --// find the terminating char trailing the 26 --// bind variable name 27 pos1 := Length( varName ); 28 for i in 1..SPECIAL_CHAR.Count 29 loop 30 pos := InStr( varName, SPECIAL_CHAR(i) ) - 1; 31 if (pos > 0) and (pos < pos1) then 32 pos1 := pos; 33 end if; 34 end loop; 35 36 --// extract the actual bind var name (without 37 --// colon char prefix) 38 varName := SubStr( varName, 2, pos1-1 ); 39 40 --// maintain a unique list of var names 41 if not varName member of varList then 42 varList.Extend(1); 43 varList( varList.Count ) := varName; 44 end if; 45 46 --// look for the next occurance 47 occur := occur + 1; 48 end loop; 49 50 return( varList ); 51 end; 52 / Function created. SQL> SQL> select 2 column_value as BIND_VAR 3 from TABLE( 4 GetBindVariables('select * from foo where col=:BIND1 and day = to_date(:B2,''yyyy/mm/dd'')') 5 ); BIND_VAR ------------------------------ BIND1 B2 SQL>
PS. just realize this code is case-sensitive, while variable bind is not. Should throw a upper() or lower() by adding the name of the var to the list - never really a problem for me because I'm pretty tense when it use cases correctly in the code. ;-)
Published by: Billy Verreynne, December 19, 2011 06:19
-
How to use the global variable in the table target?
Hello
I am trying to load several files into a single interface. the data is loaded successfully. 92. the files are there. for this I used variables and package.
My requrement is 92 files of data loaded into the target table. I want to know what data from file.
to this I added a column (filename) to the existing target table.
If I used joints (not same condition), its totally wrong. all file names are coming.
Please see the following screenshots.
exit; target table.
in fact in the target table. first 10 lines are coming from file.i.e first _ACCOUNT_LIMIT_511.TXT. but all the files names are coming.
I'm confuse. After the first data file inserted then insert second data file. in that all file names are coming. Please help me.
I thought that the global variable is preferable to identify the data came from which file.
to do this, the global variable is used in the target table. I don't always have my exit.
Please help me.
Thanks in advance.
Hello
You can use the same way, how you use the project variable, just you have to do a thin is #GLOBAL.variable_name for example: #GLOBAL. SMART_AL_FILE_NAME_S
Note: Make sure you that while you use one variable overall in interface, indicator should be staged as you chose above the screen
hope this helps you
Kind regards
Phanikanth
-
Get the value of the bind variable in backing bean class VO Impl
Hello
I have a VO that includes a bind "pOrgId" variable, the VO has a java VO Impl class that includes:
/**
* Returns the value of the variable to pOrgId.
value of the variable * @return for pOrgId
*/
public {getpOrgId() number
return (Number) ensureVariableManager () .getVariableValue ("pOrgId");
}
So it is possible to obtain the value is concluded by the binding variable using this class in a backing bean? (I tried to import the VOImpl class in the bean to support, but getpOrgId is not available?).
(JDEV 11.1.2.3.0)
Concerning
CarlHello
When you create a ViewObjectImpl class, none of these options is to generate the getter/setter for bind variable. Create a client class interface and expose the get method for the variable binding. Now, you can reference the method since a binding method in the ADF, which you then access a managed bean by calling
BindingContext bctx = BindingContext.getCurrent(); BindingContainer bindings = bctx.getCurrentBindingsEntry(); OperationBinding oper = (OperationBinding) bindings.get("name of the method binding"); Object returnVal = oper.execute();
Frank
-
Procedure with an unknown name or the amounts of the bind variable.
Hey gurus,
I hope someone out there can point me in the right direction.
I write a PL/SQL function that receives an unknown number of bind variables in the client.
I use Apex 1.1 earpiece to set up a model of RESTful resource for a x-www-formulaires-urlencoded body POSITION.
If the client publishes the following body: * "title = M. & fname = John & lname = Smith" * "
My PL/SQL procedure automatically receives the bind variables which is placed by the following:
: title: = "M";
: fname: = "John";
: lname: = 'Smith ';.
Now my limit is that the required design uses the metadata to define the structure of data of the end-user.
So in reality the body of MESSAGE I get more like this: * "M. = 120 & 121 = John & 122 = Smith" * "
So my PL/SQL procedure receives:
: 120: = "M";
: 121: = "John";
: 122: = 'Smith ';.
I can query the metadata tables to anticipate what bind variables can be present at the execution,
but this can change depending on the resource ID with the body of the MESSAGE at the time of the request.
My first attempt was to be a loop expected elements and run an EXECUTE IMMEDIATE likes:
for c_record_items in
(select field_id in the tfields where record_id =: id) loop
EXECUTE IMMEDIATE ' begin update_item ('|: field_id |', :'|| field_id |'); end;';
end loop;
But unfortunately the EXECUTE IMMEDIATE fails because the binding variable is not declared; It requires the USING clause.
Which I can't think I can code the amount or value in...
I started dabbling in the DBMS_SQL package but I still have to think of a way I can fix this problem.
There are experts out there who can direct me in the right direction?
Very much appreciated.
Published by: Codes on March 5, 2013 17:11
Published by: Codes on March 5, 2013 17:13I have a lot of procedures where I accumulate the number of bind variables.
My approach has been to load each variable binding in an associative array and maintain a counter of the number of bind variables.
Finally, there is a great if then elsif endif block which is actually
if v_binds = 0 then execute immediate
; elsif v_binds = 1 then execute immediate using bind_array(1); elsif v_binds = 2 execute immediate using bind_array(1), bind_array(2); elsif ... end if; Here is a link:
Re: USING Dynamic Clause?Later, I discovered that you could do something like the following:
(Asktom)
http://www.Oracle.com/technetwork/issue-archive/2009/09-Jul/o49asktom-090487.htmlEither of these approaches to solve your problem.
Added link: Keith Jamieson on 6 March 2013 09:26
-
Use of Bind Variable in LOV Jdev 11.1.2
Hello:
I have a lookup_codes table that has values for different columns used in multiple LOV. I created the object based on reading view single SQL statement for the table with a variable binding. Based on the column where I want to set the LOV, I would like to change the variable binding, so the LOV shows that codes of research for this particular column. Essentially, I want to change the binding variable during execution. How can I accomplish this?
Thanks for the help.
Published by: 862658 on July 28, 2011 10:51Hello
You can use the VO API and call vo.setWhereClauseParams ();
http://download.Oracle.com/docs/CD/E12839_01/apirefs.1111/e10653/Oracle/JBO/Server/ViewObjectImpl.htmlKind regards
Brano -
Link to ' effective use of bind variables, cursor_sharing and related ' KO
If I try to access to "the effective use of the bind variables, cursor_sharing and parameters related cursor" doc with link http://www.oracle.com/technetwork/database/features/performance/whitepapers-098560.html http://www.oracle.com/technology/deploy/performance/pdf/cursor.pdf I get
>
We're sorry, the page you requested was not found.
We recorded this error (404) to help us solve the problem.
You can try again using one of the tools below.
Back to previous Page
Site map
Index of products
To find your page, try our search function.
Refine your searchThis PDF file does not exist if the link has been deleted.
-
How to swap two values without using the third variable using the procedure
How to exchange the two values without using the third variable using the procedure?
In a procedure using two mode we pass two values A = x and B = y, and let us pass parameters to receive the output has A = y and B = x without using the third variable
Published by: Millar on August 19, 2012 11:23Your question doesn't seem wise. As written, there is no reason to a third variable, just
CREATE OR REPLACE PROCEDURE( x IN number, y IN number, a OUT number, b OUT number ) AS BEGIN a := y; b := x; END;
If it's an interview question, I suspect that the intention was that you had two settings IN OUT and you wanted to swap the values without the help of a third variable.
Justin
-
The use of bind variables in dynamic query created for Ref Cursor
Hello
I'm in a situation where there is a Ref cursor to which the query is built execution based on a loop. This is why the number of links would be known until the program runs.
The application is currently using literals instead of bind variables.
code snippet of the above is
strSql: = "select * from emp where 1 = 1 and ().
loop cursor1
If cond is true then
strSql = strSql | "ename = ' |" Cursor1.ColumnName;
end loop;
Open cursor2 for strSql;
How to use links in the example above.sb92075 wrote:
user13019948 wrote:
HelloHere is the code I have my trying to change literal-based link to the base.
What do you mean by "based bind?
who, what, how determines the values to be 'bound '?
He's referring to the coding style. He is currently using concatenated literal, and the goal is to change it to use the bindings.
If I understand this it is known as method 4 dynamic SQL and requires DBMS_SQL. There are examples autour but they vary according to the type of statement being generated - SELECT statements require column lists to be parsed, unlike the INSERT/UPDATE/DELETE.
This came up recently on my current project and I hit a demo. Here a table of names and values accepted procedure and had to build these in a single WHERE clause along the lines of
AND t_names(i) = t_values(i)
for an undetermined number of elements in the array. For this demonstration, I used a table that we called "attribute" (don't ask) which has columns including 'attribute_id' and 'name', and I need to build a query along the lines of
select description from attribute where attribute_id = :b1 and name = :b2
by the way '1012' and 'ISIN' respectively. (I use a table better and after a CREATE statement for her but I have to rush right now, sorry).
declare k_sql_base constant varchar2(500) := 'select description from attribute'; t_names constant varchar2_t := varchar2_t('attribute_id', 'name'); t_values constant varchar2_t := varchar2_t('1012', 'ISIN'); l_sql varchar2(500) := k_sql_base; l_rows_fetched integer := 0; l_value varchar2(4000); l_cursor_handle integer; begin -- Construct the SQL statement with column names and bind variables e.g. -- 'select description from mars.attribute where attribute_id = :b1 and name = :b2' for i in t_names.first .. t_names.last loop l_sql := l_sql || case i when t_names.first then ' where ' else ' and ' end || t_names(i) || ' = :b' || i; end loop; dbms_output.put_line('SQL statment = ' || l_sql); -- Parse the statement we built above (the remaining steps require a parsed cursor): l_cursor_handle := dbms_sql.open_cursor; dbms_sql.parse(l_cursor_handle, l_sql, dbms_sql.native); -- Associate the 1st column of output with variable l_value - required for SELECT statements: -- (actually the 3rd param here 'column' seems to be only used to get a datatype, in this case we want a string - -- dbms_sql.column_value actually extracts the value into a specified variable, which can be different. -- All examples in the documentation pass a local variable without further comment, so not entirely clear what this does other than set the output datatype.) dbms_sql.define_column(l_cursor_handle, 1, l_value, 4000); -- Now go through values array binding actual values to :bn variables in the cursor (similar to USING clause of EXECUTE IMMEDIATE) for i in t_values.first .. t_values.last loop dbms_sql.bind_variable(l_cursor_handle, ':b'||i, t_values(i)); dbms_output.put_line('Bound :b'||i || ' as ' || t_values(i)); end loop; -- Open the cursor and fetch the result (no loop here because we are expecting a single-row result): l_rows_fetched := dbms_sql.execute_and_fetch(l_cursor_handle); -- 'Returns value of the cursor element for a given position in a cursor' -- Copy the value of column 1 to variable l_value (has to match -- dbms_sql.column_value(l_cursor_handle, 1, l_value); dbms_sql.column_value(l_cursor_handle, 1, l_value); dbms_output.put_line('Result = ''' || l_value || ''''); dbms_sql.close_cursor(l_cursor_handle); end;
Hope that helps...
-
The use of bind variables in the application process
Bind variables refer to elements of session state supported in queries in an application request process?
All the examples I see show how to pass client side values using the $v () function and the htmldb_get object addParam method and refer to them using the wwv_flow.g_xNN variables, but already available in session state values, I should be able to use them directly in the process, right?
Thank youYes, they are supported.
Denes Kubicek
-------------------------------------------------------------------
http://deneskubicek.blogspot.com/
http://www.Opal-consulting.de/training
http://Apex.Oracle.com/pls/OTN/f?p=31517:1
http://www.Amazon.de/Oracle-Apex-XE-Praxis/DP/3826655494
------------------------------------------------------------------- -
pass the binding variable to the af:table using the menu drop-down
I need to create an af:table to pull all employees belonging to a Department. I created the table based on a viewobject.
The query in the view object has a variabe bind, for example:
Select * from employee where deptname to (select deptname of Department where deptid =: deptid)
My question is how to get the deptid selected in a drop-down list value passed to the query of the table of the adf?
The user, what version jdev you use?
Where is the location THAT LOV located on the page? Once you have the service ID, you can use the executeWithParams to run the query and display the result in the table.
If this isn't what you want to elaborate on the use case.
Timo
-
Use of bind variables in the repository
All,
Our client has a requirement that they need the sales this year of sales vs. last year passing year as a guest.
I can't use BI built in function to get early start or this year last year because our calendar dates are not standard. So I have to this day of dim query table to see e.g. for whats 2010 is the start date and so on...
To do this, I created a variable repository to hold these values using SQL. I want to know is can I use a binding to this SQL variable so that when the user passes year I can feed that year in this SQL and it will provide me with correct start and the end date for this year and last year.
Thanks in advanceYes. We can pass a value to what the user selects the guest. To do this you have create a session variable with "enable any user to set the value". Prompt properties for the year column choose "Ask the Variable" for whole Variable. And the use of content filtering year = ' valueof (NQ_SESSION.myVariable).
Let me know if it worked.
Kind regards
Jay
Maybe you are looking for
-
The cursor moves erratically even when no mouse connected
I've had the problem for over a year now, but I never received tour to report. From time to time, my cursor moves erratic around the screen, jumping from position every few seconds. I have a MBP, but often use it plugged on a screen and mouse etc wit
-
WWhile navigation, my iPad 2 is empty for a few seconds. Web site in seconds. This happens frequently. Very annoying. Why this phenomenon happens and is there anything I can do about it?
-
Change Parameters.ReportOptions by the expression
I'm testing five DUT with the batchmodel. Now, I want to save UUT statement of "c:\\test\\__'.»» For this purpose, I added expression to the sequence "ReportOptions: Parameters.ReportOptions.DisableReportGeneration = False, Parameters.ReportOptions.I
-
want to 4500: HP envy 4500 print only not with the iMac
I have a 4500 desire connected to a new imac. When I send documents to the printer and check the print queue, it says it has connected to the printer and print, but nothing happens. Any idea what's going on?
-
HP 7000 Wide Format: Test print (small squares and two birds) whenever I turn it on
Whenever I turn my HP 7000 Grand Format, starts printing test print (small squares and two birds). How can I stop it. It kills my ink.