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
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;
What I mean with the SQL string:
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
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
But I would not use these functions without papers as those who can change or there is no future versions APEX.
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

Tags: Database

Similar Questions

  • How to get the cursor to the first line after the addition of 3 rows in the OPS. Help, please.

    Hi Experts,

    I have a requirement to get the cursor should point to the first line instead of pointing to the third row. To the help of code below, my cursor points to the third row. Please put some light on it to reach the requirement

    XXCLKTestVOImpl vo = getXXCLKTestVO1();

    for (int i = 0; i < 3; i ++) {}

    Line = vo.createRow ();

    vo.insertRow (row);

    row.setNewRowState (Row.STATUS_INITIALIZED);

    }

    Thank you

    Gurnur Singh

    Problem is solved. Since then, I've been on 12.2.4 Ebs version and was auto insert false setting in AddtablerowBean. To reach the requirement, you will need to refer to the same number of lines to add the addtablerowbean property that you use in loop for. here I use 3 looping so you must use the number 3 lines to add the addtablerowbean property to get there. So whenever you add three rows then cursor in the first row of three lines you will add. Thank you all.

    Thank you

    Gurnur Singh

  • By creating a form that has several text boxes to a single character on the same line, how can I get the cursor to go in the next text box automatically after inserting a character?

    By creating a form that has several text boxes to a single character on the same line, how can I get the cursor to go in the next text box automatically after inserting a character?

    Create a text field and use the option 'comb n characters.

  • I'm a manuscript, PDF, editing files on my ipad.  Try to get the cursor to allow me to edit the text, how do?

    I'm editing a manuscript, aPDF, on my iPad.  How can I get the cursor appears so I can edit the words and phrases in the manuscript?

    I agree with TSN, but if you insist, go to tools > edit PDF.

  • My text box is frozen and has a dotted around her line, how can I get the cursor inside?

    My text box is frozen and has a dotted around her line, how can I get the cursor inside? I work in Indesign CS3, I wrote a page of A4 format with a unique and with a large amount of text inside text box. In the end, I brought a JPEG in the page. Now they have a thin line dotted around them and appear "frozen." I have not seen the dotted line instead of the line before usual text box.

    Points: The text box is not locked, the layer is not locked. Nothing on the page goes live with command + A to select.

    It happened between the Time Machine backups so that I can not restore.

    All I need are the captured keystrokes.

    What can happen when you put the JPEG, I myself can I have moved that file folder, a larger file, on the desktop, then placed the JPEG.

    Re-opening Indesign didn't work; restart did not work.

    Solutions appreciated.

    The dotted lines mean that your items are on a master page and not a document page.

  • How to get the cursor to change when rolled on an object?

    does anyone know how to get the cursor to change when rolled onto an object. BTW, I have several objects to apply it.

    Select your object's buttonMode:

    yourobject.buttonMode = true;

  • How do you get the cursor to move in Dreamweaver CS5?

    Im trying to get the cursor to move to the right or up and down, but he still left. IM new to dreamweaver for any advice would be much appreciated.

    Thanks in advance

    Im trying to get the cursor to move to the right or up and down, but he still left. IM new to dreamweaver for any advice would be much appreciated.

    You mean the caret blinking (slider) located in the upper left corner when you're faced with a blank page?

    If tthat's what you mean, then you have not.

    The first acts of Dreamweaver over to a wordprrocessor (it is NOT a word processor) a desktop publishing application that you can just click anywhere and insert content.

    You need to learn something about HTML and CSS to understand how to use DW.

    Good starting point: http://www.w3schools.com/

    If you meant something else, please advise.

  • java.sql.SQLSyntaxErrorException: ORA-01745: host not valid/bind variable nam

    String sequnceDocumentId = "SELECT snw_doc_type_map_id_seq. NEXTVAL INTO: 1 FROM DUAL; " ;

    PreparedStatement pStmt = null;
    ResultSet rs = null;
    rowExists Boolean = false;
    CallableStatement st1 = getDBTransaction () .createCallableStatement (sequnceDocumentId, 1);
    try {}

    ST1.registerOutParameter(1,types.) Integer);
    ST1. ExecuteQuery();
    SeqId number = new Number (st1.getInt (1));
    setDocumentTypeId (seqId);
    ST1. Close();


    }
    catch (Exception e) {}

    e.printStackTrace ();

    }

    Get the following exception

    at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:91)
    at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1035)
    at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:191)
    at oracle.jdbc.driver.T4CCallableStatement.executeForDescribe(T4CCallableStatement.java:788)
    at oracle.jdbc.driver.T4CCallableStatement.executeMaybeDescribe(T4CCallableStatement.java:863)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1187)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3386)
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3430)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1491)
    at weblogic.jdbc.wrapper.PreparedStatement.executeQuery(PreparedStatement.java:128)
    at oracle.apps.snw.schema.server.SnwDocumentTypeMappingsEOImpl.create(SnwDocumentTypeMappingsEOImpl.java:42)


    Please let me know what Miss me...

    Thank you

    Just talking about the top of my head, since I have not tried, but...

    When you use the INTO clause, you are implying that you run in a 3GL environment, in this case, PL/SQL. But if it comes to PL/SQL, you have a BEGIN and END around all the instructions. You must have:

    String sequnceDocumentId ="BEGIN SELECT snw_doc_type_map_id_seq.NEXTVAL INTO :1 FROM DUAL; END;" ;
    
  • bind variables and dynamic sql

    Hi all

    Here's my situation:

    I have a query with 2 bind variable: the FROM clause also uses a variable binding!

    PROCEDURE describe_columns(p_curr_tablename VARCHAR(50), p_curr_intentseq NUMBER)
       IS
          l_cur     INTEGER;
          l_query   VARCHAR (100);
       BEGIN
          l_query :=
             'select * from :table_name where ibmsnap_intentseq = :sequencenr';
          l_cur := DBMS_SQL.OPEN_CURSOR;
          DBMS_OUTPUT.PUT_LINE (p_curr_tablename);
          DBMS_OUTPUT.PUT_LINE (p_curr_intentseq);
          DBMS_OUTPUT.PUT_LINE (l_query);
          DBMS_SQL.PARSE (l_cur, l_query, DBMS_SQL.V7);
          DBMS_SQL.bind_variable (l_cur, ':table_name', p_curr_tablename);
          DBMS_SQL.bind_variable (l_cur, ':sequencenr', p_curr_intentseq);
          DBMS_SQL.DESCRIBE_COLUMNS (l_cur, g_count, g_desc_tab);
          DBMS_SQL.CLOSE_CURSOR (l_cur);
       EXCEPTION
          WHEN OTHERS
          THEN
             DBMS_OUTPUT.put_line ('DF-EXCEPTION: ' || SQLERRM);
             DBMS_OUTPUT.put_line (
                'DF-EXCEPTION: ' || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE
             );
    
             IF DBMS_SQL.IS_OPEN (l_cur)
             THEN
                DBMS_SQL.CLOSE_CURSOR (l_cur);
             END IF;
       --         RAISE;
       END;
    and the output is:
    CD_B136V4_NEW
    16
     select * from :table_name where ibmsnap_intentseq = :intentseq
    DF-EXCEPTION: ORA-00903: invalid table name
    DF-EXCEPTION: ORA-06512: in "SYS.DBMS_SYS_SQL", line 906
    So is the problem that I want to use a variable binding for the name of the table?

    I'd appreciate any help!
    Thank you!

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:227413938857

    Identifiers cannot be used as variable bind - never. Identifiers must be "hard-coded".
    in the query.

    I can't put in a link for "emp" variable because I can't use a string
    constant for emp.

    The reason is quite simple - a bind variable query is parsed and optimized once
    variables are evaluated before linking. If I could code:

    Select * from: bind_x

    the optimzer would not have an idea of what will come with, security (access rights)
    could be evaluated and so on. We could not develop a plan for this query - not
    enough information. Therefore, no variable bind for identifiers.

  • VO with bind variable defined in SQL is not updated correctly

    Hi Experts,

    I have a simple question here, could you please help answer? Thank you very much!

    I have 2 pages, the first page displays an employee table, the second page shows a few details to the selected employee. When to choose a single employee and click the details button I can be naviaged to the second page and see the details for the selected employee. The vo used on the second page uses a connection variable called "empId" thing for a 'adf.context.pageFlowScope.empId' pageFlowScope value, and this value pageFlowScope will be filled to the empId selected detail button actionListener during execution).

    The question is, now first navigation is ok, the details of the page can display the correct information for the employee selected on the page of the employee, but when browsing back and choosing another employee, and then again click the details button, the details of the page is NOT updated, it still shows the initial information for the selected employee. I debug the actionListener in support bean and the second selected empId passed to pageFlowScope.empId, the link in the t variable should get the new value, right? But why the second page gets no updates (request using the new value of the bind variable)?

    Thank you!

    Published by: user774592 on July 20, 2011 23:13

    Published by: user774592 on July 20, 2011 23:15

    Published by: user774592 on July 20, 2011 23:15

    In theory, if you expose specific objects of customer to your business (for example pageflowscope) service layer, you may miss 1. test driven development assistance (case of unit test can fail) 2. Customer service of independent business etc... :)
    To respond to your request try to call TargetPagesVO.execute () before the second page (by program or activity method)

  • 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;
    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;
    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?

    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

  • Left click will get the cursor in the field of data entry

    When I left click in a data entry field will not come the cursor upwards and I can't enter data. The left click works normally at any other time. I use a Dell Latitude D830 laptop. Everything works normally until today

    Hello

    • Where does this happen?
    • What were the changes made before the show?

    You can collect screenshots of color 256 and transfer it to the http://skydrive.live.com/ using your Live ID and I'll check it:

    Screenshot

    ========

    1. press the button print screen (print screen) on your keyboard.

    2. click on the "Start" menu, type "mspaint" in the search bar and press ENTER.

    3. in the Paint program, click on the "Edit" menu, click on 'Paste', click on the 'File' menu and click 'save '.

    4. the dialog box "Save as" appears. Type a file name in the "filename:" box, for example: "screenshot".

    5. make sure that "JPEG (*.)" JPG; *. JPEG; *. JPE; *. JFIF)"is selected in the box 'Save as type', click Desktop in the left pane, and then click"Save ".

    ===========================================================

  • Gets the cursor not valid error on line 6?

    create or replace procedure cust_pack (p_dept_id in number, p_emp_id number) is
    number of v_credit_limit: = 2000;
    cursor cur_cust (p_dept_id in number, p_emp_id number) is
    Select first_name, last_name, salary from employee where department_id = p_dept_id and employee_id = p_emp_id;
    Start
    for cust_record in cur_cust (50,188)
    loop
    dbms_output.put_line (' name ='| cust_record.last_name |', Sal ='| cust_record.salary);
    close cur_cust;
    end loop;
    end;
    /
    Please rectify the problem...

    Please rectify the problem...

    Remove this

    close cur_cust;
    

    You do not close the cursor yourself in a cursor for loop and especially not while you use it.

    http://docs.Oracle.com/CD/B19306_01/AppDev.102/b14261/loop_statement.htm#LNPLS01328

    Concerning
    Peter

  • How to get the cursor hand on Menu items?

    I want the cursor hand on menu items. I can get the main menu but not on the dots cursor.

    Please help, thanks in advance.

    Atul

    Hello

    If you want handcursor on menuitems put these properties on the label of the menuitem.

    useHandCursor = true;
    buttonMode = true;
    mouseChildren = false;

    If this post answers your question or assistance, please mark it as such.

    Thank you

    Jean Claude Chari.S

  • Get the cursor in the desired field

    How can I get a field ready for entering text (with the cursor in it) without the user click on it? Simple, no doubt, but I honestly don't know the answer and "were not able to find it in the forums or the support. Thank you!

    Bruce

    Perfect. Thank you!

Maybe you are looking for