Problem with bind in Execute Immediate

Hi all

Scenario 1:
It works very well.
DECLARE
  V VARCHAR2(20) := ':X';
  X VARCHAR2(20) := 'Hello World';
  RES VARCHAR2(20);
  QRY VARCHAR2(100);
BEGIN
  QRY := 'SELECT '||V||' FROM DUAL';
  EXECUTE IMMEDIATE QRY INTO RES USING X;
  DBMS_OUTPUT.PUT_LINE(RES);
END;
Scenario 2:
DECLARE
  V VARCHAR2(20) := 'X';
  X VARCHAR2(20) := 'Hello World';
  RES VARCHAR2(20);
  QRY VARCHAR2(100);
BEGIN
  QRY := 'SELECT '||V||' FROM DUAL';
  EXECUTE IMMEDIATE QRY INTO RES USING X;
  DBMS_OUTPUT.PUT_LINE(RES);
END;

Error:
X invalid identifier. 
Necessary 'X' as the output.

I could do to make it works very well for both scenarios with small changes in the code?

My code can't handle scenario 2.

You can change to sth as follows:

SQL> declare
  v     varchar2 (20) := 'X';
  x     varchar2 (20) := 'Hello World';
  res   varchar2 (20);
  qry   varchar2 (100);
begin
  qry := 'SELECT ' || case when v not like ':%' then ':' end || v || ' FROM DUAL';

  execute immediate qry into res using case when v not like ':%' then v else x end;

  dbms_output.put_line (res);
end;
/
X
PL/SQL procedure successfully completed.

SQL> declare
  v     varchar2 (20) := ':X';
  x     varchar2 (20) := 'Hello World';
  res   varchar2 (20);
  qry   varchar2 (100);
begin
  qry := 'SELECT ' || case when v not like ':%' then ':' end || v || ' FROM DUAL';

  execute immediate qry into res using case when v not like ':%' then v else x end;

  dbms_output.put_line (res);
end;
/
Hello World
PL/SQL procedure successfully completed.

Tags: Database

Similar Questions

  • 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

  • Problems with Bind Variables

    SELECT co.ref_num, co.forename, co.surname, co.dob, a.address, a.postcode,
           co.ni_num
      FROM address a, contact co
     WHERE co.ref_num = a.ref_num
       AND (:1 IS NULL OR co.forename = :2)
       AND (:3 IS NULL OR co.surname = :4)
       AND (:5 IS NULL OR a.postcode = :6)
       AND (:7 IS NULL OR a.address = :8)
       AND (:9 IS NULL OR co.dob = :10)
       AND (:11 IS NULL OR co.ni_num = :12)
    With a jdbc connection, we use a web front end for a new management system. The SQL above runs since a search screen. We meet a few serious problems with bind variable and execution plans. When the above query is sent by the database 'AND' clauses could evaluate as follows:
    AND ('Tim' IS NULL OR co.forename = 'Tim')
       AND ('Clarke' IS NULL OR co.surname = 'Clarke')
       AND ('' IS NULL OR a.postcode = '')
       AND ('' IS NULL OR a.address = '')
       AND ('25051981' IS NULL OR co.dob = '25051981')
       AND ('' IS NULL OR co.ni_num = '')
    We cannot dynamically assign 'AND' conditions so they are sent through to the database. This translates FTS 99% of the time as the execution plan never prescribed any of the available indices.

    Someone has suggestions on how to better 'control' bind variables?

    Hello

    Don't you think that 'OR' Conditions are necessary to check for Null, where the binding variable is NULL or not.

    I think that rather than running the query from the front to FB, try to convey the values of some MS and run this query in the procedure, the extraction from the point of view Design coding application. Never fire the query of the frontal part.

    To come to the problem.

    SELECT co.ref_num, co.forename, co.surname, co.dob, a.address, a.postcode,
    Co.ni_num
    ADDRESS, contact co
    WHERE co.ref_num = a.ref_num
    AND (: 1 co.forename IS NULL or =: 2)
    AND (: 3 co.surname IS NULL or =: 4)
    AND (: 5 a.postcode IS NULL or =: 6)
    AND (: 7 a.address IS NULL or =: 8)
    AND (: 9 co.dob IS NULL or =: 10)
    AND (: 11 co.ni_num IS NULL or =: 12)

    Use the procedure.

    Fact exits of the indexes on the tables and stats are updated...?
    Try to predict explain it. ??

    -Pavan Kumar N

  • Problems with tdms built executable; memory.cpp write error

    Hello

    I have a problem with writing tdms files in bed which executable, that I created with the Builder application in LabView 8.2.1.

    I created a small requesting readings some channels in the DAQmx. This schould results written in a PDM file. All this happens within a while loop, even the steps open-entry-closing-PDM.

    This test in the development environment everything is fine. But if I create an executable file and try this on the same and other computer, I received an error warning.

    The error that says: error on line 342, memory.cpp

    Is there anyone who has any idea what is the problem? What I have to insert something in the creation of PDM application designer?

    best looks, T.Malec

    The problem of TDMS is special to 8.20. However, you cannot run the executable with a new runtime, because the compiled code is not compatible between major releases (example: code compiled with 8.5.0 will run on 8.5.1, but not on 8.6.x).)

    Herbert

  • Problem with Binder

    There is something wrong with my hyperlink social media, when I publish my Web site that that work not, but they do not work in preview mode.

    It only my twitter I seem to have problems with. I'm very new with Muse and could really do with some help.

    Hi, you can publish the site to a temporary site of the BC for us to have a look on.

    Or if it's the Twitter feed widget displays do not, then you might want to check this.

    http://forums.Adobe.com/message/4725856#4725856

    Thank you

    Vinayak

  • Problem in Using of EXECUTE IMMEDIATE clause

    Hello
    I tried using using the clause, but am getting an error. Any help is welcome.

    Here is the code

    declare
    number of g_salary;
    v_stm varchar2 (100);
    Start
    v_stm: = "insert into emp (empno, deptno, sal) values (: 1,: 2: 3)"; "
    execute immediate v_stm using empno, sal, deptno;
    end;


    Here is the error message

    ERROR on line 1:
    ORA-06550: line 6, column 31:
    PLS-00201: identifier 'EMPNO' must be declared.
    ORA-06550: line 6, column 1:
    PL/SQL: Statement ignored

    You must provide values that must be inserted into the table.
    something like

    declare
       g_salary number ;
       v_stm varchar2(100);
    begin
       v_stm := 'insert into emp (empno, deptno, sal) values (:1, :2, :3)';
       execute immediate v_stm using 10, 20, 30;
    end;
    

    not tested

  • Relationship between the objects in view with bind variable executed by program

    Hello

    I am trying to create a view link between two objects in view that are query based something like this:

    firstVO

    1. Select P1 in XXX_Table where P2 =: BindVariable1 and

    P3 =: BindVariable2;

    secondVO

    2. Select B1, B2, B3, B4, 1 m env in YYY_Table where B5 =: BindVariable1 and

    B6 =: BindVariable2 and

    B7 =: BindVariable3;

    concatenation of a string of the query above in AMImpl as 'and B8 in ('P1.a', 'P1.b', 'P3.c')' in the AMImpl

    I will execute queries above, based on the variable bind entered by the user in the AMImpl.

    I need to create a link to firstVO.P1 and secondVO.P1 with a 1-based view to * cardinality.

    the problem is when I try to drop the secondVO which is an accessor to the firstVO as a master-child relationship with master table form and as a child, I don't see the details of the child when I iterate the master shape.

    I got my problem solved, the problem was that the master and the children were not in the sink, we can define the child VO by substituting preparerowsetforquery... explained clearly in the post below.

    Thank you

    Jobinesh

    Binary: Defining the value of variable binding for the destination View object in the link display

  • Problem with bind variable and as operator usage

    Hi all

    I use JDeveloper Version - 11.1.2.4.39.64.36.1 .


    While implementing the search functionality in the hierarchical Viewer, I created a link in the underlying t variable, created to find, due east of the request-


    SELECT XxamAnkitObjects.ID,

    XxamAnkitObjects.OBJECT_NAME,

    XxamAnkitObjects.OBJECT_TYPE,

    XxamAnkitObjects.PARENT,

    XxamAnkitObjects.PARENT_ID,

    XxamAnkitObjects.PARENT_TYPE

    OF XXAM_ANKIT_OBJECTS XxamAnkitObjects

    WHERE object_name like ' %: o_name ".

    What I'm trying to accomplish here, it is that the input provided by the user in the search box must match with the object_name in the table.

    During execution, I met the following error (from newspapers WLS)-

    < QueryCollection > < buildResultSet > [598] java.sql.SQLException: try to set a parameter name that does not intervene in the SQL: o_name

    at oracle.jdbc.driver.OraclePreparedStatement.setNullAtName(OraclePreparedStatement.java:5384)

    at oracle.jdbc.driver.OraclePreparedStatementWrapper.setNullAtName(OraclePreparedStatementWrapper.java:1451)

    The following query has been generated during the operation of a research-

    < ViewObjectImpl > < buildQuery > [593] SELECT XxamAnkitObjects.ID, XxamAnkitObjects.OBJECT_NAME, XxamAnkitObjects.OBJECT_TYPE, XxamAnkitObjects.PARENT, XxamAnkitObjects.PARENT_ID, XxamAnkitObjects.PARENT_TYPE XXAM_ANKIT_OBJECTS XxamAnkitObjects WHERE object_name like ' %: o_name ".

    < ViewObjectImpl > < bindParametersForCollection > [594] params for ViewObject Bind: [model.vo.ObjectNameSearch] AppModule.ObjectNameSearch1

    Advice kindly the way ahead.

    Best regards

    Ankit Gupta

    The problem is that you used quotes around the variable binding. Try

    SELECT XxamAnkitObjects.ID,
           XxamAnkitObjects.OBJECT_NAME,
           XxamAnkitObjects.OBJECT_TYPE,
           XxamAnkitObjects.PARENT,
           XxamAnkitObjects.PARENT_ID,
           XxamAnkitObjects.PARENT_TYPE
    FROM XXAM_ANKIT_OBJECTS XxamAnkitObjects
    WHERE object_name like '%' || :o_name || '%'
    

    A note: this type of query will do a full table scan, as the searches with wildcards to the left cannot use a regular index. If you have multiple lines, this will impact on the research persormance hughe!

    Timo

  • Problem with NI Switch Executive - test Panel

    NI Switch Executive - Test Panel, I connect routes I created previously, which are then displayed to connected, without error. However, the corresponding relay is not activated (what I mean by monitring DMM). Using NOR-SWITCH Soft Front Panel, I can make the same connections and everything works fine, no idea why connections are not deployed in the Test Panel?

    Here is what I use:

    PXI-1033 on a PCIe bridge

    Matrix 4 x 32 PXI-2530 switch on slot 3

    PXI-4071 DMM on slot 2

    Hi DeadMeat,

    Looks like the NI PXI-2530 is simulated in the IVI configuration.

    OR Switch devices Executive virtual peripheral references by their logical names.  Each logical name to a Session links pilot Max (Measurement & Automation Explorer).  A setting in the pilot Session allows you to simulate a device.

    I recommend to open MAX, expand the IVI Drivers > driver and check the general tab that the fake it with the drop-down list selection is set to do not simulateSessions.

    I hope this helps!

    Chad Erickson

    Switch Product Support Engineer

    NOR - USA

  • Problem with binding components of fragments of page in bean managed when rendered as region

    I detected a problem when I bind a component in a managed bean for a page fragment which is a view of a TaskFlow exposed to JSF as a region.


    This problem happened when I exhibited same TaskFlow as region of two or more instances in the same Joint Strike Fighter. The component that is only returned in the latter region.


    JDeveloper 12 c (12.1.2.0) ADF12c.

    This is the code:

    The page fragment:

    <?xml version='1.0' encoding='UTF-8'?>
    <ui:composition xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
      <af:panelGroupLayout id="pgl1">
        <af:inputText label="Label 1" id="it1" binding="#{bindingComponentBean.inputText}"/>
        <af:button text="button 1" id="b1"/>
      </af:panelGroupLayout>
    </ui:composition>
    

    Bean managed (within the scope of the request)

    package com.edisa.test.errors.view.backing;
    
    
    import oracle.adf.view.rich.component.rich.input.RichInputText;
    
    
    public class BindingComponentBean {
        private RichInputText inputText;
    
    
        public BindingComponentBean() {
        }
    
    
        public void setInputText(RichInputText inputText) {
            this.inputText = inputText;
        }
    
    
        public RichInputText getInputText() {
            return inputText;
        }
    }
    

    TaskFlow

    <?xml version="1.0" encoding="UTF-8" ?>
    <adfc-config xmlns="http://xmlns.oracle.com/adf/controller" version="1.2">
      <task-flow-definition id="TestTaskFlow">
        <default-activity>test_fragment</default-activity>
        <managed-bean id="__1">
          <managed-bean-name>bindingComponentBean</managed-bean-name>
          <managed-bean-class>com.edisa.test.errors.view.backing.BindingComponentBean</managed-bean-class>
          <managed-bean-scope>request</managed-bean-scope>
        </managed-bean>
        <view id="test_fragment">
          <page>/fragments/test_fragment.jsff</page>
        </view>
        <use-page-fragments/>
      </task-flow-definition>
    </adfc-config>
    

    JSF page

    <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE html>
    <f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
        <af:document title="index.jsf" id="d1">
            <af:form id="f1">
                <af:pageTemplate viewId="/oracle/templates/threeColumnTemplate.jspx" id="pt1">
                    <f:facet name="center">
                        <af:panelGridLayout id="pgl1" inlineStyle="border: 1px solid #eee;">
                            <af:gridRow marginTop="5px" height="auto" marginBottom="5px" id="gr1">
                                <af:gridCell marginStart="5px" width="50%" id="gc1" inlineStyle="border: 1px solid #eee;"
                                             halign="stretch">
                                    <af:panelBox text="Region 1" id="pb1">
                                        <f:facet name="toolbar"/>
                                        <af:region value="#{bindings.TestTaskFlow2.regionModel}" id="r2"/>
                                    </af:panelBox>
                                </af:gridCell>
                                <af:gridCell marginStart="5px" width="50%" marginEnd="5px" id="gc2"
                                             inlineStyle="border: 1px solid #eee;" halign="stretch">
                                    <af:panelBox text="Region 2" id="pb2">
                                        <f:facet name="toolbar"/>
                                        <af:region value="#{bindings.TestTaskFlow1.regionModel}" id="r1"/>
                                    </af:panelBox>
                                </af:gridCell>
                            </af:gridRow>
                        </af:panelGridLayout>
                    </f:facet>
                    <f:facet name="header"/>
                    <f:facet name="end"/>
                    <f:facet name="start"/>
                    <f:facet name="branding"/>
                    <f:facet name="copyright"/>
                    <f:facet name="status"/>
                </af:pageTemplate>
            </af:form>
        </af:document>
    </f:view>
    

    Component to bind to the support extended to bean bean would be.

    In fact, it is solely to support the scope of the bean - to distinguish two or more instances of the page fragment component.

    It has the same duration of life as the requestScope, but for different instances of the components parts / declarative, you have separate instances of scope backingBean controlled beans.

    http://adfpractice-Fedor.blogspot.com/2012/03/managed-bean-scopes-for-page-fragments.html

  • Problem with Bind variable cannot be changed.

    Hi all
    I use Jdev 11.1.2.3.0. In my VO, I created a Bind Variable and set it NOT UPDATABLE. Then, I created a display with some other Variables Bind criterion.
    I use this criterion to display on a search page, but when running, I see also an inpunt for the defined variable NOT UPDATABLE text and I can't change its value.
    Of course, if I try to change the value, and I do research, I get an error.

    It is the source of the VO:

    < variable
    Name = "UlssVar".
    Type = "where".
    Type = "Java.lang.String"
    IsUpdateable = "false" >
    < TransientExpression > <! [CDATA [adf.context.current.sessionScope.get ('ulss')]] > < / TransientExpression >
    < / variable >

    Is this a bug of the ADF?
    I thank in advance.

    Hello

    try selecting the variable binding and open the property inspector, under the guidance of the user interface, set the flag of 'view' to hide. This should hide it (no bug for this reason)

    Frank

  • Creating symbols double-problem with binding

    Hi team,

    I created this insanely complex deployment menu with buttons, tweens with dynamic text lables - you name it... now I want to doublonnait of this symbol and changes its color to make a new tab menu, but when I try to do it (by going in there and by duplicating each part nested - I get an error of linkage -

    * WARNING * the binding identifier "Symbole1" was already assigned to the symbol ' symbol 2' and impossible to assign to the symbol ' symbol 1', because the link identifiers must be unique. "

    SO where can I find it and how do I do it please?

    Thanks for your help,

    void

    Binding identifiers are found in signs of properties/Assembly of the objects in the library.  If you right-click one of the symbols of the library in question, you should see an option to establish links in the offerings that appear.  This liaison Panel is a high school of the Properrties Panel for this library object (you can open the same way by selecting properties instead of Assembly.

  • Problems with binding on scrollPosition atribute

    Hello

    I'm having some trouble to implement the binding between a painting and a list.

    When I scroll vertically through the Web, the list scrolls, but the elements make as it should.

    The canvas are the same size from the list.

    I created a quick example to show what the problem is.

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
         layout="absolute"
         backgroundColor="0xFFFFFF"
         creationComplete="addRandomItems()">
         
         <mx:Script>
              <![CDATA[
                   import mx.collections.ArrayCollection;
                   import mx.utils.ObjectUtil;
                   
                   private function addRandomItems():void {
                        var provider:ArrayCollection = new ArrayCollection();
                        
                        for (var i:int = 0; i < 100; i++){
                             var o:Object = new Object();
                             var children:Array = [];
                             var incYear:int = 0;
                             
                             incYear += i % 2 == 0 ? 1 : 0; 
                             
                             o.description = "Teste " + i ;
                             
                             for (var j:int = 0; j < 3; j++){
                                  var xyz:Object = new Object();
                                  
                                  do {
                                       xyz.startDate = new Date(2008 + incYear , Math.random()*10, Math.random()*31);
                                       xyz.endDate = new Date(2008 + incYear, Math.random()*11, Math.random()*31);
                                       xyz.color = Math.random() * 0xFFFFFF;
                                       
                                       if (xyz.startDate.date == 31 && xyz.startDate.month == 11){
                                            xyz.startDate.date++;
                                       }
                                       
                                       if (xyz.endDate.date == 31 && xyz.endDate.month == 11){
                                            xyz.endDate.date++;
                                       }
                                  } while (ObjectUtil.dateCompare(xyz.startDate, xyz.endDate) != -1 );
                                  
                                  children.push(xyz);                              
                             }
                             
                             o.children = children;
                             provider.addItem(o);
                        }
                        descriptionList.dataProvider = provider;
                   }
              ]]>
         </mx:Script>
         
         <mx:List id="descriptionList"
              x="10" 
              y="10" 
              height="738"
              width="300"
              rowHeight="25"
              labelField="description" 
              horizontalScrollPolicy="off" 
              verticalScrollPolicy="off" 
              verticalScrollPosition="{viewer.verticalScrollPosition}"/>
         
         <mx:Canvas id="viewer" x="318" y="10" width="840" height="738">
              <mx:Canvas height="2500" width="2500" />
         </mx:Canvas>
         
         
    </mx:Application>
    

    Kind regards

    Fredy.

    Hi, Freddy

    Here is the solution:

    On the Web, create the updateComplete (event) method.

    private void updateComplete(evt:ScrollEvent):void {}

    If (evt.direction == ScrollBarDirection.VERTICAL) {}
    var p: Number;
    % = (100 * viewer.verticalScrollPosition) / viewer.maxVerticalScrollPosition;
    descriptionList.verticalScrollPosition = (descriptionList.maxVerticalScrollPosition * %) / 100;
    descriptionList.dataProvider.refresh ();

    }
    }

    When you scroll the canvas, the list scrolls.

    The problem is because the viewer.verticalScrollPosition is greater than the list.

    You must make a percentage.

    Thank you!

  • Problem with on (rollOut) executed

    We want to create an effect on a clip that starts when the mouse is over it ends (and returns to its initial state) when the mouse goes.
    We did, but we still have a problem. If the user is moving the mouse, the event of we (rollOut) does not work properly and so the clip is not the starting point.

    If some of you had the same? Can you help me?

    Thank you very much

    We can view the code where it would be useful

    I'm sorry but I have not read all the previous posts on this issue. Now, I found the asnwer in this topic:

    http://www.Adobe.com/cfusion/webforums/Forum/MessageView.cfm?forumid=15&CATID=288&ThreadId = 1230799 & highlight_key = y & keyword1 = deployment

    Thank you very much anyway.

  • problem with binding breadsticks

    I have a page contains two jsff, dragged and dropped as a region.
    I want to get the link of the other jsff container while I'm in the first jsff.
    The jsff contains form and some components of text input and checkbox component.

    This I have done it before, but in this case the other jsff was an array element.
    I wrote this code to get the link container:

    RicheTableau deptable = (RichTable) ADFUtil.findComponentInRoot ("deptTable");
    Model CollectionModel = (CollectionModel) deptable.getValue ();
    JUCtrlHierBinding employeesTableBinding = (JUCtrlHierBinding) model.getWrappedData ();
    DCBindingContainer dcbindings = employeesTableBinding.getBindingContainer ();
    OperationBinding operationBinding = dcbindings.getOperationBinding("ExecuteWithParams");

    How to get the link container when I do not have a component of the table, but a layout of the form that contains some entries texts and boxes.

    http://download.Oracle.com/otn_hosted_doc/JDeveloper/11gdemos/ADF-region-interaction/ADF-region-interaction.html
    http://download.Oracle.com/otn_hosted_doc/JDeveloper/11gdemos/AdfInsiderContextualEvents/AdfInsiderContextualEvents.html

Maybe you are looking for

  • How to retrieve a letter that I wrote about Wordpad. I recorded it, now I can't find it.

    Yesterday, I wrote a letter on Wordpad. I saved it, but now I can't the extractor it.

  • Programs of study

    I'm looking for more information about Windows Server R2 for classroom use. What programs are available for the implementation of a PC with Windows Server R2 2012 classroom. I have about 20 students for two classes of accreditation of certification.

  • PIXMA 180 has lost driver for scanner - what can I do?

    I lost the driver for the scanner, I have a pixma 180.  Tried to use the CD, but computor would not read. I'm not gifted in computor so I am at a loss.

  • Training suggestions

    Could someone provide a suggestion for the best bang for the buck when it comes to training Cisco Telepresence?  I'm thinking 1 or 2 week long course. I worked a lot with Polycom solutions but do not have a lot of hands on experience with Cisco platf

  • Limited number of app in the store

    I use a full update preloaded Windows 8 pro 64-bit on a touch of carbon lenovo x 1 with full access to all my account settings.   I get only showed a limited number of app in the store. for example, only 3 in the category economy and two in the healt