powered by simpleCommunicator - 2.0.60     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / FoxPro, Visual FoxPro [игнор отключен] [закрыт для гостей] / Возврат курсора из пакета Oracle 9.2 в VFP 8
2 сообщений из 2, страница 1 из 1
Возврат курсора из пакета Oracle 9.2 в VFP 8
    #32764992
Молодой Я
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Приветствую, уважаемые. В Oracle есть пакет:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
create or replace package pkg_crosstab as

  type array is table of varchar2 ( 30 );

  procedure pivot (
    p_max_cols in number default null
  , p_max_cols_query in varchar2 default null
  , p_query in varchar2
  , p_anchor in array
  , p_pivot in array
  , p_cursor in out sys_refcursor
  );
end;
/

create or replace package body pkg_crosstab as

  procedure pivot (
    p_max_cols in number default null
  , p_max_cols_query in varchar2 default null
  , p_query in varchar2
  , p_anchor in array
  , p_pivot in array
  , p_cursor in out sys_refcursor
  ) as
    l_max_cols number;
    l_query long;
    l_cnames array;
  begin

    -- figure out the number of columns we must support
    -- we either KNOW this or we have a query that can tell us

    if (p_max_cols is not null) then
      l_max_cols := p_max_cols;
    elsif (p_max_cols_query is not null) then
      execute immediate p_max_cols_query
        into l_max_cols;
    else
      raise_application_error (- 20001 , 'Cannot figure out max cols');
    end if;

    -- Now, construct the query that can answer the question for us...
    -- start with the C1, C2, ... CX columns:

    l_query := 'select ';

    for i in  1  .. p_anchor.count loop
      l_query := l_query || p_anchor (i) || ',';
    end loop;

    -- Now add in the C{x+1}... CN columns to be pivoted:
    -- the format is "max(decode(rn,1,C{X+1},null)) cx+1_1"

    for i in  1  .. l_max_cols loop
      for j in  1  .. p_pivot.count loop
        l_query := l_query || 'max(decode(rn,' || i || ',' || p_pivot (j) || ',null)) ' 
                   || p_pivot (j) || '_' || i || ',';
      end loop;
    end loop;

    -- Now just add in the original query

    l_query := rtrim (l_query, ',') || ' from ( ' || p_query || ') group by ';

    -- and then the group by columns...

    for i in  1  .. p_anchor.count loop
      l_query := l_query || p_anchor (i) || ',';
    end loop;

    l_query := rtrim (l_query, ',');

    -- and return it

    execute immediate 'alter session set cursor_sharing=force';
    open p_cursor for l_query;
    execute immediate 'alter session set cursor_sharing=exact';
  end;
end;
который реализует транспонирование столбцов запроса в строки.
В SQL Plus-е его использование выглядит след. образом:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
variable x refcursor;

begin
  pkg_crosstab.pivot (
      p_max_cols_query => 'select max(count(*)) from scott.emp group by deptno,job'
    , p_query          => 'select deptno, job, ename, sal, row_number() over (partition by deptno, job order by sal, ename) rn '||
                          'from scott.emp a'
    , p_anchor         => pkg_crosstab.array('DEPTNO', 'JOB')
    , p_pivot          => pkg_crosstab.array('ENAME', 'SAL')
    , p_cursor         => :x
  );
end;
/
Просмотреть его результат в том же SQL Plus можно так:
Код: plaintext
print x;

А вот как затянуть результирующую таблицу в курсор VFP при помощи SQLEXEC(nHandle,cSQLCommand,cCursorName)?
...
Рейтинг: 0 / 0
Возврат курсора из пакета Oracle 9.2 в VFP 8
    #32771755
-гость-
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Так же как ты его тянешь а Оракуле. Только в виде параметра как строка.
И все. параметры из фокса как обычно, вызов хранимых процедур/по твоему пакетов как обычно, если не ошибаюсь у вашей братвы, оракуловкой через CALL ... , вообщем ничего нового.
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / FoxPro, Visual FoxPro [игнор отключен] [закрыт для гостей] / Возврат курсора из пакета Oracle 9.2 в VFP 8
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]