Programowanie « Różności …

Różności …

18 listopada 2011

Oracle SOA jdev extension.

Zaszufladkowany do: Java,Oracle,Programowanie — Tagi: — Jacek @ 17:52

Extensions for JDeveloper:

http://www.oracle.com/ocom/groups/public/@otn/documents/webcontent/156082.xml

17 listopada 2011

BPMN – podstawy

Zaszufladkowany do: Programowanie — Tagi: — Jacek @ 13:15

Tablice BPMN

BPMN_Poster_A4_ver_1.0.10

BPMN_Poster_A3_ver_1.0.10

BPMN_Poster_A2_ver_1.0.10

15 listopada 2011

PL/SQL – functions

Zaszufladkowany do: Bazy danych,PL/SQL,Programowanie — Tagi: , — Jacek @ 19:44

PL/SQL Functions

What is a Function in PL/SQL?

A function is a named PL/SQL Block which is similar to a procedure. The major difference between a procedure and a function is, a function must always return a value, but a procedure may or may not return a value.

The General Syntax to create a function is:

CREATE [OR REPLACE] FUNCTION function_name [parameters]

RETURN return_datatype;

IS

Declaration_section

BEGIN

Execution_section

Return return_variable;

EXCEPTION

exception section

Return return_variable;

END;

1) Return Type: The header section defines the return type of the function. The return datatype can be any of the oracle datatype like varchar, number etc.
2) The execution and exception section both should return a value which is of the datatype defined in the header section.

For example, let’s create a frunction called ”employer_details_func’ similar to the one created in stored proc

1> CREATE OR REPLACE FUNCTION employer_details_func

2>    RETURN VARCHAR(20);

3> IS

5>    emp_name VARCHAR(20);

6> BEGIN

7>      SELECT first_name INTO emp_name

8>      FROM emp_tbl WHERE empID = ’100′;

9>      RETURN emp_name;

10> END;

11> /

In the example we are retrieving the ‘first_name’ of employee with empID 100 to variable ‘emp_name’.
The return type of the function is VARCHAR which is declared in line no 2.
The function returns the ‘emp_name’ which is of type VARCHAR as the return value in line no 9.

How to execute a PL/SQL Function?

A function can be executed in the following ways.

1) Since a function returns a value we can assign it to a variable.

employee_name :=  employer_details_func;

If ‘employee_name’ is of datatype varchar we can store the name of the employee by assigning the return type of the function to it.

2) As a part of a SELECT statement

SELECT employer_details_func FROM dual;

3) In a PL/SQL Statements like,

dbms_output.put_line(employer_details_func);

This line displays the value returned by the function.

source:

http://plsql-tutorial.com/plsql-functions.htm

18 października 2011

(SQL) select with translation table

Zaszufladkowany do: Programowanie,SQL — Tagi: — Jacek @ 10:03

CREATE TABLE HR.JS_TAB1(MIASTO VARCHAR2(20), ULICA VARCHAR2(20));

SELECT * FROM HR.JS_TAB1;

CREATE TABLE HR.JS_TRANS1(ULICA_Z VARCHAR2(30), ULICA_NA VARCHAR(30));

SELECT * FROM HR.JS_TRANS1;

INSERT INTO HR.JS_TAB1 VALUES(‘GDYNIA’,'NAGIETKOWA’);
INSERT INTO HR.JS_TAB1 VALUES(‘GDYNIA’,'SWIETOJANSKA’);
INSERT INTO HR.JS_TAB1 VALUES(‘GDANSK’,'KOLOBRZESKA’);
INSERT INTO HR.JS_TAB1 VALUES(‘GDANSK’,'MALBORSKA’);

INSERT INTO HR.JS_TRANS1 VALUES (‘KOLOBRZESKA’,'CHLOPSKA’);
INSERT INTO HR.JS_TRANS1 VALUES (‘SWIETOJANSKA’,'WLADYSLAWA IV’);

SELECT MIASTO, ULICA FROM HR.JS_TAB1;

SELECT MIASTO,
Nvl((SELECT ULICA_NA FROM HR.JS_TRANS1 TRAN1 WHERE TAB1.ULICA = TRAN1.ULICA_Z),TAB1.ULICA)
FROM HR.JS_TAB1 TAB1;

30 sierpnia 2011

UML

Zaszufladkowany do: UML — Tagi: — Jacek @ 09:32

Projekt w procesie kaskadowym – uporządkowane działanie. (analiza, projektowanie, implementacja, testy, wdrożenie)

Projekt w procesie iteracyjnym – projekt dzielimy na podstawie funkcjonalności – większa elastyczność niż w procesie kaskadowym. Klient na bieżąco uczestniczy w życiu projektu.

Projekt w procesie Agile (lekkie) – predykcja (przewidujemy np. cenę …), adaptacja – do aktualnych warunków, krótkie iteracje, UML – stosuje się w trybie szkicowym.

RUP – Rational Unified Process – szkielet procesu (wybór przypadku tworzenia oprogramowania), inception (rozpoczęcie), elaboration (opracowanie), construction, transition (przejście – np. szkolenie użytkowników)

UML – narzędzia modelowania do RUPa

Analiza wymagańprzypadki użycia (jak ludzie komunikują się z systemem), diagram klas (pojęcia używane w organizacji), diagram czynności – opis procesów biznesowych, współpraca ludzi z systemem na poziomie biznesowym, diagram stanów (np telewizor (wyłączony/włączony))

Projektowanie – diagram klas (klasy programu), diagramy sekwencji, diagramy pakietów (organizacja oprogramowania), diagramy wdrożenia

Dokumentowanie

Reverse engeneering

17 sierpnia 2011

UML (Zunifikowany język modelowania)

Zaszufladkowany do: Programowanie,UML — Tagi: — Jacek @ 10:42

SmallTalk – dopbry do nauki programowania obiektowego.

UML – modelowanie graficzne

Metamodel – specyfikacja języka.

Diagramy strukturalne (klas, komponentów, wdrożenia) i behawioralne (aktywności, przypadków użycia, state machine, interakcji -> sekwencji).

Stosowany do: szkicy projektowych (mało formalne), projekty (pełna specyfikacja), programowanie (generowanie kodu, MDA Model Driven Architecture)

Specyfikacja UML: http://www.omg.org/spec/UML/2.4/

UML 2.4 Infrastructure

UML_2.4_superstructure_10-11-14

2 sierpnia 2011

UML

Zaszufladkowany do: UML — Tagi: — Jacek @ 11:44

Projektując system informatyczny, rozpoczyna się przeważnie od tworzenia diagramów w następującej kolejności:

  1. Przypadków użycia
  2. Sekwencji
  3. Klas
  4. Aktywności

22 kwietnia 2011

ApEx

Zaszufladkowany do: ApEx,Programowanie — Tagi: — Jacek @ 13:52

Grupy w APEXie

http://www.avout.com/avout-blog/using-groups-application-express

REST services

http://docs.oracle.com/cd/E37099_01/doc/doc.20/e25066/toc.htm

JavaScritp Apex

https://apex.oracle.com/pls/apex/f?p=31517

APEX installation

http://docs.oracle.com/cd/E37097_01/doc/install.42/e35123/toc.htm

Creating new workspace and assigning a schema to it.

6 kwietnia 2011

PL/SQL – select into

Zaszufladkowany do: PL/SQL — Tagi: — Jacek @ 10:59

SQL> declare
2    v_authName author.author_last_name%type;
3  begin
4    select
5      author_last_name into v_authName
6    from
7      author
8    where
9      author_key = ‘A103′;
10
11    dbms_output.put_line(‘Name: ‘||v_authName);
12  end;
13  /

SQL> declare
2    v_author author%rowtype;
3  begin
4    select
5      * into v_author
6    from
7      author
8    where
9      author_key = ‘A103′;
10
11    dbms_output.put_line(‘Name: ’||v_author.author_first_name||’ ‘|| v_author.author_last_name);
12  end;
13  /

Źródła:

http://www.dba-oracle.com/t_pl_sql_plsql_select_into_clause.htm

5 kwietnia 2011

Oracle ApEx – adding a link

Zaszufladkowany do: ApEx,Oracle,Programowanie — Tagi: — Jacek @ 07:29

Adding a link.

4 kwietnia 2011

Dafault value (alter table – oracle)

Zaszufladkowany do: Bazy danych,Oracle,PL/SQL — Tagi: — Jacek @ 17:56

alter table PROBY modify (“WYDANO” FLOAT(126) DEFAULT 0)

1 kwietnia 2011

ApEx – primary key

Zaszufladkowany do: ApEx,Bazy danych,Oracle — Tagi: , — Jacek @ 11:47

CREATE table “PROBY” (
“ID”                   NUMBER(7) NOT NULL,
“DATA”                 DATE,
“TEMAT”                VARCHAR2(250),
“FAKTURA”              VARCHAR2(200),
“MASA_PROBY”           NUMBER(7),
“MASA_BADANIA”         NUMBER(7),
“MASA_PO_BADANIACH”    NUMBER(7),
“W_ZAMRAZARCE”         NUMBER(7),
“DLA_PRACOWNIKOW”      NUMBER(7),
“WARTOSC”              NUMBER(7),
“WARTOSC_PO_BADANIACH” NUMBER(7),
“ODPADY”               NUMBER(7),
“ODPOWIEDZIALNY”       VARCHAR2(150),
constraint  ”PROBY_PK” primary key (“ID”)
)
/
CREATE sequence “PROBY_SEQ”
/
CREATE trigger “BI_PROBY”
before insert on “PROBY”
for each row
begin
if :NEW.”ID” is null then
select “PROBY_SEQ”.nextval into :NEW.”ID” from dual;
end if;
end;
/
alter table “PROBY” add
constraint “PROBY_UK1″
unique (“ID”)
/

Aby zmienić home page:

Go to shared component.
Click on Edit Security Attribute under Secuirty
In Home Link text box… you will find something smilar to f?p=&APP_ID.:1:&SESSION.

After &APP_ID. you see a number , that number denotes home page.. in the above example 1 denotes the home page change 1 to 4 if you want page 4 to be ur home page


16 marca 2011

ApEx (K2)

Zaszufladkowany do: ApEx,Programowanie — Tagi: — Jacek @ 11:52

ApEx webshits

(K2 -- END :-) )

15 marca 2011

ApEx (K2)

Zaszufladkowany do: ApEx,Programowanie — Tagi: — Jacek @ 12:57

Instalacja OEHR Sample Objects

Packaged apps:

http://www.oracle.com/technetwork/developer-tools/apex/application-express/packaged-apps-090453.html

(45)

Źródła:

http://download.oracle.com/docs/cd/E17556_01/doc/appdev.40/e15516/toc.htm

8 marca 2011

Apex – podstawy (K2)

Zaszufladkowany do: ApEx,Programowanie — Tagi: — Jacek @ 08:59

Oracle Application Express is a rapid Web application development tool for the Oracle database.

Oracle Application Express installs with your Oracle database and is comprised of data in tables and PL/SQL code.

The application session state is managed in the database tables within Oracle Application Express. It does not use a dedicated database connection. Instead, each request is made through a separate database session, consuming minimal CPU resources.

In order to run, Oracle Application Express must have access to Oracle Application Express Listener, Oracle HTTP Server and mod_plsql, or the embedded PL/SQL gateway.

The embedded PL/SQL gateway installs with in the Oracle database. It provides the Oracle database with a Web server and also the necessary infrastructure to create dynamic applications. The embedded PL/SQL gateway runs in the Oracle XML DB HTTP server in the Oracle database and includes the core features of mod_plsql.

ApEx embeded PL/SQL gateway

lub architektura three-tier:

ApEx in three tier architecture

The area where you develop applications is called a workspace.

A workspace is a virtual private database that enables multiple users to work within the same Oracle Application Express installation while keeping their objects, data, and applications private.

ApEx workspace

When you create a workspace, you associate it with a new or existing schema. A schema is a logical container for database objects such as tables, views, and stored procedures. A single schema can be associated with one or more workspaces.

The roles within Oracle Application Express include the following: Workspace administrators, Developers, End users, Instance administrators (manage an entire hosted instance using the Application Express Administration Services application)

Logging In to Administration Services

http://hostname:port/apex/apex_admin (port 8080)
port is the port number assigned to Oracle HTTP Server. In a default installation, for Oracle WebLogic Server this number is 7001, in OC4J this number is 8888, in Oracle Glassfish Server this number is 8080.

ApEx Workspace creation.

If you want to use the same name for both your workspace and schema, enter a workspace name that contains only alphabetic characters. Schema names are restricted to alphabetic characters.

Workspace ID – Leave Workspace ID blank to have the new Workspace ID automatically generated. A Workspace ID must be a positive integer greater than 100000

ApEx Workspace creation.

ApEx Workspace creation.

ApEx Workspace creation.

ApEx Workspace creation.

Źródła:

http://download.oracle.com/docs/cd/E17556_01/doc/appdev.40/e15516/toc.htm

3 marca 2011

Instalacja APEX na Oracle Express

Zaszufladkowany do: ApEx,Bazy danych,Oracle — Tagi: , — Jacek @ 13:02

Oracle HTTP Server uses the mod_plsql plug-in to communicate with the Oracle Application Express engine within the Oracle database. Oracle Application Express Listener communicates directly with the Oracle Application Express engine, thus eliminating the need for the mod_plsql plug-in.

W katalogu c:\apex_4.0.2\apex\owa

logawanie na sys

Sprawdzam wersję PL/SQL Web Toolkit
sql>  select owa_util.get_version from dual;
u mnie była 10.1.2.0.4
uaktualniam:
sql> @owainst.sql
po aktualizacji: 10.1.2.0.6

W katalogu c:\apex_4.0.2\apex

logowanie na sys

SQL>@apexins USERS USERS TEMP /i/

po instalce

podmaina plików gravicznych, css, java script
SQL>@apxldimg.sql C:\apex_4.0.2

ustawiamy hasło dla użytkownika admin:
SQL>@apxxepwd.sql haslo

No i jest ekran powitalny na http://127.0.0.1:8080/apex

Jeżeli nie masz jeszcze żadnych workspace’ów użyj adresu: http://localhost:8080/apex/f?p=4550:10
Zaloguj się na konto “ADMIN”

Domyślnym worskpace’m dla ADMIN jest: “INTERNAL”

JAVA (K2,K3)

Zaszufladkowany do: Java — Tagi: — Jacek @ 11:24

.jws (aplikacja)
Projekty zawarte są w aplikacji.

ADF –  Application Developement Framework

CTRL + SHIFT + ENTER – auto completion

JSE – Java Standard Edition – standardowa technologia Javy. Sercem platformy JSE jest JVM (Java Virtual Machine), która wraz z Javą API (interfejs tworzenia aplikacji) służy do uruchomianaia aplikacji Java.
Te dwa elementy stanowią JRE SE (Java Runtime Environment SE) – środowisko uruchomieniowe standardowej Javy.
Zainstalowanie tego środowiska umożliwia uruchamianie aplikacji desktopowych lub apletów.

JDK SE (Java Developement Kit SE) – środowisko do tworzenia aplikacji. (10,10)

13 stycznia 2011

Instalacja APEX 4.0.2

Zaszufladkowany do: ApEx,Oracle — Tagi: , — Jacek @ 13:11

Pobieram najnowszego APEXa z: http://www.oracle.com/technetwork/developer-tools/apex/downloads/index.html

Kopiuję rozpakowany katalog do: /home/oracle/orahome/base/db11gr2/apex402

Będąc w katalogu /home/oracle/orahome/base/db11gr2/apex402/owa loguję się na SYSa do bazy.

Instaluję najnowszą wersję PL/SQL Web Toolkit:
Aktulaną wersję można sprawdzić przez: SQL>select owa_util.get_version from dual;  (moja była: 10.1.2.0.8)
SQL>@owainst.sql
Dostałem informację, że mam już nowszą wersję i że nie jest wymagana instalacja.

Będąc w katalogu /home/oracle/orahome/base/db11gr2/apex402 loguję się na SYSa do bazy.
Uruchamiamy skrypt upgradeu z parametriami.
Pierwszy parametr to przestrzeń tabel w jakiej powinny być składowane obiekty bazodanowe (tablespace_apex) , drugi parametr to przestrzeń tabel w której maja byc składane pliki (tablespace_files), trzeci parametr to przestrzeń tymczasowa która ma być wykorzystywana przez APEX (tablespace_temp), przestrzeń ta musi być typem przetrzeni tabel tymczasowych. Ostatnim elementem jest tzw. katalog wirtualny (images), w którym znajdować się będą pliki graficzne i odpowiadające za wygląd templatów.
SQL> @apexins APEX APEX APEX_TMP apeximages

.. wśród całej masy komunikatów otrzymamy między innymi:

The structure of the link to the Application Express administration services is as follows:
http://host:port/pls/apex/apex_admin (Oracle HTTP Server with mod_plsql)
http://host:port/apex/apex_admin     (Oracle XML DB HTTP listener with the embedded PL/SQL gateway)
The structure of the link to the Application Express development interface is as follows:
http://host:port/pls/apex (Oracle HTTP Server with mod_plsql)
http://host:port/apex     (Oracle XML DB HTTP listener with the embedded PL/SQL gateway)
JOB_QUEUE_PROCESSES: 1000

Na mojej testowej (czytaj gównianej) maszynie, skrypt wykonywał się przez 16 minut.

Teraz pozostało nam wykonanie podmiany plików graficznych, css i javascript.
W tym celu należy uruchomić skrypt: apxldimg.sql
Skrypt ten przyjmuje tylko jeden argument: lokalizację katalogu z instalką ApEx’a.
Skrypt załaduje obrazki do XDB.

SQL> @apxldimg.sql /home/oracle/orahome/base/db11gr2/apex402


old   1: create directory APEX_IMAGES as ‘&1/apex/images’
new   1: create directory APEX_IMAGES as ‘/home/oracle/orahome/base/db11gr2/apex402/apex/images’
Directory created.
declare
*
ERROR at line 1:
ORA-22288: file or LOB operation FILEOPEN failed
No such file or directory
ORA-06512: at “SYS.XMLTYPE”, line 296
ORA-06512: at line 15

Ostatni krok to ustawienie hasła dla Administratora workspace-ów.

SQL> @apxxepwd.sql jakies_haslo

Session altered.
…changing password for ADMIN
PL/SQL procedure successfully completed.

7 stycznia 2011

PL/SQL Associative Arrays

Zaszufladkowany do: PL/SQL — Tagi: — Jacek @ 15:04

declare
type assoc_arr is table of varchar2(255) index by varchar2(255);
apollo_commanders assoc_arr;
begin
apollo_commanders(‘Apollo 11′) := ‘Neil Armstrong’;
apollo_commanders(‘Apollo 12′) := ‘Pete Conrad’;
apollo_commanders(‘Apollo 13′) := ‘James Lovell’;
apollo_commanders(‘Apollo 14′) := ‘Alan Shepard’;
apollo_commanders(‘Apollo 15′) := ‘David Scott’;
apollo_commanders(‘Apollo 16′) := ‘John W. Young’;
apollo_commanders(‘Apollo 17′) := ‘Eugene A. Cernan’;

dbms_output.put_line(apollo_commanders(‘Apollo 11′));
dbms_output.put_line(apollo_commanders(‘Apollo 14′));
end;
/

– Results:
– Neil Armstrong
– Alan Shepard

Znalezione na: http://tylermuth.wordpress.com/2008/02/21/plsql-associative-arrays/

3 stycznia 2011

PL/SQL – functions, zwrot wartości tablicy z funkcji.

Zaszufladkowany do: PL/SQL — Tagi: — Jacek @ 13:16

Tu jest dobry artykuł o funkcjach.

A function is a named PL/SQL Block which is similar to a procedure. The major difference between a procedure and a function is, a function must always return a value, but a procedure may or may not return a value.

The General Syntax to create a function is:

CREATE [OR REPLACE] FUNCTION function_name [parameters]
RETURN return_datatype;
IS
Declaration_section
BEGIN
Execution_section
Return return_variable;
EXCEPTION
exception section
Return return_variable;
END;

1) Return Type: The header section defines the return type of the function. The return datatype can be any of the oracle datatype like varchar, number etc.
2) The execution and exception section both should return a value which is of the datatype defined in the header section.

For example, let’s create a frunction called ”employer_details_func’ similar to the one created in stored proc

1> CREATE OR REPLACE FUNCTION employer_details_func
2>    RETURN VARCHAR(20);
3> IS
5>    emp_name VARCHAR(20);
6> BEGIN
7>	SELECT first_name INTO emp_name
8>	FROM emp_tbl WHERE empID = '100';
9>	RETURN emp_name;
10> END;
11> /

In the example we are retrieving the ‘first_name’ of employee with empID 100 to variable ‘emp_name’.
The return type of the function is VARCHAR which is declared in line no 2.
The function returns the ‘emp_name’ which is of type VARCHAR as the return value in line no 9.

How to execute a PL/SQL Function?

A function can be executed in the following ways.

1) Since a function returns a value we can assign it to a variable.

employee_name :=  employer_details_func;

If ‘employee_name’ is of datatype varchar we can store the name of the employee by assigning the return type of the function to it.

2) As a part of a SELECT statement

SELECT employer_details_func FROM dual;

3) In a PL/SQL Statements like,

dbms_output.put_line(employer_details_func);

This line displays the value returned by the function.

Zawartość tablicy jako wynik funkcji.

Za http://www.tek-tips.com/faqs.cfm?fid=846.
If you need to return dynamic amounts of data, you probably want to use PL/SQL tables.  A PL/SQL table is similar to an array, but it can have only one bound.

PL/SQL tables are sparse.  That is if you write to index 1 and index 10, only two values are stored in memory.  Oracle doesn’t store NULL values for indexes 2 through 9.  If you reference an index that has not been stored yet, you will get a NO_DATA_FOUND exception.

You need to define a TYPE to hold your data before you can use a table.  You do that with the oracle TYPE statement.
<type_name> IS TABLE OF ORACLE_DATA_TYPE INDEX BY BINARY_INTEGER;

You can declare the type anywhere declarations are valid.  You can put them in a package header or in a DECLARE section.  Putting them in a package header makes them sharable between packages and easily reusable.  I always create a package header that defines useful table structures an I call it TABLE_TYPES

CREATE OR REPLACE PACKAGE TABLE_TYPES
AS
TYPE tNumber IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
TYPE tString IS TABLE OF VARCHAR2(250) INDEX BY BINARY_INTEGER;
END;

If you put the table definitions into their own package you don’t have to worry about cluttering up all your other packages with useless table definitions.  Notice, I use the TABLE_TYPES package in the package example below.

When you create a table variable, you can place data into it sparsely, as I said before..  Take this anonymous block for example.

DECLARE
tab TABLE_TYPE.tNumber;
BEGIN
tab(1) := 30;
tab(30) := 1;
tab(2) := tab(30) – tab(1);

DBMS_OUTPUT.ENABLE();
DBMS_OUTPUT.PUT_LINE(‘Index two contains: ‘ || tab(2));
END;

If you run the above anonymous block you should get the output:

Index two contains: -29

PL/SQL procedure successfully completed.

if you only see the last line, type set serveroutput on before running the anonymous block.

The COUNT property of a table returns the total number of rows that are found in that table.  If the table is defined sparesly, unfilled rows ARE NOT INCLUDED.  In the above anonymous block tab.COUNT will be THREE.


1. CREATE OR REPLACE PACKAGE EXAMPLE_PKG AS
2. FUNCTION myFunction() RETURN TABLE_TYPES.tNumber;
3. PRAGMA RESTRICT_REFERENCES(myFunction,WNDS);
4. END;
5. /

And here is the packge body

1.  CREATE OR REPLACE PACKAGE BODY EXAMPLE_PKG AS
2.  FUNCTION myFunction() RETURN tNumber
3.  – this function returns a table of numbers 1 to 10
4.  IS
5.    example_table TABLE_TYPES.tNumber;
6.  BEGIN
7.    FOR indx IN 1 .. 10
8.    LOOP
9.      example_table(indx) := i;
10.   END LOOP;
11. END;
12. /

Finally, we’ll create an anonymous block that calls the myFunction function, gets a table of results and displays them on the screen.


1. DECLARE
2.  tab TABLE_TYPES.tNumber;
3. BEGIN
4.   tab := EXAMPLE_PKG.myFunction();
5.   DBMS_OUTPUT.ENABLE();
6.   for i in 1 .. tab.COUNT
7.   LOOP
8.      DBMS_OUTPUT.PUT_LINE(‘Row ‘ || i || ‘. value = ‘ || tab(i));
9.  END LOOP;
10.END;

I DRUGI OPIS

How to return a table from function.

SQL> create type numtab is table of number;
  2  /

Type created.

SQL> create type rectype as object (col1 number, col2 date, col3 varchar2(120));
  2  /

Type created.

SQL> create type complextab as table of rectype;
  2  /

Type created.

SQL> create or replace function f1 return numtab
  2  is
  3    v_temptab numtab;
  4  begin
  5    v_temptab := new numtab();
  6    for j in 1..20 loop
  7      v_temptab.extend();
  8      v_temptab(v_temptab.last) := j;
  9    end loop;
 10    return v_temptab;
 11  end;
 12  /

Function created.

SQL> create or replace function f2 return complextab
  2  is
  3    v_temptab complextab;
  4  begin
  5    v_temptab := new complextab();
  6    for j in 1..20 loop
  7      v_temptab.extend();
  8      v_temptab(v_temptab.last) := new rectype( col1 => j
  9                                              , col2 => sysdate - j
 10                                              , col3 => to_char(to_date(j,'J'),'JSP')
 11                                              );
 12    end loop;
 13    return v_temptab;
 14  end;
 15  /

Function created.

SQL> select *
  2    from table(f1);

COLUMN_VALUE
------------
           1
           2
           3
           4
           5
           6
           7
           8
           9
          10
          11

COLUMN_VALUE
------------
          12
          13
          14
          15
          16
          17
          18
          19
          20

20 rows selected.

SQL> select *
  2    from table(f2);

      COL1 COL2      COL3
---------- --------- --------------------
         1 09-MAY-05 ONE
         2 08-MAY-05 TWO
         3 07-MAY-05 THREE
         4 06-MAY-05 FOUR
         5 05-MAY-05 FIVE
         6 04-MAY-05 SIX
         7 03-MAY-05 SEVEN
         8 02-MAY-05 EIGHT
         9 01-MAY-05 NINE
        10 30-APR-05 TEN
        11 29-APR-05 ELEVEN

      COL1 COL2      COL3
---------- --------- --------------------
        12 28-APR-05 TWELVE
        13 27-APR-05 THIRTEEN
        14 26-APR-05 FOURTEEN
        15 25-APR-05 FIFTEEN
        16 24-APR-05 SIXTEEN
        17 23-APR-05 SEVENTEEN
        18 22-APR-05 EIGHTEEN
        19 21-APR-05 NINETEEN
        20 20-APR-05 TWENTY

20 rows selected.

SQL>
The first is a small numeric table, the second uses not only NUMBER, but also DATE and VARCHAR2.
« Nowsze wpisyStarsze wpisy »

Strona startowa: www.jaceksen.pl