1

I have created a multiversioned view in Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production. I can access a specific version using a SQL script in SQL Developer. However, using other tools, I can only access DEFAULT.

The following script works fine:

call sde.version_util.set_current_version('MY_VERSION');
select * from mv_my_view;

Encapsulating this logic inside an Oracle View (something similar to Jay Cummins' answer to this question would be a great solution, but I cannot see a way to put a call inside a view).

In Crystal Reports, I can add SDE.VERSION_UTIL.SET_CURRENT_VERSION as a table, but cannot use it to set the version. If I specify a known good version, I get a Query Engine Error: 'Cannot obtain error message from server.'

In contrast, if I specify a non-existent version (with a typo, for example), I get an 'HY000:[Oracle][ODBC][ORA]ORA-20126: Version x not found... ORA-06512'

How can I set the current version to something other than DEFAULT for tabular reporting purposes - either in an Oracle View, or using Crystal Reports, or using some other tool?

0

The key is to build a function that returns a result set that can be queried as if it were a table. In the function, include a call to set_current_version (see line 6 below).

SQL> create type emp_obj is object (empno number, ename varchar2(10));
  2  /

Type created.

SQL> create type emp_tab is table of emp_obj;
  2  /

Type created.

SQL> create or replace function all_emps return emp_tab
  2  is
  3     l_emp_tab emp_tab := emp_tab();
  4     n integer := 0;
  5  begin
  6     sde.version_util.set_current_version('ALT_VERSION')
  7     for r in (select empno, ename from emp)
  8     loop
  9        l_emp_tab.extend;
 10        n := n + 1;
 11       l_emp_tab(n) := emp_obj(r.empno, r.ename);
 12     end loop;
 13     return l_emp_tab;
 14  end;
 15  /

Function created.

SQL> create or replace view ALT_VER_VIEW as select empno, ename from table (all_emps);

View ALT_VER_VIEW created.

SQL> select * from alt_ver_view;

     EMPNO ENAME
---------- ----------
      7369 SMITH
      7499 ALLEN
      7521 WARD
      7566 JONES
      7654 MARTIN
      7698 BLAKE
      7782 CLARK
      7788 SCOTT
      7839 KING
      7844 TURNER
      7902 FORD
      7934 MILLER

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["-item\"><a href=\"https://twitter.com/stackoverflow\" class=\"-link js-gps-track\" data-gps-track=\"footer.click({ location: 2, link: 32 })\">Twitter</a></li>\r\n                    <li class=\"-item\"><a href=\"https://linkedin.com/company/stack-overflow\" class=\"-link js-gps-track\" data-gps-track=\"footer.click({ location: 2, link: 33 })\">LinkedIn</a></li>\r\n                </ul>\r\n\r\n                <p class=\"mt-auto mb24\">\r\nsite design / logo &#169; 2019 Stack Exchange Inc; user contributions licensed under <a href=\"https://creativecommons.org/licenses/by-sa/3.0/\" class=\"js-gps-track\" data-gps-track=\"footer.click({ location: 2, link: 34 })\" rel=\"license\">cc by-sa 3.0</a>\r\n                            with <a href=\"https://stackoverflow.blog/2009/06/25/attribution-required/\"  class=\"js-gps-track\" data-gps-track=\"footer.click({ location: 2, link:35 })\" rel=\"license\">attribution required</a>.\r\n                    <span id=\"svnrev\">rev&nbsp;2019.8.22.34677</span>\r\n                </p>\r\n            </div>\r\n        </div>\r\n\r\n            </footer>\r\n            <script>StackExchange.ready(function () { StackExchange.responsiveness.addSwitcher(); })</scri"], "copyright__copyright__copyright": ["ER_VIEW created.\n\nSQL> select * from alt_ver_view;\n\n     EMPNO ENAME\n---------- ----------\n      7369 SMITH\n      7499 ALLEN\n      7521 WARD\n      7566 JONES\n      7654 MARTIN\n      7698 BLAKE\n      7782 CLARK\n      7788 SCOTT\n      7839 KING\n      7844 TURNER\n      7902 FORD\n      7934 MILLER\n\nYour Answer\n\nBy clicking \u201cPost Your Answer\u201d, you agree to our terms of service, privacy policy and cookie policy\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}