SQL Bind Variables workshop - Date issues
I use SQL Workshop to run through some queries. I'm having a problem with Bind Variables that contain dates. I enter the following date:12/12/2013
but it is converted to:
12 & amp; #x2F 12 & amp; #x2F; 2013
I'm doing something wrong?
Thank you
Glen
It looks like a bug. It should not escape what either.
Denes Kubicek
-------------------------------------------------------------------
http://deneskubicek.blogspot.com/
http://www.Apress.com/9781430235125
http://Apex.Oracle.com/pls/Apex/f?p=31517:1
http://www.Amazon.de/Oracle-Apex-XE-Praxis/DP/3826655494
-------------------------------------------------------------------
Tags: Database
Similar Questions
-
I am writing a process to delete records based on dates.
Here is the chart:
Column name Data type Nullable Default Primary key ID NUMBER NO. - 1 CT_NAME VARCHAR2 (100) Yes - - CT_CATEGORY VARCHAR2 (100) Yes - - BASE_PTS NUMBER Yes - - PROD_PTS NUMBER Yes - - REF_PTS NUMBER Yes - - START_DATE DATE Yes - - END_DATE DATE Yes - - CREATED_ON DATE Yes - - CREATED_BY VARCHAR2 (50) Yes - - UPDATED_ON DATE Yes - - UPDATED_BY VARCHAR2 (50) Yes - - start_date and end_date are the fields of date key.
The query will remove the dates with specific start and end dates. The question I have, is that I get a ORA-01858: a non-digit character was found here where was waiting for a digital error while the query is running.
remove from ct_point_values
where start_date =: P4_START_DATE_V
and end_date =: P4_END_DATE_V
If I run the query in the sql window, no problem:
remove from ct_point_values
where start_date =' 01 / 01/2014 '
and end_date = 31 December 2014"
Find the query with the works of values hard-coded. Links to fail. I tried casting and to_char to_date variations with no luck.
One thing that I notice, is that when I go to enter my bind variables in the sql workshop, the fields are pre-populated with this:
1 & amp; #x2F 1 & amp; #x2F; 2014
12 & amp; #x2F 31 & amp; #x2F; 2014
01/01/2014 and 31/12/2014. I found that the only element relates to this suggests that this is a possible bug:
SQL Bind Variables workshop - Date issues
Any thoughts on how to address this issue, or is it really a bug?
I run on Apex 4.2, 11g.
Thank you!
Hello
I guess that these dates come from elements on the page to which the user can select a range of dates.
These fields have a custom format mask?
What seems to be the case for me, is that these fields have an explicit format mask (for example: DD/MM/YYYY) but the default database/session format mask is something different (e.g. DD-MON-YYYY).
I suppose also that the issue in the SQL workshop isn't something related.
-
Update MS SQL for APEX pl/sql - Bind variable/field process table
I created a page APEX that updates a table of linked server sql through the call to a pl/sql process 'submit '.
The anonymous pl/sql block refers to a hidden field on the page titled "P3_RECORD_ID" in the place where it is clause.
The pl/sql block, I invoke is:
Start
commit;
Update "SRSRATINGS".
'Status' value = 'PASS '.
where "Record_ID" =: P3_RECORD_ID;
commit;
end;
This is block if I replace it with a literal numeric value for the variable/hidden bind field: P3_RECORD_ID. However, when I use the link variable: P3_RECORD_ID, I get the following error:
ORA-02070: SRS database. MSSQL does not support the TO_NUMBER in this context
He doesn't seem to understand that P3_RECORD_ID is a reference to the primary key on the form field.
Any help is appreciated.Hello:
Try if edit the pl/sql block below work
declare l_num number := :P3_RECORD_ID; begin commit; update "SRSRATINGS" set "Status" = 'PASS' where "Record_ID" = l_num ; commit; end;
CITY
-
SQL * more substitution vs bind variable question
Hi all, I am trying to automate some SQL within SQL codes * more script that is triggered by a script .bat, the only parts that change are Dates...
example:
create table blah as
Select * from table
WHERE DATE between start_date and END_DAY;
the DATE is a numeric field, YYYYMMDD
The script runs always at the beginning of a new week, so a Monday, unless a public holiday, then a Tuesday.
The END_DAY is * always * last Friday and I realized that:
variable L_FRIDAY char (15);
Start
Select to_char (next_day(sysdate-7,'FRIDAY'), 'YYYYMMDD') as Last_Friday in: double L_FRIDAY;
end;
/
The thing is that I get an error when I try to use the binding variable?
create table blah as
Select * from table
WHERE DATE between start_date and: L_FRIDAY;
Then once I found the end date, I was going to use add_months(L_FRIDAY,-12) for previous 12 months for the start_date...
When I tried to use a variable Substitution I could just hard code the date, but I can not or do not know how to set the value of this exec to the variable?
Help!
:-)
Basically my research reveals that - Bind variables are not allowed for operations of data definition, use substutions instead of bind variables
I need an automated way to find the END_DAY which is last Friday and START_DATE that is 12 months before Friday and refer to those in the SQL without errors.
Hello
Kodiak_Seattle wrote:
Hi all, I am trying to automate some SQL within SQL codes * more script that is triggered by a script .bat, the only parts that change are Dates...
example:
create table blah as
Select * from table
WHERE DATE between start_date and END_DAY;
the DATE is a numeric field, YYYYMMDD
The script runs always at the beginning of a new week, so a Monday, unless a public holiday, then a Tuesday.
The END_DAY is * always * last Friday and I realized that:
variable L_FRIDAY char (15);
Start
Select to_char (next_day(sysdate-7,'FRIDAY'), 'YYYYMMDD') as Last_Friday in: double L_FRIDAY;
end;
/
The thing is that I get an error when I try to use the binding variable?
create table blah as
Select * from table
WHERE DATE between start_date and: L_FRIDAY;
Then once I found the end date, I was going to use add_months(L_FRIDAY,-12) for previous 12 months for the start_date...
When I tried to use a variable Substitution I could just hard code the date, but I can not or do not know how to set the value of this exec to the variable?
Help!
:-)
Basically my research reveals that - Bind variables are not allowed for operations of data definition, use substutions instead of bind variables
I need an automated way to find the END_DAY which is last Friday and START_DATE that is 12 months before Friday and refer to those in the SQL without errors.
Or SQL * more bind variable or variable substitution can be DATEs. The best you can do is set a different type, as a string, representing a date. A string as June 19, 2015"represents a date, but so strings like 'SYSDATE' and ' SYSDATE - 7', so you can do something like this:
SET l_friday = ' NEXT_DAY ((SYSDATE-7), 'FRIDAY').
DEFINE start_date = "ADD_MONTHS (& l_friday, - 12)"
SELECT & start_date AS t_n
, & l_friday AS l_f
OF the double
;
Output (when executed on 25 June 2015):
L_F T_N
----------- -----------
June 19, 2014 19 June 2015
-
Value data named to bind variables of Type table
Hello
I have a display object with a query that has a where clause, clause which use 'en' (e.g. Select projTitle PROJECT where PROJID in: projIds)
'projIds' is a variable of type table of liaison.
I'm moving in that variable binding expects (an array of projIds that can be used by the sql statement), and I did not. I'm calling a method in the bean to support the named child tag data from the action tag in the pageDef file links section.
Can you give me the proper syntax and object Array as this variable binding will accept, please? Maybe I used the wrong NDType? I found a couple of different options, but none that I can make it work.
The page definition file:
< action IterBinding = "ProjPendingApprovalByApproverVO1Iterator" id = "loadPendingApproval".
InstanceName = "SystemAMDataControl.RooProjIdArrayt.ApprovalAM1.ProjPendingApprovalByApproverVO1"
DataControl = "SystemAMDataControl" RequiresUpdateModel = "true" Action = "executeWithParams" >
< NamedData NDName = 'PROJID"NDValue =" #{dashboard.projIdArray} "NDType="oracle.jbo.domain.Array"/ >"
< / action >
Application of VO:
SELECT ProjectEO.PROJ_ID,
ProjUtnDtlEO.UTN_TYPE,
ProjectEO.PROJ_SHORT_DESC,
ProjUtnDtlEO.PROJ_DTL_ID,
ProjectEO.PROJ_OWNER,
VEmployeeInfoEO.FIRST_NAME,
VEmployeeInfoEO.EMPLOYEE_ID,
VEmployeeInfoEO.FIRSTNAMELASTNAME,
VEmployeeInfoEO.LAST_NAME,
VEmployeeInfoEO.LASTNAMEFIRSTNAME,
ProjApprovalDecisionDtlEO.PROJ_APPROVAL_DECISION_DTL_ID,
ProjApproverEO.PROJ_APPROVER_ID,
ProjApproverEO.APPROVER_LEVEL,
ProjApproverEO.APPROVER_NUMBER,
ProjApproverEO.APPROVER_ROLE,
ProjApprovalDecisionDtlEO.COMMENTS,
ProjApprovalDecisionDtlEO.PROJ_APPROVAL_DECISION_ID,
ProjApprovalDecisionDtlEO.LASTUPDATEDBY,
ProjApprovalDecisionDtlEO.APPROVEDDATE,
ProjectEO.SYS_STATUS,
ProjApproverEO.LASTUPDATEDBY AS LASTUPDATEDBY1,
ProjApprovalDecisionDtlEO.PROJ_APPROVAL_TYPE_ID,
ProjStatusLkpEO.STATUS_DESC,
ProjStatusLkpEO.PROJ_STATUS_ID,
ProjectEO.PROJ_CATEGORY_ID,
STRING. APPROVAL_DESC
OF PTS. ProjectEO PROJECT,
PTS. PROJ_UTN_DTL ProjUtnDtlEO,
PTS. V_EMPLOYEE_INFO VEmployeeInfoEO,
PTS. PROJ_APPROVAL_DECISION_DTL ProjApprovalDecisionDtlEO,
PTS. PROJ_APPROVER ProjApproverEO,
PTS. PROJ_STATUS_LKP ProjStatusLkpEO,
PTS. Channel PROJ_APPROVAL_CHAIN_LKP
WHERE ((ProjectEO.PROJ_ID = ProjUtnDtlEO.PROJ_ID (+))
AND (ProjectEO.PROJ_ID = ProjApprovalDecisionDtlEO.PROJ_ID))
AND (ProjectEO.PROJ_ID = ProjApproverEO.PROJ_ID)
AND (ProjectEO.SYS_STATUS = ProjStatusLkpEO.SYS_STATUS)
AND (ProjectEO.PROJ_OWNER = VEmployeeInfoEO.EMPLOYEE_ID)
AND (ProjApprovalDecisionDtlEO.PROJ_APPROVER_ID = ProjApproverEO.PROJ_APPROVER_ID)
and PROJAPPROVEREO. PROJ_APPROVAL_CHAIN_ID = STRING. PROJ_APPROVAL_CHAIN_ID
AND (ProjApprovalDecisionDtlEO.PROJ_APPROVAL_DECISION_ID = 0)
and PROJAPPROVEREO. APPROVER_LEVEL <>2
and PROJAPPROVEREO. PROJ_ID in: PROJID
Thank you!
Please refer to http://www.jobinesh.com/2010/09/using-bind-variable-for-sql-statements.html?m=1 for an example of this.
Timo
-
How to pass a list as a bind variable in SQL Developer?
How can I pass a list as a bind variable in SQL Developer?
The following query in SQL Developer so work I put ": prmRegionID = 2.
SELECT COUNTRY_ID,
COUNTRY_NAME
OF HUMAN RESOURCES. COUNTRY
WHERE IN REGION_ID (: prmRegionID);
The problem is that I can't find how to set ": prmRegionID = 2, 3.
I know that I can replace ": prmRegionID" by a proxy '& prmRegionID '. The above query will work well with"& prmRegionID = 2" and with "& prmRegionID = 2, 3". "
But with this solution, I lost all the benefit of the use of bound variables (analysis hard against soft parse, possibility of SQL injection, etc.).
I'm learning how to do this in SQL, as well as the use of UDT in this thread: How to move a list as a bind variable?
But with this solution, I've lost nice SQL Developer user interface. In SQL developer, it is easy to test a query using the standard binding variable. When we start the application, a pop up asking for a value of the variable binding.
With the UDT, the interface request always variable binding standard. You have an idea on how I can get a variable string binding (such as 1, 2, 10) in a set of NUMBER or VARCHAR2? This way I would be able to launch a standard query in SQL Developer to test my application.
Can someone tell me what is the best approach to this?
Thank you in advance,
MBHi Blais,
Thank you for trying the SQL and PL/SQL instance before coming here - it was definitely the right approach, and you've got some very good suggestions there. Your needs for a invite only bind to the value in the clause list, I think I have a possible solution. I'll introduce you to a list of characters, so you'll have to tweak it for other types of data. First, add the following to your schema:
create or replace TYPE bind_tab_typ AS TABLE OF VARCHAR2(4000); create or replace FUNCTION comma_to_table(iv_raw IN VARCHAR2) RETURN bind_tab_typ PIPELINED IS ltab_lname dbms_utility.lname_array; ln_len BINARY_INTEGER; BEGIN dbms_utility.comma_to_table(list => iv_raw ,tablen => ln_len ,tab => ltab_lname); FOR i IN 1 .. ln_len LOOP PIPE ROW (ltab_lname(i)); END LOOP; END;
Now you can write a query, say for scott.dept, as follows, and have executed statement ask the value list in the clause as a single binding variable:
select * from dept where dname in ( select * from table( comma_to_table( :BNDS )) );
When you are prompted, provide the list of values separated by a single comma without any extra spaces.
I don't know if the Varchar2 (4000) really needs to be which is great. I use it because that's what dbms_utility.lname_array uses.
Kind regards
Gary
SQL development team -
bind variables in pl/sql static
Hello world.
This feature will be works faster than the function below without binding? (I mean if he calls very often, and execution plan is in cache)FUNCTION get_amployee_name (empid INTEGER, empcity VARCHAR2) RETURN VARCHAR2 IS TYPE GenericCursor IS REF CURSOR; c1 GenericCursor; empname VARCHAR2(200); BEGIN OPEN c1 FOR SELECT ename FROM employees WHERE id = :id AND city = :city USING empid, empcity; FETCH c1 INTO empname; CLOSE c1; RETURN empname; END;
I tried to find info related to the execution of pl/sql query steps, but cannot. Optimizer does use the values of real variables in pl/sql to generate the exec. plan? Or it will be generated only once when the function performed the first time?FUNCTION get_amployee_name (empid INTEGER, empcity VARCHAR2) RETURN VARCHAR2 IS empname VARCHAR2(200); BEGIN SELECT ename into empname FROM employees WHERE id = empid AND city = empcity; RETURN empname; END;
Reference and discusses this in Chapter 1 PL/SQL user's Guide
http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14261/overview.htm#sthref145
"When you embed an INSERT, UPDATE, DELETE or SELECT SQL statement directly in your PL/SQL code, PL/SQL transforms the variables in the WHERE clauses of the VALUES to automatically bind variables. Oracle can re-use these SQL statement every time the same code is executed. To execute statements similar with different values of variables, you can save the analysis of overhead by calling a stored procedure that accepts parameters, and then issues the declarations with the parameters substituted in the appropriate places. »
Justin
-
Convert SQL to take advantage of the Bind Variables
Hi all
Is it possible to convert the SQL below so I can enjoy variable Bind? It's just my personal way of followed by the name of the script that I use on a daily basis... the file is passed to a point that its about 2K lines long, and whenever I run this specific file to get a script name, it creates a new SQL in the database pool shared... I tried to change this option to use bind variables , but it doesn't seem to work properly and I wanted what suggestion of the community...
ACCEPT script_name_like prompt 'ENTER SCRIPT NAME OR HIT ENTER TO GET ALL SCRIPT NAME OR PUT PART OF THE SCRIPT NAME : ' WITH help_script AS ( SELECT 'top_seg_tab_obj_ash' AS Script_Name, 'top segment by tot wait time' AS Description, '# of mins to go back' AS INPUT FROM dual UNION ALL SELECT 'v$_tab' AS Script_Name, 'shows list v$ views' AS Description, 'view name like' AS INPUT FROM dual UNION ALL SELECT 'dba_tab' AS Script_Name, 'shows list dba views' AS Description, 'view name like' AS INPUT FROM dual UNION ALL SELECT 'nls_params' AS Script_Name, 'shows list of current NLS setting for DB/INST/SESS' AS Description, 'no Input Needed' AS INPUT ) SELECT upper(script_name) AS "MY SCRIPT NAME", upper(description) AS description, upper(INPUT) AS INPUT FROM help_script WHERE script_name LIKE nvl('%&script_name_like%', script_name) ;
Hello
user13454469 wrote:
Hi all
Is it possible to convert the SQL below so I can enjoy variable Bind? It's just my personal way of followed by the name of the script that I use on a daily basis... the file is passed to a point that its about 2K lines long, and whenever I run this specific file to get a script name, it creates a new SQL in the database pool shared... I tried to change this option to use bind variables , but it doesn't seem to work properly and I wanted what suggestion of the community...
- ACCEPT script_name_like invites ' ENTER NAME or HIT ENTER to GET ALL THE SCRIPT NAME or PART OF THE SCRIPT the SCRIPT NAME: '
- WITH help_script AS
- (SELECT "top_seg_tab_obj_ash" AS Script_Name,
- "upper segment by tot queue time" AS Description,.
- "# of minutes to go back" AS INPUT
- OF the double
- UNION ALL SELECT ' v$ _tab "AS Script_Name,.
- "Show list views$ v ' AS Description,.
- 'show the name as' AS ENTRY
- OF the double
- UNION ALL SELECT 'dba_tab' AS Script_Name,
- "Show list views dba" AS Description,.
- 'show the name as' AS ENTRY
- OF the double
- UNION ALL SELECT 'nls_params' AS Script_Name,
- 'displays the list of current NLS parameter for DB/INST/SESS' AS Description,.
- ("No input is necessary" IN ENTRY)
- SELECT upper (script_name) AS "MY SCRIPT NAME",
- Upper (Description) as a description,
- Upper (Input) AS INPUT
- OF help_script
- WHERE script_name AS nvl (script_name ' % & script_name_like %',);)
The WHERE clause (last line) of is the only place where you are using the proxy & script_name_like? If so:
-ACCEPT command is exactly the same as before
ACCEPT script_name_like invites ' ENTER NAME or HIT ENTER to GET ALL THE SCRIPT NAME or PART OF THE SCRIPT the SCRIPT NAME: '
VARIABLE script_name_like_b VARCHAR2 (30)
EXEC: script_name_like_b: = '% & script_name_like;
WITH the help _script AS
...
WHERE script_name AS NVL (: script_name_like_b, script_name);
-
problem with bind variables in the SQL query view object
Hi all
I use JDev 11.1.2.4.0.
I have a problem with bind variables in the SQL query view object.
This is my original SQL
SELECT sum(t.TIME) , t.legertype_id FROM LEDGER t WHERE t.nctuser_id = '20022' AND to_char(t.insertdate,'YYYYMMDD') in ('20130930','20130929') group by t.legertype_id
In my view .xml object query tab, I am writing this
SELECT sum(t.TIME) , t.legertype_id FROM LEDGER t WHERE t.nctuser_id = '20022' AND to_char(t.insertdate,'YYYYMMDD') in :dddd group by t.legertype_id
Davis here is a variable of Type liaison: String, updatable and necessary.
I try to deal with Davis as ('20130930 ', ' 20130929') hoping the view object, run as my original SQL.
But failed. The view object retrieves 0 line after that I run.
Why?
Thank you! ('2original SQL0130930', '20130929') ('20130930 ', ' 20130929')
A variable binding cannot be used as this is why you must use years table. Check decompilation binary ADF: using oracle.jbo.domain.Array with ViewCriteria to see a solution.
Timo
-
Can I use session variables in data model BI publisher SQL query?
Hi Experts,
We apply security at the level of the BI Publisher 11g data.
In OBIEE we do so using session variables, so I wanted to just ask if we can use the same session variables in BI Publisher as well
That is, we can include a where clause in the SQL for the sample data as
Where ORG_ID = @{biServer.variables ['NQ_SESSION.]} {[INV_ORG']}
I would like to know your opinion on this.
PS: We implement security EBS r12 in BI Publisher.
Thank youRead this-> OBIEE 11 g: error: "[nQSError: 23006] the session variable, NQ_SESSION.» LAN_INT, has no definition of value. "When you create a SQL query using the session NQ_SESSION variable. LAN_INT in BI Publisher [ID 1511676.1]
Follow the ER - BUG: 13607750 -NEED TO be able TO SET up a SESSION IN OBIEE VARIABLE AND use it IN BI PUBLISHER
HTH,
SVS -
How to get SQL that do not use bind variables
Hello
I am trying to identify the SQL code which should benefit from the use of bind variables.
First of all, I tried to get the common signature of all the sql calls, using:
Then I copied these values to the Clipboard and run:select * from ( select force_matching_signature, count(1) from v$sql where force_matching_signature<>0 group by force_matching_signature order by 2 desc ) where rownum < 50;
Now, I want to make it automatically and get only 1 occurrence of each SQL that resembles others by using a query.select sql_text from v$sql where force_matching_signature=<<<copied_signature_value>>>;
I tried this:
But it is not returning results by showing up at the count (1) from the first query, I've used. How can I change this if I get the results in order of "importance"?select sql_text from ( select sql_text, force_matching_signature, row_number() over (partition by force_matching_signature order by sql_text desc)rn from v$sql where force_matching_signature <>0 )where rn <2 and rownum < 10 order by force_matching_signature desc
Thank youAnd I said. First use the command by then use rownum. I did not mention row_number. Also, there should be no need to add more columns.
Have you tried it? Why it did not work?example not tested
select * from ( select sql_text from (select sql_text, force_matching_signature, row_number() over (partition by force_matching_signature order by sql_text desc) rn from v$sql where force_matching_signature != 0) where rn = 1 order by force_matching_signature desc /* add any ordering you like here */ ) where rownum < 10 /* then filter on the first 10 results */
If you want to order that the statement that found most of the time comes first, say so. However, I don't see how to group in your case.
Maybe like thisexample of tested
select * from ( select cnt, sql_text from (select sql_text, force_matching_signature, row_number() over (partition by force_matching_signature order by sql_text desc) rn , count(*) over (partition by force_matching_signature) cnt from v$sql where force_matching_signature != 0) where rn = 1 order by cnt desc, force_matching_signature desc /* add any ordering you like here */ ) where rownum < 10 /* then filter on the first 10 results */ ;
Published by: Sven w. October 11, 2012 14:49
Published by: Sven w. October 11, 2012 14:51
Published by: Sven w. on October 11, 2012 14:56 - number column added to the output
-
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>
-
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
-
Correct way to use Bind variables when you use an interface to MS SQL Server
Hey,.
I have some difficulty to find how to use bind variables in a view, when you use an interface to MS SQL Server. For some reason when I use an ApplicationModule who has a library of MS SQL Server JDBC loaded and I try to click on OK when you change the following query:
SELECT kit_status, component_id
OF numbered_inv
WHERE trialname =: 1
I get an error stating that ' SQL Query Error Message incorrect syntax near ':'. JDeveloper is compatible with SQL server for bind variable as this query works fine if I replace the: 1 with a Word to say "Test test".
Thanks in advance
Edited by: NullCheck December 15, 2010 14:06Use positional JDBC Style Binding to bind variables
Try to use? Instead of:
As shown here:
http://www.Oracle.com/technetwork/developer-tools/jdev/multidatabaseapp-085183.html -
Query report back "No data found" with bind variables
I put a simple query in the report query:
Select "bluefish". 'name' as 'name',
"bluefish". "" primary_flag "as"primary_flag. "
"bluefish". "" status "than"status. "
"bluefish". ' ' ID ' as 'ID' of "bluefish" "bluefish" where "bluefish". "" ID "=: P3_XPRINTID
When I test the query, the data is returned. However, when I try to run the query using the "Test report" button, I get an error 01403 no data found. If I replace the link with an explicit value variable, the report runs.
Anyone have any ideas as to what is causing this problem? I use the generic report layout, with different types of output. I'M editting the query and set the binding variable before test report (otherwise, the query is not executed).
CharlesIn fact the report would go - unlike other products of Oracle who complain about a missing binding variable, Apex is not complaining but interprets as a null value. So if you hurt typed the name of your variable, you are never alerted to it.
Check the Session window to make sure that it is a value - the most common questions are that you named the wrong variable in the query or your item has no value in session state again.
Maybe you are looking for
-
When I do a new installation of Skype, it is not sync my old chat history. How to bring back my old chat history. Old computer died so I can't recover the files from it
-
I don't know if I'm blind, or the software is not installed. I recently bought the HP Pavilion 17-e110dx of BestBuy and it says it comes with the software Dragon Notes but I can't seem to find it anywhere. Has anyone else thought of it?
-
Brother HL-2140 printer has not passed logo testing for XP
Use printer Brother HL-2140 for nearly two years without problem. Recently started to receive the message "Printer not passed Windows Logo testing to verify its compatibility with Windows XP Pro." Tried to change the settings through "driver settings
-
"The product key you entered has been blocked use by Microsoft.
My hard drive crashed I am reinstalling Windows 7 64 bit with my original product key and I get this error Please don't tell me that I have counterfeit software, I use your downloaded media and my original key so it does not http://answers.microsoft.
-
Too late for the free offer PlayBook?
Hello I don't know if this is the appropriate section of this post, but I'll put it here anyway... I presented my PlayBook application in time for the free offer of the PlayBook, but it has not been approved at the time. In the email I received, they