2 Replies Latest reply: Dec 21, 2011 10:11 AM by rp0428 RSS

    Variable 'per' not in scope error

    vviswana
      HI,

      The below code fails with 'Detail: variable 'per' not in scope ' error. Can somebody help me in fixing that..

      String xq = "declare variable $per1 as document-node(element(*, xs:untyped)) := " +
      "fn:parse-xml($per);" +
      "declare variable $job1 as document-node(element(*, xs:untyped)) := fn:parse-xml($job);" +
      "for $i in $per1//pimergednodes/Get__CompIntfc__CI_PERSONAL_DATAResponse,\n" +
      " $j in $job1//jobmergednodes/Get__CompIntfc__CI_JOB_DATAResponse[PROP_EMPLID = $i/PROP_EMPLID]\n" +
      "\n" +
      " return\n" +
      " <emp>\n" +
      " {\n" +
      " $i/PROP_EMPLID,\n" +
      " $i/PROP_BIRTHDATE,\n" +
      " <coll_names>\n" +
      " {\n" +
      " $i/COLL_NAME_TYPE_VW/COLL_NAMES\n" +
      " }\n" +
      " </coll_names>,\n" +
      "\n" +
      " $i/PROP_BIRTHDATE/COLL_NAME_TYPE_VW/PROP_FIRST_NAME,\n" +
      " $j/COLL_JOB/PROP_DEPTID\n" +
      "\n" +
      " }\n" +
      " </emp>";

      XQDataSource xds = new oracle.xquery.xqj.OXQDataSource();
      XQConnection conn = xds.getConnection();
      XQPreparedExpression pEx = conn.prepareExpression(xq); -> error raised in this call.

      Thanks In Advance,
      Vidya
        • 1. Re: Variable 'per' not in scope error
          tsuji
          Looking at it, I think this is pretty much a retrograde from the previous related thread.
          Passing variable in fn:doc

          [1] If you look at the prolog part, it is obvious that $per is not declared and is bound to nothing... Similarly for $job. If you want to do that, you can add that declaration to bind them and let the xquery itself to load the source document, something like this.
          String xq = "declare variable $per as xs:string := 'file:///c:/personal.xml';\n" +
            "declare variable $job as xs:string := 'file:///c:/job_info.xml';\n" +
            "declare variable $per1 as document-node(element(*, xs:untyped)) := " +
            " etc etc...";
          [2] Now, you can simply load and parse the persistent xml source document using doc() funtion. No need anything more than that.
          String xq = "etc etc..." +
            "declare variable $per1 as document-node(element(*, xs:untyped)) := doc($per);\n" +
            "declare variable $job1 as document-node(element(*, xs:untyped)) := doc($job);\n" +
            "etc etc...";
          [3] If you want to use document-node() inside the xquery and have them $per and $job being declared external like the structure you used in the related link above, you sure can do that. Only that, this time you are not using bindNode() but other appropriate binding methods, that's all.

          Edited by: tsuji on Dec 21, 2011 9:05 AM (Edited a typo on doc1($job) delinquent character "1".)
          • 2. Re: Variable 'per' not in scope error
            rp0428
            The part of your code that says "fn:parse-xml($per);" refers to '$per' when it should refer to '$per1'.