declare the variable binding

I do homework here and ran into the wrong hope that someone here can help

1. I thought that I understand the conscept of variable binding (which I think it is the same concept as the pointer in C/C++ programming), is that correct?

2. I write the code and find the problem below, please point out what I did wrong?


SQL & gt; describe the plants
Name Null? Type
----------------------------------------- -------- ----------------------------
PLANTID NOT NULL NUMBER (5)
COMMONNAME NOT NULL VARCHAR2 (30)
LIKE NOT NULL VARCHAR2 (30)
SPECIES NOT NULL VARCHAR2 (30)
FLOWERCOLOR VARCHAR2 (10)
HEIGHT NUMBER (4.1)
DATE OF ACQUIREDDATE
LISTPRICE NUMBER (6.2)




SQL & gt;
declare


bv_color variable varchar2 (10);
v_price plants.listprice%Type;



cursor cur_color is
Select distinct lower (flowercolor) color
plants;



Start


for rec_color looping cur_color

: bv_color: = rec_color.color;



Select avg (listprice)
in v_price
plants
where lower (flowercolor) =: bv_color;



dbms_output.put_line)
"The average price for our plants with ' |: bv_color |"
"flowers is $' | Round(v_price,2) | '.');
dbms_output.put_line ('thank you');



end loop;



exception
while others then
dbms_output.put_line (' my exception:' | sqlcode |)
' : ' || SQLERRM);
end;
/
SP2-0552: Bind "BV_COLOR" variable not declared.

This is the way of declaring bind variables in SQL * more.

In a PL/SQL block, you do not use bind variables like SQL * more. You just use normal variables. The PL/SQL engine is smart and sends SQL statements to the SQL engine containing all PL/SQL variables converted to bind variables. If it works transparent in PL/SQL and you don't have to do something more.

Kind regards
Rob.

Tags: Database

Similar Questions

  • Execution plan will change if I use the variable binding instead of the literal value?

    Hi guys,.

    Suppose I have a select "... Of... WHERE ID = 2 and... "if I go to use the variable binding instead of the literal value 2," SELECT... " Of... WHERE ID =: p_id and... ", the execution plan change?
    I test multiple statements, the plan does not change, but I don't know if it would even as well as in some other cases.
    Someone at - it ideas?

    Thank you very much.

    Anneso wrote:
    Hi, sorry for the unclear post, it's 11 GR 2.

    As Sybrand already mentioned, there are a lot of change that came in the implementation of the bind variable in some versions of Oracle db. Since you're on 112, it is still true with the introduction of Adaptive Cursor Sharing . Please have a read on it since the post below written by the development of Oracle optimizer group.
    http://blogs.Oracle.com/optimizer/entry/why_are_there_more_cursors_in_11g_for_my_query_containing_bind_variables_1

    Aman...

  • Use sessionScope as the value of the Variable binding

    Dear all,

    I have a variable in sessionScope, and I want to use it as a condition of application of a ViewObject.

    I found a thread talking about, there's only one: (Re: set the value in the global variable. )
    How to use the value in the scope of session groovy script?

    Model project:
    Set variable in the scope of the session:
    ADFContext.getCurrent () .getSessionScope () .put ("Empno", empno);

    Getting value of session scope:
    Object empno is ADFContext.getCurrent () .getSessionScope () .get ("Empno");.

    ViewProject:
    Set variable in the scope of the session:
    FacesContext.getCurrentInstance () .getExternalContext () .getSessionMap () .put ("Empno", empno);

    Getting value of session scope:
    Object empno is FacesContext.getCurrentInstance () .getExternalContext () .getSessionMap () .get ("Empno");.

    Getting value of scope jspx page session
    #{sessionScope.Empno}

    Hi Samson,.

    Here are the groovy expression to access the value of the sessionscope:

    adf.context.sessionScope.role
    

    But, as the said John instead to access the session of the model can be a method of model (whether in AMImpl or voImpl) who takes the role as a parameter value and sets the value of the variable binding of the vo, then call this AM from the bean method passing the role value by getting the scope of the session.

    Jean Lou

  • The possibility of declaring the variable on request?

    Hello

    With the help of Oracle 9i. I'm new to the PL/SQL (coming from c#), I would like to know if it is possible to declare a variable around the where it is used. For example, in the execution of the procedure block, suppose I want to do:

    .. existing code...

    vTest whole;
    vTest: = 123;

    .. existing code (continued)...

    In doing so, the procedure could not compile. The only way I know to date is to declare the whole vTest. in the declaration block. Can you please let me know how to declare the variable in the body of the procedure?

    Thanks in advance.

    It is technically possible, but I wouldn't recommend it (I personally do not like this approach a LOT).

    ME_XE?create or replace procedure testin  2  as  3  4     vparamone   number default 123;  5  6  begin  7  8     declare  9        vparamtwo   number default 456; 10     begin 11        vparamone   := vparamtwo; 12     end; 13     dbms_output.put_line(vparamone); 14  end; 15  /
    
    Procedure created.
    
    Elapsed: 00:00:00.29ME_XE?exec testin;456
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:00.01ME_XE?
    
  • Declare the Variable step in a package

    Hello

    Is it obligatory to declare a variable in a package, even when we are refreshing or set the value of this variable in the package? What are the problems that occur in the case where a variable is not declared in the package?

    Please note that I understand that the variable must be romance in the package in case it is not be refreshed or set or incremented but is used by any step in the package.

    Thank you and best regards,

    PV

    Hi PV.

    You must declare a variable, unless it is explicitly used in the package to arm, refreshing or evaluate its value (as you mentioned).

    You must declare also specifically when:

    • You want its value to be passed during execution (runtime scenarios)
    • You want to use in the name of the resource to a data store in a scenario
  • How to set the value of the variable bind in VO on page load?

    Hello, I use JDeveloper 11.1.2.3.0.

    I created a VO in my application that uses a variable binding in the where clause. I want to put the value of this variable on the loading of the page automatically.

    I read that I can do this through setNamedWhereClauseParam()... but I can't find out where and how to use it.

    Can anyone help please?

    You can put in different places:

    AppModuleImpl,

    ViewObjectImpl,

    ViewRowImpl

    Just him export the customer interface and use whenever you want

  • [ORACLE 9] OPEN for the variable binding USING declaration

    Hello

    I have a loop that retrieves only 1 sheet instead of 7:
    DECLARE
    
     lv_into varchar2(40);
     lv_qry  varchar2(400);
     
     type curtest_ref is ref cursor;
     
     curtest          curtest_ref;
     lv_compteur number(4) := 1;
     
     lv_client_loc   varchar2(100);
     BEGIN
     dbms_output.put_line( 'Début' );
     lv_qry := 'select client_loc from tmp_jbm where client_id = :A ';
     
     open curtest for lv_qry using lv_compteur;                 
     loop
                    fetch curtest into lv_client_loc ;
                    exit when curtest%notfound;
                    dbms_output.put_line( 'ligne: '       || to_char( lv_compteur )
                                       || ' Client Loc: ' || lv_client_loc );
                    lv_compteur := lv_compteur + 1;
                    exit when lv_compteur > 6;
         end loop;
    EXCEPTION
        when others then
                 dbms_output.put_line( 'Erreur exception: ' || sqlerrm );
    END; 
    [/END CODE]
    
    It looks like the cursor only fetches 1 record and then stops.
    
    Many thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

    Bind variables are evaluated when the cursor is opened. Not when extract you the data.
    I don't know why you use dynamic sql, here, you do not need.
    In any case, your code is incorrect.
    Assuming that the client_id is unique, Yes, your fetch fetch one line. When you loop the second time, retrieving a new record for the same statement, then you hit no_data_found.

    ---------
    Sybrand Bakker
    Senior Oracle DBA

  • ADF where can I set the variable binding VO?

    I created VO with bind variable 'BPM_USER_NAME '.

    In VOImpl.java I have getter and setter:

    public void setBPM_USER_NAME (String value) {}

    ensureVariableManager () .setVariableValue ("BPM_USER_NAME", value);

    }

    I plugged my .jspx to BephorePhase - #{pageFlowScope.SimpleBean.beforePhase}

    My SimpleBean.java beforePhaseof the method:

    Public Sub beforePhase (PhaseEvent phaseEvent) throws SQLException {}

    If (phaseEvent.getPhaseId () == PhaseId.RENDER_RESPONSE) {}

    Logger.Warning ("InventoryIlliquid - BeforePhase");

    FacesContext fctx = FacesContext.getCurrentInstance ();

    AdfFacesContext = AdfFacesContext

    AdfFacesContext.getCurrentInstance ();

    Boolean isInitialRequest =! adfFacesContext.isPartialRequest (fctx);

    If {(isInitialRequest)

    OnLoad();

    System.out.println ("InventoryIlliquid - onload");

    }

    else System.out.println ("InventoryIlliquid - NO onload");

    }

    }

    public void onload() {}

    Nobody PersonIdVOImpl = new PersonIdVOImpl();

    person.setBPM_USER_NAME ("user");

    }

    I won't set my ' BPM_USER_NAME 'user' and after that my form will open see results. " Where should I write my code?

    What is the error you get?

    Are you viewCriteria assistance or a variable base of bind query?

    and do not write like this

    PersonIdVOImpl p = new PersonIdVOImpl(); / / use this. getPersonIdVo();

    p.setbpm_user_name ("username");

  • $a_report to refresh a report, but it is not picking up the variable binding

    Hello

    APEX - Express 4.1.0 Application
    Browsers - all
    Database - 11g 2

    I have a tree on a page region. When a user clicks on a leaf of the tree, I want to be able to use the ID to refresh a report in a different region on the same page

    Code for when the user clicks on the map

    $('div.tree_li_a').click (function() {}

    node_id = $(this).parents('li:first').attr ('id');

    If (node_id.substr (0, node_id.indexOf('|')) == 'Y')
    {
    $s ('P4_SELECTED_VALUE', node_id.substr (node_id.indexOf('|') + 1));
    Alert ("value: ' + $v ('P4_SELECTED_VALUE')");
    $a_report ('28576803999973770 ',' 1','20 ', ' 20');
    $a_report ($v ('P4_REPORT_ID'), '1','20 ', ' 20');
    };
    });

    SQL statement

    SELECT *.
    PRODS p WHERE PROD_CODE =: P4_SELECTED_VALUE

    The problem I have is that when the report is run (I know it's refreshing) the P4_SELECTED_VALUE of the link variable is null.

    Pop alert contains the correct value, and when I do the visible P4_SELECTED_VALUE it also contains the value?

    Any help is very appreciated

    Rob

    Rob,

    You insert P4_SELECTED_VALUE value in the APEX session before refreshing the report.

    Add following the JS function in your page

    //insert value into session using JS
    
    function fnSetSessionState(pItem, pValue) {
        var vAjaxDummy = new htmldb_Get(null, $v('pFlowId'), null, 0);
        vAjaxDummy.add(pItem, pValue);
        var vDummy = vAjaxDummy.get();
        vAjaxDummy = null;
    }
    

    and your code...

    $('div.tree li a').click( function() {
    
    node_id = $(this).parents('li:first').attr('id');
    
    if (node_id.substr(0,node_id.indexOf('|')) == 'Y')
    {
    $s('P4_SELECTED_VALUE',node_id.substr(node_id.indexOf('|')+1));
    alert('Value Set: ' + $v('P4_SELECTED_VALUE'));
    fnSetSessionState('P4_SELECTED_VALUE',$v('P4_SELECTED_VALUE'));
    //$a_report('28576803999973770','1','20','20');
    $a_report($v('P4_REPORT_ID'),'1','20','20');
    };
    });
    

    That's how I used the version 3.2 or earlier. But now I prefer to use declarative dynamic actions...

    Kind regards
    Hari

  • Declare the variable in the loop or abroad?

    What is the smartest, if the statement is a loop much like 100000. Is there a difference?

    * for(int i = 0; i < 100000; i++) {*}
    Dim myStr = getSomething();
    *}*

    or

    Dim myStr = "";
    * for(int i = 0; i < 100000; i++) {*}
    myStr = getSomething();
    *}*

    No, there is no performance difference (that's what you thought, weren't you).

    The basic rule by declaring variables is "the smallest scope possible. So in this case inside the loop for.

  • declare the variable

    I started warning after running this code.
    He says that this line variable has no type declaration.
    What should I do? This is the code-->

    I suggest you break it down and focus on the creation of the table of the lines before trying to move on as follows

    var myText:String = myText.text
    var myTextArr = myText.toString().split(/[\r\n]/g)
    trace (myTextArr.Length) / / should give you a count of all rows...

    / [\r\n]/g - is a regular exp that looks like for each newline character in the string that was created programmatically using \r to represent the newline

    You can also try variations of the rational expression until you get the number of rows, that you expect.

    / [\r\n]{1,2}/g - resembles a minimum of 1 and a maximum of 2 line breaks

    As a beginner, you have a hard work in front of you, I know it can get frustrating but trial and error is the search of google and way only for examples. Sample analysis weblogs out there he wrote too much already, a lot of developers is the willingness to help but little do not have the time to write the code for you. I recommend you read about regular Expressions too that they are an essential part of any directory of programmers

  • using the variable binding

    drop table tab purge;
    create table tab (number x, y varchar2 (5));
    Insert tab values(1,'rr');
    Insert tab values(2,'rr');
    Insert tab values(3,'rr');
    Insert tab values(4,'rr');
    commit;
    create or replace PROCEDURE get_data (p_data ON SYS_REFCURSOR,
    P_ID IN varchar2)
    is
    sql_str varchar2 (100): = ' SELECT * FROM tab WHERE. X IN (: x)';
    Start
    Open p_data
    for sql_str
    using p_id;
    end;
    /

    SET SERVEROUTPUT ON

    VAR A REFCURSOR
    VAR B VARCHAR2 (1000)

    EXEC get_data (: one, '3', 4);

    PRINT

    following error, so that the value of product produced no arrow.
    -------------------------
    ERROR:
    ORA-01722: invalid number
    -------------------------

    Here the implicit conversion does not work, and '3.4' is considered a stgring rather 2 separate values. I have to have to use bind variable and do not want to use dbms_sql. Is it possible, '3,4' is taken as 2-digit values, rather a string value helps Pl, thanks.

    You cannot use list as a bind variable. Use:

    SQL> create or replace PROCEDURE get_data (p_data IN OUT SYS_REFCURSOR,
      2  p_id IN varchar2)
      3  is
      4  sql_str varchar2(100) := 'SELECT * FROM tab WHERE tab.X IN (' || p_id || ')';
      5  begin
      6  open p_data
      7  for sql_str;
      8  end;
      9  /
    
    Procedure created.
    
    SQL> SET SERVEROUTPUT ON
    SQL>
    SQL> VAR A REFCURSOR
    SQL> VAR B VARCHAR2(1000)
    SQL>
    SQL> EXEC get_data(:A, '3,4');
    
    PL/SQL procedure successfully completed.
    
    SQL>
    SQL> PRINT A
    
             X Y
    ---------- -----
             3 rr
             4 rr
    
    SQL> 
    

    Or, if you want to use bind variable, use the composite type. Something like:

    SQL> create or replace
      2    type NumberList
      3      as table of number
      4  /
    
    Type created.
    
    SQL> create or replace PROCEDURE get_data (p_data IN OUT SYS_REFCURSOR,
      2  p_id IN NumberList)
      3  is
      4  sql_str varchar2(100) := 'SELECT * FROM tab WHERE tab.X member of :x';
      5  begin
      6  open p_data
      7  for sql_str
      8  using p_id;
      9  end;
     10  /
    
    Procedure created.
    
    SQL> SET SERVEROUTPUT ON
    SQL>
    SQL> VAR A REFCURSOR
    SQL> VAR B VARCHAR2(1000)
    SQL>
    SQL> EXEC get_data(:A, NumberList(3,4));
    
    PL/SQL procedure successfully completed.
    
    SQL> PRINT A
    
             X Y
    ---------- -----
             3 rr
             4 rr
    
    SQL> 
    

    SY.

  • ViewObject accesses the variable binding a sessionScope setting?

    Hello

    using the Fusion of ADF Jdev11g request
    ViewObject get a sessionScope parameter and set in the binding variable? without the help of executeWithParameter

    Thank you
    greenApple

    N °

    You must call a method in the model layer and pass the parameter.

    Timo

  • read the value of the variable binding

    Hello

    I was debugging a java application and in the process, I wanted to know what values the request as a bind variable. So, I checked v$ sql_bind_capture and activated the trace on the session. Unfortunately the data type is TIMESTAMP, so the view did not show a value and I got the trace was a memory dump that is not helpful for me:
     Bind#1
      oacdty=180 mxl=11(11) mxlc=00 mal=00 scl=00 pre=00
      oacflg=03 fl2=1000000 frm=01 csi=873 siz=0 off=24
      kxsbbbfp=fffffd7ffdb6fbd0  bln=11  avl=07  flg=01
      value=
    Dump of memory from 0xFFFFFD7FFDB6FBD0 to 0xFFFFFD7FFDB6FBD7
    FFFFFD7FFDB6FBD0 0D0B6C78 00010101                    [xl......]
    Is there a function/method to convert a timestamp or at least vice versa?

    Just run this little test:

    SQL> CREATE TABLE t (c1 TIMESTAMP);
    
    Table created.
    
    SQL> INSERT INTO t VALUES (TRUNC(SYSTIMESTAMP));
    
    1 row created.
    
    SQL> COMMIT;
    
    Commit complete.
    
    SQL> SELECT TO_CHAR(c1) FROM t
      2  UNION
      3  SELECT DUMP(c1) FROM t;
    
    TO_CHAR(C1)
    --------------------------------------------------------------------------------
    13-NOV-08 00.00.00.000000
    Typ=180 Len=7: 120,108,11,13,1,1,1
    

    Convert decimal to hex you gives 78, 6 C, 0, 0 D, 01, 01, 01 what byte order accountant reverse is the same as your memory dump. So I think the bind value is 00:00:00:000000 November 13, 2008.

    Not very well how to recover of the hexagon directly at the time, but I do not know someone knows!

    In fact, Google has been very helpful... take 100 on the first two decimal values: 120-100 = 20; 108-100 = 08, to give you the year: 2008. Then 11 and 13 are the month and day. The rest is hour + 1 minute + 1, the second + 1. So just convert your hex decimal and you should be able to discern the value!

    Published by: Mike Pargeter 13 November 2008 16:54

  • Declare the Variable global server which can be accessed in all reports

    Hello

    We use submodels that are imported in the model using:
    <? import: file: / / / D: / < path > / HeaderFooter.rtf? >

    I would like to have dynamics can see it, so that in case of change of the way, I have just
    Change it to the same place. I heard it is possible to define server variables in bi publisher who
    are available in all models?

    If so someone can tell me how to do this? or is there another way?

    would be very happy to advise.

    Thank you very much!

    Check out the following blog: http://bipconsulting.blogspot.com/2009/11/common-header-and-footer-with-sub.html

    Thank you!

Maybe you are looking for

  • Windows on Macbook 2009 10

    Hello I've updated to 10 Windows on my MacBook. The installation process has worked well, and I was able to use Windows yesterday. However, off the computer for the first time after the upgrade, I can't past the ctrl + alt + del window when I try to

  • PAGE_FAULT_IN_NONPAGED_AREA error, I can't yet start windows in safe mode, I can't really afford to lose everthing on my laptop

    I get error page_fault_in_nonpaged_area, I can not even to start windows in safe mode, I can't really afford to lose everthing on my laptop, it did not come with any disk, I have not installed new hardware, only the new software is Google Chrome with

  • Service Pack 3 window

    I get an alert of almost every day that the updates are ready for my computer. This update is for Windows Service Pack 3. When I click 'Download' the alert box goes, but nothing is downloaded.  I'm stuck with Service Pack 2. Any suggestions?

  • Help new issues Tophology to Config?

  • Audio Jack

    I bought the new dell vostro 5470 and the 3.5 mm jack earpiece not to get in shape in it so can anyone please advice me what is the size of the audio input jack. Thank you.