Use of PL/SQL collections

Hi gurus,

I have a new collection and just wanted to know about little things.

I would like to declare the associative array for emp % rowtype and I want to load the entire table in the pl/sql table, and then I want to display on the screen.

I wrote the following code but impossible to load the entire table and display it.

Could you please guide me in the loading and display of the entire record of the table emp also please share some links that will give me examples of collections on the emp table.

Literature Informatics very difficult to understand concepts.

declare
type emplist is table of emp%rowtype index by binary_integer;
etab emplist;




begin
if etab is null then
dbms_output.put_line('etab empty');
else
dbms_output.put_line('etab not empty');
end if;
dbms_output.put_line(etab.count);
--null;




end;

Thank you...

Oracle offers 3 types of PL/SQL collection type.

1. associative array

2. nested table

3. Varray

You must first determine what type of suites collection your goal. To show how what you try, I used the nested Table collection type.

SQL > select * from version $ v where rownum = 1;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi

SQL > declare
2 tbl type is table of the emp % rowtype;
tbl 3 v;
4 start
5 Select * bulk collect into emp v.;
6
7 because I loop 1.v.count
8 dbms_output.put_line (v (i) .empno |) '/' || v (i) .ename);
9 end of the loop;
10 end;
11.
7369/SMITH
7499/ALLEN
7521/WARD
7566/JONES
7654/MARTIN
7698/BLAKE
7782/CLARK
7788/SCOTT
7839/KING
7844/TURNER
7876/ADAMS

PL/SQL procedure successfully completed.

A common myth about the treatment in bulk, it's that it improves performance. Grouping of PL/SQL variable uses an area of PGA memory. PGA is a private memory area. For example, if a process requires 1 MB of storage for a variable grouping in PGA and 25 users ask the same process, then 25 MB is allocated in PGA for this collection. It's a very expensive.

It must be so always remember, the best and the only way to process the data in Oracle using SQL. PL/SQL is not a recommended tool to process the data. Therefore, always try to make the processing of your data by using simple SQL. Never treat the data in a loop using the explicit cursor or collection of PL/SQL.

Tags: Database

Similar Questions

  • PL/SQL, Collection and email 'question '.

    Hi all
    I'm spending external monitoring scripts to internal procedures or packages.
    In this specific case, I create a procedure (it can be a lot, but I started to test it as a procedure) that checks free space on storage space (the percentage estimate).
    Everything works fine but...
    I want to send the result set to my email account (in the body of the message, not as an attachment.). So, first, I used the following code:
    create or replace
    PROCEDURE TBSALERT AS
    tbs VARCHAR(100);
    per NUMBER;
    conn utl_smtp.connection;
    v_From VARCHAR2(80) := '[email protected]';
    v_Recipient VARCHAR2(80) := '[email protected]';
    v_Subject VARCHAR2(80) := 'TBS Status';
    v_Mail_Host VARCHAR2(30) := 'smtp.domain.com.com';
    CURSOR tbs_alertc IS
    SELECT A.tablespace_name "Tablespace", trunc(b.free/A.total*100) "Free %" FROM (SELECT tablespace_name,sum(bytes)/1024/1024 total FROM sys.dba_data_files where tablespace_name not like 'UNDO%' GROUP BY tablespace_name) A,(SELECT tablespace_name,sum(bytes)/1024/1024 free FROM sys.dba_free_space where tablespace_name not like 'UNDO%' GROUP BY tablespace_name) B WHERE A.tablespace_name=b.tablespace_name;
    BEGIN
    OPEN tbs_alertc;
    LOOP
    FETCH tbs_alertc INTO tbs,per;
    EXIT WHEN tbs_alertc%NOTFOUND;
    conn := UTL_SMTP.OPEN_CONNECTION(v_Mail_Host);
    UTL_SMTP.HELO(conn, v_Mail_Host);
    UTL_SMTP.MAIL(conn, v_From);
    UTL_SMTP.RCPT(conn, v_Recipient);
    UTL_SMTP.OPEN_DATA(conn);
    UTL_SMTP.WRITE_DATA(conn, UTL_TCP.CRLF ||'Alerta TBS: '||tbs|| ' Free%: '||per);
    DBMS_OUTPUT.PUT_LINE('Alerta TBS :'||tbs||' Percent :'||per);
    UTL_SMTP.CLOSE_DATA(conn);
    UTL_SMTP.QUIT(conn);
    END LOOP;
    CLOSE tbs_alertc;
    END;
    /
    The problem with that I get an email for each tablespace from the list (if I don't make a mistake, this behavior is because I make a loop of sending an email for each row in the cursor).
    So, I think that "I must use a PL/SQL collection", but, unfortunately, I am not able to solve my 'problem '.
    This is the code with I was playing around:
    create or replace
    PROCEDURE TBSALERTNEW AS
       TYPE tbslst IS TABLE OF SPACESTATUS_VW.TABLESPACE%TYPE;
       TYPE perlst IS TABLE OF SPACESTATUS_VW.Free%TYPE;
       CURSOR c1 IS SELECT TABLESPACE, FREE from SPACESTATUS_VW;
       tbs tbslst;
       per  perlst;
       TYPE spacestlst IS TABLE OF c1%ROWTYPE;
       spacest spacestlst;
    conn utl_smtp.connection;
    v_From VARCHAR2(80) := '[email protected]';
    v_Recipient VARCHAR2(80) := '[email protected]';
    v_Subject VARCHAR2(80) := 'TBS Status';
    v_Mail_Host VARCHAR2(30) := 'smtp.domain.com';
    PROCEDURE print_results IS
       BEGIN
    --      dbms_output.put_line('Results:');
          IF tbs IS NULL OR tbs.COUNT = 0 THEN
             RETURN; -- Don't print anything if collections are empty.
          END IF;
          FOR i IN tbs.FIRST .. tbs.LAST
          LOOP
             dbms_output.put_line(' i Tablespace: ' || tbs(i) || ' Free %:' ||
                per(i));
          END LOOP;
       END;
    BEGIN
       dbms_output.put_line('--- Processing all results at once ---');
       OPEN c1;
       FETCH c1 BULK COLLECT INTO tbs, per;
       CLOSE c1;
       print_results;
    
       dbms_output.put_line('--- Fetching records rather than columns ---');
       OPEN c1;
       FETCH c1 BULK COLLECT INTO spacest;
       FOR i IN spacest.FIRST .. spacest.LAST
       LOOP
    -- Now all the columns from the result set come from a single record.
          dbms_output.put_line(' h Tablespace ' || spacest(i).TABLESPACE || ' Free %: '
             || spacest(i).Free);
       END LOOP;
    END;
    Somethings to notice:
    a. This code is not exactly mine, she is part of an Oracle example (I thought it should be easier to play with something that worked).
    b. I created a display from the query in the first procedure, in order to facilitate the work on the second procedure.
    c. when debug you the code, it works fine.
    d I don't know where (or how) to use the UTL_SMTP part to send the complete set of results in the body of the email.
    e. I am company running Oracle 10.2.0.4 on Linux x86_64

    Any help will be appreciated.

    Thanks in advance.

    >
    So I think that "I have to use a collection of PL/SQL.
    >
    Why? Simply create a long string with a line for each table space. Add a newline at the end of each line.
    What makes a string body.

    Create VARCHAR2 (32000);

    The loop allows you to add a line for each table space.

    Easy to use a PL/SQL table.

  • run immediately with bind sql collection

    Hi, I'm working on an implementation immediate execution where to use a binding that is to an SQL array type. The type of table is produced by be transmitted from an array of Java.

    So it looks like:

    execute immediate mystatement using myarray;

    "mystatement" contains a forall command. I thought that it wouldn't work, because of limitations in the use of tables to link with dynamic sql, but it does. Also, I see in the Oracle documentation that allows dynamic sql to binds to SQL collection types. Am I so I read the documentation correctly, please, that this is a correct use of the immediate execution with a SQL collection?

    I tested on 10.2 and 11 g

    Thank you

    David

    979394 wrote:
    Hi, I'm working on an implementation immediate execution where to use a binding that is to an SQL array type. The type of table is produced by be transmitted from an array of Java.

    So it looks like:

    execute immediate mystatement using myarray;

    "mystatement" contains a forall command. I thought that it wouldn't work, because of limitations in the use of tables to link with dynamic sql, but it does. Also, I see in the Oracle documentation that allows dynamic sql to binds to SQL collection types. Am I so I read the documentation correctly, please, that this is a correct use of the immediate execution with a SQL collection?

    I tested on 10.2 and 11 g

    Thank you

    David

    Welcome to the Forum!
    Here is a small demonstration to what Solomon said: (not the best of examples I would say, but should provide an indication)

    drop table depts;
    drop table emps;
    drop type type_depts;
    
    create table depts (dept_no   number, dept_name varchar2(25), loc varchar2(10));
    
    create table emps (empno  number, name varchar2(25), dept_no  number, salary number);
    
    create or replace type type_depts is table of number;
    
    insert into depts values (10, 'ABC', '111');
    insert into depts values (20, 'ABC1', '111');
    insert into depts values (30, 'ABC2', '111');
    insert into depts values (40, 'ABC3', '111');
    insert into depts values (50, 'ABC4', '111');
    
    insert into emps values (1, 'PQR', 10, 100);
    insert into emps values (2, 'PQR1', 20, 100);
    insert into emps values (3, 'PQR2', 30, 100);
    insert into emps values (4, 'PQR3', 10, 100);
    insert into emps values (5, 'PQR4', 30, 100);
    insert into emps values (6, 'PQR5', 10, 100);
    insert into emps values (7, 'PQR6', 40, 100);
    insert into emps values (8, 'PQR7', 80, 100);
    
    commit;
    
    /* Block to find a DEPT_NO in EMP that does not exist in DEPT table */
    set serveroutput on;
    declare
      dept    type_depts;
    
      type type_emp is table of pls_integer index by pls_integer;
      emp     type_emp;
    
      idx     pls_integer;
    begin
      select dept_no
        bulk collect into dept
        from depts;
    
      execute immediate 'select empno from emps where dept_no not in (select column_value from table(:1))' bulk collect into emp using dept;
    
      for i in emp.first..emp.last loop
        dbms_output.put_line('Emp No:- ' || emp(i));
      end loop;
    end;
    
    anonymous block completed
    Emp No:- 8
    

    As you say, the 'mystatement"contains the FORALL statement; Is the name of the Table known at runtime, or it is passed as an additional parameter? If the Table name is known, then, IMO, there is no any dynamic SQL. A FORALL statement should be enough.

    Please provide details. In addition, please read {message identifier: = 9360002}.

  • PL/SQL collection headaches

    Hello guys,.

    Thought maybe you could help simple here, I write a procedure to validate a Tin CAN.

    Basic rules are

    A Tin CAN has exactly eleven digits.
    Among the ten first exactly two digits are the same (the others are all different).
    -And then some - check digit - check module.

    The control module that brings me to put all the numbers in a table. So far so good.
    Then, I need to check "exactly two. Now that I have them in a table, I had in my mind that I could use this table. But I'm NOT in good terms with PL/SQL collections ;)

    I've been watching of multiset, but doesn't seem not that it is, or?

    So far I did it in SQL, but which seems to repeat what I just did, so I thought if a solution using the table. (I know how to do these two things in a single SQL, but I fear that no one here will understand)

    This is my procedure (please do not pay attention to the management of exceptions)
    SQL> CREATE OR REPLACE PROCEDURE validate_otn (in_tin VARCHAR2) IS
      TYPE tin_t IS VARRAY (11) OF PLS_INTEGER NOT NULL;
    
      v_digits       tin_t := tin_t (0);
      v_count        NUMBER;
      v_count_dist   NUMBER;
    BEGIN
      --
      -- Verify that we have numeric, non-null input
      --
      IF TO_NUMBER (in_tin) IS NULL THEN
        RETURN;
      END IF;
    
      ---------
      -- Verify that we have exactly the right number of digits
      ---------
      IF LENGTH (in_tin) != v_digits.LIMIT THEN
        RAISE VALUE_ERROR;
      END IF;
    
      ---------
      -- Put all digits into array
      ---------
      SELECT     SUBSTR (in_tin,
                         LEVEL,
                         1
                        )
                   x
      BULK       COLLECT INTO v_digits
      FROM       DUAL
      CONNECT BY LEVEL <= LENGTH (in_tin);
    
      ---------
      -- Verify exactly one digit used twice, among first ten
      ---------
      SELECT COUNT (x),
             COUNT (DISTINCT x)
      INTO   v_count,
             v_count_dist
      FROM   (SELECT     SUBSTR (in_tin,
                                 LEVEL,
                                 1
                                )
                           x
              FROM       DUAL
              CONNECT BY LEVEL <= LENGTH (in_tin) - 1);
    
      IF v_count - v_count_dist != 1 THEN
        RAISE VALUE_ERROR;
      END IF;
    --
    -- Lots more to come, including some modulo checks, etc
    --
    EXCEPTION
      WHEN OTHERS THEN
        DBMS_OUTPUT.put_line (SQLERRM);
        RAISE VALUE_ERROR;
    END validate_otn;
    /
    Procedure created.
    
    SQL> show errors
    No errors.
    
    SQL> select banner from v$version;
    
    BANNER                                                          
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production                          
    CORE     10.2.0.3.0     Production                                      
    TNS for Linux: Version 10.2.0.3.0 - Production                  
    NLSRTL Version 10.2.0.3.0 - Production                          
    
    5 rows selected.
    I'm looking to replace it with Collection/full year:
      SELECT COUNT (x),
             COUNT (DISTINCT x)
      INTO   v_count,
             v_count_dist
      FROM   (SELECT     SUBSTR (in_tin,
                                 LEVEL,
                                 1
                                )
                           x
              FROM       DUAL
              CONNECT BY LEVEL <= LENGTH (in_tin) - 1);
    Any ideas?


    I don't want to follow during a casting of hours - commuting.


    Best regards
    Peter

    Returns The VALUE of distinct values, for example:

    DECLARE
       p_tin CONSTANT sys.ku$_objnumset := sys.ku$_objnumset(1,2,2,3,4,5,6,7,8,9,10);
    BEGIN
       DBMS_OUTPUT.PUT_LINE(p_tin.count || ' elements');
       DBMS_OUTPUT.PUT_LINE(SET(p_tin).count || ' distinct elements');
    END;
    
    11 elements
    10 distinct elements
    

    You can probably use it somehow.

    Note that it needs correct nested table collections, not varrays.

  • To bulk table the PL/SQL collection

    Hi all

    version 10g 10.2.0.1

    Can what I do to accomplish the following.

    I need to build a collection based on the result of two SQL statements in a loop.

    Example:

    IS FUNCTION (get_info)

    RETURN retrieval_pkg_public_ty
    PIPELINED

    TYPE ret_tab IS TABLE OF THE ret_rec;

    BECAUSE me in 1... 2
    LOOP

    SELECT...
    BULK COLLECT into ret_tbl
    FROM (SELECT...
    FROM (SELECT...

    Quite a big SQL statement...

    WHERE
    x = parameter_value, - I'm from the changes of parameters to values
    y = parameter_value,-I'm from the changes of parameters to values

    END LOOP;


    BECAUSE me IN ret_tbl. FIRST... ret_tbl. LAST
    LOOP
    COURSE OF ACTION...

    END LOOP;

    I can use a global temporary table to store the results of each loop and select TWG, but I prefer to use a table function.

    Thank you
    Mark

    user1602736 wrote:
    Currently I have a procedure that is called in a package that returns a SYS_REFCURSOR.

    Course code of procedure is

    I'm in 1.2
    LOOP
    INSERt INTO TWG

    END LOOP;

    Why not just fill the TWG using a TWG INSERT INTO SELECT... Source FROM WHERE... ?

    I wanted to avoid creating a TWG to accomplish above.

    Why? You do the problems with this approach TWG think there?

    The cursor returns only about 50 records. The record includes data fields about 20

    Don't forget that if you store it as a collection of PL/SQL (there is no such thing as PL "+ table + '), this collection resides in expensive private process memory (PGA). Is there are 100 sessions by using this code, then it will have a 100 copies of this collection.

    On the other hand, a TWG does not lie in the expensive private memory. And it adapts to a 1000 lines in the future, without affecting performance (do not forget that the TWG can be indexed - not collections). For a collection, you will need to pay an excessive price in memory to keep this 1000 lines in the PGA.

    TWG is not a bad thing. The collections are not a bad thing. They are tools to solve specific problems. Your task is to select the right tool for the job. Cached data line SQL in a PL/SQL collection is almost never the right tool for the job, because it requires private process memory and uses a very simplistic data structure (does not support the index and so on).

  • Using mod pl/sql to create a dynamic form

    We have a backend application that creates questionnaires. The questions for this are created by an administrator and put in a MySQL database. This administrator can use a number of types of possible questions (like OPEN, MULTIPLE and RANGE). These questionnaires are then presented to the outside world using Web services.

    I'm currently building an Apex application that will accomplish this dynamically built form in the frontend.
    For this I used some PL/SQL procedures. A to collect data from Web services and put in temporary tables and another to return the data of these temporary tables using the cursor for loops and dynamically build the form using the htp package.

    It all works very well. Can I open a page of the Apex and it will show me the form with all the fields, as I expect. However, the problem with recording of data entered in this form.
    In the 'old' days when I created something like this using only modPL/SQL, I would have just a procedure with a parameter name_array and value_array to receive all the data. But in this case, when I try to do, I get a 404 error, because my form is between the apex #OPEN_FORM # and #CLOSE_FORM #...

    A brief overview of my code:
    -Page HTML apex with a region of PL/SQL calling the procedure p_get_form ('P1_PARAMETER');
    -p_get form with a call to p_get_webservice_data and the code to generate the form:
    htp.formopen('p_save_form');
    --
    --
    htp.formsubmit;
    htp.formclose;
    -p_save_form with name_array OWA settings. VC_ARR, value_array OWA. VC_ARR

    Can someone help me with this problem?

    Hello

    You should put the code in a process of PL/SQL (using point 'On Submit - after calculations' and Validations process) on the page. I have a full version of this, but he tried here: [http://apex.oracle.com/pls/otn/f?p=16338:3]

    Have you created a branch on your page?

    Andy

  • Need to check delays in update of 1000 lines using the PL/SQL procedure.

    Hi all

    I'm new to PL/SQL. I need your help to build a procedure that executes the following statement and follows the time of update of 1000 rows. This is to check the performance of the database. I need to print the timestamp of start before the update and end timestamp after update. I need to do for the 1000 lines. The statement that will be used in the procedure is:

    SELECT

    'UPDATE XXAFL_MON_FACTS_F SET TASK_WID =' | NVL (TO_CHAR (TASK_WID), 'NULL') |', EXECUTION_PLAN_WID =' | NVL (TO_CHAR (EXECUTION_PLAN_WID), 'NULL').

    ', DETAILS_WID =' | NVL (TO_CHAR (DETAILS_WID), 'NULL') |', SOURCE_WID =' | NVL (TO_CHAR (SOURCE_WID), 'NULL') |', TARGET_WID = ' | NVL (TO_CHAR (TARGET_WID), 'NULL').

    ', RUN_STATUS_WID =' | NVL (TO_CHAR (RUN_STATUS_WID), 'NULL') |', SEQ_NUM =' | NVL (TO_CHAR (SEQ_NUM), 'NULL') |', NAME = "' | NVL (TO_CHAR (NAME), 'NULL').

    "', NO_POSITION =" ' | NVL (TO_CHAR (INSTANCE_NUM), e ') | " ', INSTANCE_NAME = "' | NVL (TO_CHAR (INSTANCE_NAME), 'NULL').

    "', TYPE_CD =" ' | NVL (TO_CHAR (TYPE_CD), e ') | " ', STATUS_CD = "' | NVL (TO_CHAR (STATUS_CD), e ') | " ', START_TS =' | NVL (TO_CHAR (START_TS), 'NULL').

    ', END_TS =' | NVL (TO_CHAR (END_TS), 'NULL') |', DURATION = ' | NVL (TO_CHAR (DURATION), 'NULL') |', STATUS_DESC = "' | NVL (TO_CHAR (STATUS_DESC), 'NULL').

    "', DBCONN_NAME =" ' | NVL (TO_CHAR (DBCONN_NAME), e ') | " ', SUCESS_ROWS =' | NVL (TO_CHAR (SUCESS_ROWS), 'NULL').

    ', FAILED_ROWS =' | NVL (TO_CHAR (FAILED_ROWS), 'NULL') |', ERROR_CODE = ' | NVL (TO_CHAR (ERROR_CODE), 'NULL') |', NUM_RETRIES =' | NVL (TO_CHAR (NUM_RETRIES), 'NULL').

    ', READ_THRUPUT =' | NVL (TO_CHAR (READ_THRUPUT), 'NULL') |', LAST_UPD = ' | NVL (TO_CHAR (LAST_UPD), 'NULL') |', RUN_STEP_WID = "' | NVL (TO_CHAR (RUN_STEP_WID), 'NULL').

    "', W_INSERT_DT = ' | NVL (TO_CHAR (W_INSERT_DT), 'NULL') |', W_UPDATE_DT = ' | NVL (TO_CHAR (W_UPDATE_DT), 'NULL').

    ', START_DATE_WID =' | NVL (TO_CHAR (START_DATE_WID), 'NULL') |', END_DATE_WID = ' | NVL (TO_CHAR (END_DATE_WID), 'NULL') |', START_TIME =' |

    NVL (TO_CHAR (START_TIME), 'NULL') |', END_TIME =' | NVL (TO_CHAR (END_TIME), 'NULL'). "WHERE INTEGRATION_ID ="' | INTEGRATION_ID | " « ; »  OF XXAFL_MON_FACTS_F;

    The above query creates instructions of update that must be executed 1000 times and the time required to update the 1000 lines should be followed.

    Thanks in advance!

    Code horribly wrong!

    Why this approach?

    Dynamic SQL is almost NEVER needed in PL/SQL. And if you think it's necessary and taking into account what is displayed as being problems here, you have a 99% chance of being wrong.

    This 1% where dynamic SQL is necessary, he will WITH bind variables to create shareable SQL, decrease memory requests, decrease the likelihood of a fragmented shared reel and decrease the burning CPU cycles on hard analysis.

    An example below. Your approach is the 1st. One that is slower than the correct approach to 37 (x_!) ...

    SQL> create table t ( n number );
    
    Table created.
    
    SQL>
    SQL> var ITERATIONS number;
    SQL> exec :ITERATIONS := 100000;
    
    PL/SQL procedure successfully completed.
    
    SQL>
    SQL>
    SQL> TIMING START "INSERTs using Hard Parsing"
    SQL> declare
      2          i      integer;
      3  begin
      4          for i in 1..:ITERATIONS
      5          loop
      6                  execute immediate 'insert into t values ('||i||')';
      7          end loop;
      8          commit;
      9  end;
    10  /
    
    PL/SQL procedure successfully completed.
    
    SQL> TIMING SHOW
    timing for: INSERTs using Hard Parsing
    Elapsed: 00:02:00.33
    SQL>
    SQL> TIMING START "INSERTs using Soft Parsing"
    SQL> declare
      2          i      integer;
      3  begin
      4          for i in 1..:ITERATIONS
      5          loop
      6                  execute immediate 'insert into t values ( :1 )' using i;
      7          end loop;
      8          commit;
      9  end;
    10  /
    
    PL/SQL procedure successfully completed.
    
    SQL> TIMING SHOW
    timing for: INSERTs using Soft Parsing
    Elapsed: 00:00:06.06
    SQL> drop table t;
    
    Table dropped.
    
    SQL> create table t( n number );
    
    Table created.
    
    SQL>
    SQL>
    SQL> TIMING START "INSERTs using a single parse and repeatable statement handle "
    SQL> declare
      2          i      integer;
      3  begin
      4          for i in 1..:ITERATIONS
      5          loop
      6                  insert into t values ( i );
      7          end loop;
      8          commit;
      9  end;
    10  /
    
    PL/SQL procedure successfully completed.
    
    SQL> TIMING SHOW
    timing for: INSERTs using a single parse and repeatable statement handle
    Elapsed: 00:00:04.81
    SQL>
    
  • retrieve id WCS jsp site without using ics. SQL

    Hello

    Is it possible that I can get my current site in JSP siteId without using ics. SQL tags and recovering from the publishing table

    We are trying to apply a search lucene for loading the assets in the current site only.

    Thanks in advance for your help.

    Use the code to do so below.

    Don't forget to import publication.tld

    Kind regards

    Ravi G

  • Could not get the native web service response to Oracle using a PL/SQL &lt; Message &gt; function &lt;! [CDATA [component "WS_CALC" must be said]] &gt; &lt; / Message &gt;

    Hi, we have a problem with oracle native web service access using a PL/SQL function. We are running out of ideas how to solve the problem. Someone would be so nice to take a look at our case. Thank you much in advance. Best regards, Smiljana

    CREATE TABLE for_web_info (some_hello_text VARCHAR2 (150), when_inserted DATE, we_are_from VARCHAR2 (30));

    INSERT INTO for_web_info VALUES ('HI everyone :-) ', SYSDATE, 'Ljubljana, Slovenia');

    CREATE OR REPLACE

    PACKAGE ws_calc AUTHID CURRENT_USER AS

    FUNCTION CalcProduct (a NUMBER by DEFAULT 1,

    b in on NUMBER,

    g NUMBER of OUTPUT)

    RETURN NUMBER;

    END ws_calc;

    /

    CREATE OR REPLACE

    PACKAGE ws_calc AS BODY

    FUNCTION CalcProduct (a NUMBER by DEFAULT 1,

    b in on NUMBER,

    g NUMBER of OUTPUT)

    RETURN NUMBER IS

    product NUMBER;

    BEGIN

    SELECT SUM (1) IN the for_web_info OF g;

    product: = a * b;

    RETURN any product;

    END;

    END;

    /

    Our two DBA done all the steps described in the manual Oracle® XML DB's Guide Developer, 11 g Release 2 (11.2), E23094-04, February 2014, section using Oracle DB native XML Web Services.

    Access us two wsdl with browser without problem and get two of them. We also receive web serivce response which databese of query table.

    http://our_db:8080 / orawsv? WSDL

    http://our_db:8080 / orawsv/OUR_SCHEMA/WS_CALC/CALCPRODUCT? WSDL

    ---------------

    | First WSDL.

    ---------------

    <? XML version = "1.0"? >

    " < name definitions = targetNamespace"orawsv"=" http://xmlns.Oracle.com/orawsv "" "

    " xmlns =" http://schemas.xmlsoap.org/wsdl/ "

    ' xmlns:tns = ' http://xmlns.Oracle.com/orawsv "" "

    ' xmlns:soap = ' http://schemas.xmlsoap.org/WSDL/SOAP/ "

    " container = ' http://www.w3.org/2001/XMLSchema "

    " xmlns: xsi =" http://www.w3.org/2001/XMLSchema-instance "

    " xsi: schemaLocation =" http://schemas.xmlsoap.org/wsdl/ http://schemas.xmlsoap.org/wsdl/"> ".

    < types >

    < xsd: Schema

    " targetNamespace = ' http://xmlns.Oracle.com/orawsv "" "

    elementFormDefault = "qualified" >

    < xsd: element name = "query" >

    < xsd: complexType >

    < xsd: SEQUENCE >

    < xsd: element name = "DDL_text" type = "xsd: String".

    minOccurs = "0" maxOccurs = "unbounded" / >

    < xsd: element name = 'query_text' >

    < xsd: complexType >

    < xsd:simpleContent >

    < xsd:extension base = "XSD: String" >

    < xsd: attribute name = "type" >

    < xsd:simpleType >

    < xsd:restriction base = "xsd:NMTOKEN" >

    < value xsd: Enumeration = "SQL" / >

    < value xsd: Enumeration = "XQUERY" / >

    < / xsd:restriction >

    < / xsd:simpleType >

    < / xsd: attribute >

    < / xsd:extension >

    < / xsd:simpleContent >

    < / xsd: complexType >

    < / xsd: element >

    < xsd: Choice minOccurs = "0" maxOccurs = "unbounded" >

    < xsd: element name = "bind" >

    < xsd: complexType >

    < xsd:simpleContent >

    < xsd:extension base = "XSD: String" >

    < xsd: attribute name = "name" type = "xsd: String" / >

    < / xsd:extension >

    < / xsd:simpleContent >

    < / xsd: complexType >

    < / xsd: element >

    < xsd: element name = "bindXML" >

    < xsd: complexType >

    < xsd: SEQUENCE >

    < xsd: all / >

    < / xsd: SEQUENCE >

    < / xsd: complexType >

    < / xsd: element >

    < / xsd: Choice >

    < xsd: element name = "null_handling" minOccurs = "0" >

    < xsd:simpleType >

    < xsd:restriction base = "xsd:NMTOKEN" >

    < value xsd: Enumeration = "DROP_NULLS" / >

    < value xsd: Enumeration = "NULL_ATTR" / >

    < value xsd: Enumeration = "EMPTY_TAG" / >

    < / xsd:restriction >

    < / xsd:simpleType >

    < / xsd: element >

    < xsd: element name = "max_rows" type = "positiveInteger" minOccurs = "0" / >

    < xsd: element name = "skip_rows" type = "positiveInteger" minOccurs = "0" / >

    < xsd: element name = "pretty_print" type = "xsd: Boolean" minOccurs = "0" / >

    < xsd: element name = "indentation_width" type = "positiveInteger" minOccurs = "0" / >

    < xsd: element name = "rowset_tag" type = "xsd: String" minOccurs = "0" / >

    < xsd: element name = "row_tag" type = "xsd: String" minOccurs = "0" / >

    < xsd: element name = "item_tags_for_coll" type = "xsd: Boolean" minOccurs = "0" / >

    < / xsd: SEQUENCE >

    < / xsd: complexType >

    < / xsd: element >

    < xsd: element name = "queryOut" >

    < xsd: complexType >

    < xsd: SEQUENCE >

    < xsd: all / >

    < / xsd: SEQUENCE >

    < / xsd: complexType >

    < / xsd: element >

    < / xsd: Schema >

    < / types >

    < name of message = "QueryInput" >

    < name of part = element "body" = "tns:query" / >

    < / message >

    < name of the message 'XMLOutput' = >

    < name of part = element "body" = "tns:queryOut" / >

    < / message >

    < portType name = "ORAWSVPortType" >

    < operation name = "XMLFromQuery" >

    < input message = "tns:QueryInput" / >

    < output message = "tns:XMLOutput" / >

    < / operation >

    < / portType >

    < connection name = "ORAWSVBinding" type = "tns:ORAWSVPortType" >

    " < style: soap = transport = 'document' binding ' http://schemas.xmlsoap.org/SOAP/HTTP "/>

    < operation name = "XMLFromQuery" >

    " < soap: operation soapAction = ' http://our_db:8080 / orawsv "/>

    < input >

    < use of soap: body = "literal" / >

    < / Entry >

    < output >

    < use of soap: body = "literal" / >

    < / output >

    < / operation >

    < / binding >

    < service name = "ORAWSVService" >

    < documentation > Oracle Web Service < / documentation >

    < name of port = "ORAWSVPort" binding = "tns:ORAWSVBinding" >

    " < soap: address location = ' http://our_db:8080 / orawsv "/>

    < / port >

    < / service >

    < / definitions >

    ----------------

    | Second WSDL.

    ----------------

    <? XML version = "1.0"? >

    < name of definitions = "CALCPRODUCT."

    " targetNamespace = ' http://xmlns.Oracle.com/orawsv/OUR_SCHEMA/WS_CALC/CALCPRODUCT "" "

    " xmlns =" http://schemas.xmlsoap.org/wsdl/ "

    ' xmlns:tns = ' http://xmlns.Oracle.com/orawsv/OUR_SCHEMA/WS_CALC/CALCPRODUCT "" "

    " container = ' http://www.w3.org/2001/XMLSchema "

    ' xmlns:soap = ' http://schemas.xmlsoap.org/WSDL/SOAP/ ">

    < types >

    " < xsd: Schema targetNamespace = ' http://xmlns.Oracle.com/orawsv/OUR_SCHEMA/WS_CALC/CALCPRODUCT "" "

    elementFormDefault = "qualified" >

    < xsd: element name = "SNUMBER-CALCPRODUCTInput" >

    < xsd: complexType >

    < xsd: SEQUENCE >

    < xsd: element name = "G-NUMBER-OUT" >

    < xsd: complexType / >

    < / xsd: element >

    < xsd: element name = "B-NUMBER-INOUT" type = "xsd: double" / >

    < xsd: element name = "A-NUMBER-IN" minOccurs = "0" maxOccurs = "1" type = "xsd: double" / >

    < / xsd: SEQUENCE >

    < / xsd: complexType >

    < / xsd: element >

    < xsd: element name = "CALCPRODUCTOutput" >

    < xsd: complexType >

    < xsd: SEQUENCE >

    < xsd: element name = "RETURN" type = "xsd: double" / >

    < xsd: element name = "G" type = "xsd: double" / >

    < xsd: element name = "B" type = "xsd: double" / >

    < / xsd: SEQUENCE >

    < / xsd: complexType >

    < / xsd: element >

    < / xsd: Schema >

    < / types >

    < name of message = "CALCPRODUCTInputMessage" >

    < name of part = "parameters" element = "tns:SNUMBER - CALCPRODUCTInput" / >

    < / message >

    < name of message = "CALCPRODUCTOutputMessage" >

    < name of part = "parameters" element = "tns:CALCPRODUCTOutput" / >

    < / message >

    < portType name = "CALCPRODUCTPortType" >

    < operation name = "CALCPRODUCT" >

    < input message = "tns:CALCPRODUCTInputMessage" / >

    < output message = "tns:CALCPRODUCTOutputMessage" / >

    < / operation >

    < / portType >

    < connection name = "CALCPRODUCTBinding".

    Type = "tns:CALCPRODUCTPortType" >

    " < style: soap = transport = 'document' binding ' http://schemas.xmlsoap.org/SOAP/HTTP "/>

    < operation name = "CALCPRODUCT" >

    < soap: operation

    soapAction = "CALCPRODUCT" / >

    < input >

    < soap body parts: = 'settings' use = "literal" / >

    < / Entry >

    < output >

    < soap body parts: = 'settings' use = "literal" / >

    < / output >

    < / operation >

    < / binding >

    < service name = "CALCPRODUCTService" >

    < documentation > Oracle Web Service < / documentation >

    < name of port = "CALCPRODUCTPort" binding = "tns:CALCPRODUCTBinding" >

    < address soap:

    " location = ' http://our_db:8080 / orawsv/OUR_SCHEMA/WS_CALC/CALCPRODUCT "/>

    < / port >

    < / service >

    < / definitions >

    -----------------

    | SQL Developer |

    -----------------

    SET serveroutput ON

    -------------

    | First WS.

    -------------

    DECLARE

    V_SOAP_REQUEST XMLTYPE: = XMLTYPE (' <? xml version = "1.0"? > < env:Envelope xmlns:env = "http://www.w3.org/2002/06/soap-envelope " > < env:Body > < query xmlns = "http://xmlns.oracle.com/orawsv" > < type of the argument texte_requete = "SQL" > <!) ([CDATA [SELECT * FROM for_web_info WHERE the INSTR (UPPER (we_are_from),: e) > 0]] > < / query_text > < link name 'e' = > SLOVENIA < / bind > < false pretty_print > < / pretty_print > < / query > < / env:Body > < / env:Envelope > ');

    V_SOAP_REQUEST_TEXT CLOB: = V_SOAP_REQUEST.getClobVal ();

    V_REQUEST UTL_HTTP. REQ;

    V_RESPONSE UTL_HTTP. RESP;

    V_BUFFER VARCHAR2 (1024);

    URL VARCHAR2 (4000): = ' http://our_db:8080 / orawsv ';

    BEGIN

    V_REQUEST: = UTL_HTTP. BEGIN_REQUEST (URL = > URL, METHOD = > 'POST');

    UTL_HTTP. SET_AUTHENTICATION (R = > V_REQUEST, username = > 'OUR_U', PASSWORD = > 'OUR_P'); -not case-sensitive

    V_REQUEST. METHOD: = 'POST';

    UTL_HTTP. SET_HEADER (R = > V_REQUEST, NAME = > 'Content-Length', VALUE = > DBMS_LOB.) GETLENGTH (V_SOAP_REQUEST_TEXT));

    UTL_HTTP. WRITE_TEXT (R = > V_REQUEST, DATA = > V_SOAP_REQUEST_TEXT);

    V_RESPONSE: = UTL_HTTP. GET_RESPONSE (V_REQUEST);

    LOOP

    UTL_HTTP. READ_LINE (V_RESPONSE, V_BUFFER, TRUE);

    DBMS_OUTPUT. PUT_LINE (V_BUFFER);

    END LOOP;

    UTL_HTTP. END_RESPONSE (V_RESPONSE);

    EXCEPTION

    WHEN UTL_HTTP. END_OF_BODY THEN

    UTL_HTTP. END_RESPONSE (V_RESPONSE);

    END;

    anonymous block filled

    " <? xml version ="1.0"? > < envelope soap: xmlns:soap = ' http://www.w3.org/2002/06/SOAP-envelope ' > < soap: Body > < queryOut xmlns = " http://xmlns.Oracle.com/orawsv "> "

    < set of LINES > < ROW > < SOME_HELLO_TEXT > HI everybody :-) < / SOME_HELLO_TEXT > < WHEN_INSERTED > 03.10.14 < / WHEN_INSERTED > < WE_ARE_FROM > Ljubljana, Slovenia < / WE_ARE_FROM > < / ROW > < / rowset > < / queryOut > < / soap: Body > < / envelope soap: >

    --------------

    | Second WS.

    --------------

    DECLARE

    V_SOAP_REQUEST XMLTYPE: = XMLTYPE ("<?") XML version = "1.0"? > < soap envelope: xmlns:soap = "http://www.w3.org/2002/06/soap-envelope" > < soap: Body > < xmlns SNUMBER-CALCPRODUCTInput = ""http://xmlns.oracle.com/orawsv/OUR_SCHEMA/WS_CALC/CALCPRODUCT"(> < A-NUMBER-IN > 2 < / A-NUMBER-IN > < B-NUMBER-INOUT > 3 < / B-NUMBER-INOUT > < R-NUMBER-OUT / > < / SNUMBER-CALCPRODUCTInput > < / soap: Body > < / SOAP: envelope > '); "

    V_SOAP_REQUEST_TEXT CLOB: = V_SOAP_REQUEST.getClobVal ();

    V_REQUEST UTL_HTTP. REQ;

    V_RESPONSE UTL_HTTP. RESP;

    V_BUFFER VARCHAR2 (1024);

    URL VARCHAR2 (4000): = ' http://our_db:8080 / orawsv/OUR_SCHEMA/WS_CALC/CALCPRODUCT ';

    BEGIN

    V_REQUEST: = UTL_HTTP. BEGIN_REQUEST (URL = > URL, METHOD = > 'POST');

    UTL_HTTP. SET_AUTHENTICATION (R = > V_REQUEST, username = > 'OUR_U', PASSWORD = > 'OUR_P'); -not case-sensitive

    V_REQUEST. METHOD: = 'POST';

    UTL_HTTP. SET_HEADER (R = > V_REQUEST, NAME = > 'Content-Length', VALUE = > DBMS_LOB.) GETLENGTH (V_SOAP_REQUEST_TEXT));

    UTL_HTTP. WRITE_TEXT (R = > V_REQUEST, DATA = > V_SOAP_REQUEST_TEXT);

    V_RESPONSE: = UTL_HTTP. GET_RESPONSE (V_REQUEST);

    LOOP

    UTL_HTTP. READ_LINE (V_RESPONSE, V_BUFFER, TRUE);

    DBMS_OUTPUT. PUT_LINE (V_BUFFER);

    END LOOP;

    UTL_HTTP. END_RESPONSE (V_RESPONSE);

    EXCEPTION

    WHEN UTL_HTTP. END_OF_BODY THEN

    UTL_HTTP. END_RESPONSE (V_RESPONSE);

    END;

    anonymous block filled

    <? XML version = "1.0"? >

    " < envelope soap: xmlns:soap = ' http://www.w3.org/2002/06/SOAP-envelope/ ">

    < soap: Body >

    < soap: Fault >

    < Code: soap >

    < soap: value > SOAP: sender < / SOAP: value >

    < / Code: soap >

    entry processing < soap: reason > error < / SOAP: reason >

    < soap: detail >

    " < OracleErrors xmlns =" http://xmlns.Oracle.com/orawsv/faults "> "

    So OracleError >

    < ErrorNumber > ORA-19202 < / ErrorNumber >

    < message > <! [CDATA [error has occurred in the processing of XML]] > < / Message >

    < / OracleError >

    So OracleError >

    < ErrorNumber > ORA-06550 < / ErrorNumber >

    < message > <! [CDATA [line 1, column 24:]] > < / Message >

    < / OracleError >

    So OracleError >

    < ErrorNumber > PLS-00302 < / ErrorNumber >

    < message > <! [CDATA [component "WS_CALC" must be said]] > < / Message >

    < / OracleError >

    So OracleError >

    < ErrorNumber > ORA-06550 < / ErrorNumber >

    < message > <! [CDATA [line 1, column 7:]]

    [[PL/SQL: statement ignored]] > < / Message >

    < / OracleError >

    < / OracleErrors >

    < / Details: soap >

    < / soap fault: >

    < / soap: Body >

    < / envelope soap: >

    With reference APEX web service, the response is exactly the same and apex_web_service.make_request also work.

    Thanks again.

    The SOAP request is not correct.

    must be:

    So again, it does not solve the problem:

    -Which user you are using to authenticate on the other side?

    If it's another user the owner of the package, then of course you must grant the execute privilege appropriate to this user (and possibly one explicit SELECT on the table referenced too privilege).

  • error in pseudo-column "DECODE" can be used within an SQL statement

    Hi gurus,

    Your help is grealty appreciated. Please help me.


    I'm trying to see if I can use the function decode as below and get the error, here below vPlatformfrom value would be QA or MTS


    vDataBase1 :='@'|| Decode (vPlatformfrom, 'STD', 'STD', 'QA', 'QA')


    Before we check function NVL to a single platform, but now we need the database based on the platform is here.

    -vDataBase1 :='@'|| NVL (vPlatformto, 'MTS');

    Error:

    PLS-00204: pseudo-column "DECODE" or function may be used within an SQL statement

    > So, here, instead of the decode function, I can use this case as below:

    Well... you can, but why?  In your CASE, you simply return the same value as the variable.

    You might as well use: vDataBase1: = vPlatformfrom;  It would reach exactly the same thing.

    If vPlatformfrom can be a null value, you will need to decide what database to use or an exception.  I think you're original code (NVL) were probably more correct, but I can't decide which.

    (and don't bother selecting double, it is an unnecessary sql statement which must be analysed, etc..)

  • Can I use only the a collection of photographs with Photos Apple '&amp;' Adobe Creative Cloud

    I am new to Adobe Creative Cloud and have used Apple base 'Photos' collect/store my photos (mainly photographs of family more than 40 years) - Great to take pictures on my iPad to show parents.

    I bought Creative cloud not only to improve potentially good photographs of family and finally properly organize them, but to use it with my new found passion for digital SLR photography.

    However, I now seem to have two series double massive photographs. The one with the Photos of the Apple and the other with Lightroom. Is there a simple way, I use two Photos Apple & Lightroom just the single series of photographs, (though that I need to make changes to the image of files/folders exclusively through Lightroom) other than to have to constantly import/export photographs of an application to the hard drive before, before import/export photos to the other application?

    Thanking you in advance,

    M.

    Hello mv.

    The time that you have moved your iPhotos to Lightroom gallery, I believe that you used the Lightroom plugin to move the library

    There is also an option while you import images from iPhoto "keep files referenced in your iPhoto library.

    If this option is not duplicate images.

    Please let us know if it helps.

    Kind regards

    Tanuj

  • Default presentation variable used in the SQL filter expression

    Hello
    I am trying to use a default value for a variable used in a sql expression in a filter presentation and could use assistance on why obiee stifles the syntax.

    I have a report prompted with a prompt on the name of the month (variable presentation framework - pres_month_name). The value read is used in a filter as an sql expression. The sql expression is a DEAL on the variable of presentation and its conversion to a number based on business rules.

    In the sql expression, I give you the presentation variable a default value for a variable of repository - rep_default_month_name. Repository variable is correct and no, based on business rules, returns an appropriate default month name.

    Now, if I hard code the value by default, there is no problem. Here is a sample of the filter:
    The month number less than or equal to * DEAL "{pres_month_name} {OCT}" WHEN "NOV" THEN 10 WHEN... END *.

    Notice that the variable of presentation is between single quotes, because this is an area of character. Once more, it works fine, but I don't want to hardcode the default, I want it based on the variable repository, therefore:

    The month number less than or equal to * DEAL '{pres_month_name} {ValueOf (rep_default_month_name)}' WHEN 'NOV' THEN 10 WHEN... END *.

    By having this syntax for default of the variable of the presentation, I receive a message from the incorrect values in a filter.

    This report is not only used on a dashboard, but used in a briefing book as well. Whenever a briefing book is updated, by default the presentation variable is used, because obviously, the presentation is not available in a briefing, and I don't want to use a hard-coded value.

    I could duplicate the report and adjust the sql to not use the presentation variable, but always use the repository variable that returns a month by default, but I would be duplication of effort and I have to do this on several requests.

    Thanks for the help!

    Try this syntax described in the blog of Shiva that follows...

    http://shivabizint.WordPress.com/2008/10/02/Oracle-BI-EE-variables-overview/

  • Updates using the single SQL Update statement.

    Hi guys,.

    I got an interview... and was not able to answer a question.

    In view of the table emp... need to update the salary with the following requirement by using an SQL statement.

    1 update salary + 1000 for employees who receive pay between 500 and 1000
    2 update salary + 500 for employees who receive wages between 1001 and 1500

    The two above the requirement should be made using only a SQL update statement... can someone tell me how to do?
    update emp
      set salary   = case when salary between 500 and 1000
                                then salary + 1000
                                when salary between 1001 and 1500
                                then salary + 500
                          end;
    

    Concerning
    Arun

  • Retrieve and display a result set using the dynamic sql?

    Hi all

    How would display a result set in Oracle using the dynamic SQL? Reason being, the table where I'd retrieve and display the result set is a GLOBAL TEMP TABLE created in a stored procedure. If I try to use the loop as usual, the compiler complains that the table does not exist. This makes sense because the compiler does not recognize the table because it is created dynamically. Here is an example:

    create or replace PROCEDURE maketemptab IS
    sql_stmt VARCHAR2 (500);
    OutputString VARCHAR2 (50);

    BEGIN
    -create temporary table
    sql_stmt: = ' CREATE of TABLE TEMPORARY GLOBAL globtemptab (id NUMBER, col1 VARCHAR2 (50))';
    EXECUTE IMMEDIATE sql_stmt;
    dbms_output.put_line ('... created table ');

    -Insert a row into the temporary table
    sql_stmt: = "INSERT INTO globtemptab values (1, 'some data of a test')';"
    EXECUTE IMMEDIATE sql_stmt;
    dbms_output.put_line ('... inserted row ');

    -Insert a row into the temporary table
    sql_stmt: = ' INSERT INTO globtemptab values (2, "some more test data");
    EXECUTE IMMEDIATE sql_stmt;
    dbms_output.put_line ('... inserted row ');

    -Select the row on temporary table
    sql_stmt: = 'SELECT col1 FROM globtemptab WHERE id = 1';
    EXECUTE IMMEDIATE sql_stmt INTO outputstring;
    dbms_output.put_line ('... selected line: ' | outputstring);

    -drop temporary table
    sql_stmt: = 'DROP TABLE globtemptab;
    EXECUTE IMMEDIATE sql_stmt;
    dbms_output.put_line ('... moved table ');

    -display the result set
    for tabdata loop (select col1 from globtemptab)
    dbms_output.put_line ('... test of recovered data are' | tabdata.col1)
    end loop;
    end;


    In short, how to rewrite the SQL below the comment "to display the result set" using the dynamic sql?

    Thank you
    Amedeo.

    Hello

    Try this:

    CREATE OR REPLACE PROCEDURE maketemptab IS
       sql_stmt     VARCHAR2(500);
       outputstring VARCHAR2(50);
       v_cursor     SYS_REFCURSOR;
       v_col1       VARCHAR2(30);
    BEGIN
       -- create temp table
       sql_stmt := 'CREATE GLOBAL TEMPORARY TABLE globtemptab(id NUMBER, col1 VARCHAR2(50))';
       EXECUTE IMMEDIATE sql_stmt;
       dbms_output.put_line('...table created');
    
       -- insert row into temp table
       sql_stmt := 'INSERT INTO globtemptab values (1, ''some test data'')';
       EXECUTE IMMEDIATE sql_stmt;
       dbms_output.put_line('...row inserted');
    
       -- insert row into temp table
       sql_stmt := 'INSERT INTO globtemptab values (2, ''some more test data'')';
       EXECUTE IMMEDIATE sql_stmt;
       dbms_output.put_line('...row inserted');
    
       -- select row from temp table
       sql_stmt := 'SELECT col1 FROM globtemptab WHERE id=1';
       EXECUTE IMMEDIATE sql_stmt
          INTO outputstring;
       dbms_output.put_line('...row selected: ' || outputstring);
    
       OPEN v_cursor FOR 'SELECT col1 FROM globtemptab';
    
       LOOP
          FETCH v_cursor
             INTO v_col1;
          EXIT WHEN v_cursor%NOTFOUND;
          dbms_output.put_line('...test data retrieved is' || v_col1);
       END LOOP;
       CLOSE v_cursor;
    
       -- drop temp table
       sql_stmt := 'DROP TABLE globtemptab';
       EXECUTE IMMEDIATE sql_stmt;
       dbms_output.put_line('...table dropped');
    END;
    /
    

    Kind regards

  • Tables created in a stored procedure cannot be used with dynamic SQL? The impact?

    There is a thread on the forum which explains how to create tables within a stored procedure (How to create a table in a stored procedure , however, it does create a table as such, but not how to use it (insert, select, update, etc.) the table in the stored procedure.) Looking around and in the light of the tests, it seems that you need to use dynamic SQL statements to execute ddl in a stored procedure in Oracle DB. In addition, it also seems that you cannot use dynamic SQL statements for reuse (insert, select, update, etc.) the table that was created in the stored procedure? Is this really the case?

    If this is the case, I am afraid that if tables cannot be 'created and used"in a stored procedure using the dynamic SQL, as is the case with most of the servers of DB dynamic SQL is not a part of the implementation plan and, therefore, is quite expensive (slow). This is the case with Oracle, and if yes what is the performance impact? (Apparently, with Informix, yield loss is about 3 - 4 times, MS SQL - 4 - 5 times and so on).

    In summary, tables created within a stored procedure cannot be 'used' with dynamic SQL, and if so, what is the impact of performance as such?

    Thank you and best regards,
    Amedeo.

    Published by: AGF on March 17, 2009 10:51

    AGF says:
    Hi, Frank.

    Thank you for your response. I understand that the dynamic SQL is required in this context.

    Unfortunately, I am yet to discover "that seeks to" using temporary tables inside stored procedures. I'm helping a migration from MySQL to Oracle DB, and this was one of the dilemmas encountered. I'll post what is the attempt, when more.

    In Oracle, we use [global temporary Tables | http://www.psoug.org/reference/OLD/gtt.html?PHPSESSID=67b3adaeaf970906c5e037b23ed380c2] aka TWG these tables need only be created once everything like a normal table, but they act differently when they are used. The data inserted in TWG will be visible at the session that inserted data, allowing you to use the table for their own temporary needs while not collide with them of all sessions. The data of the TWG will be automatically deleted (if not deleted programmatically) when a) a commit is issued or b) the session ends according to the parameter that is used during the creation of the TWG. There is no real need in Oracle to create tables dynamically in code.

    I noticed that many people say that the "Creation of the tables within a stored procedure" is not a good idea, but nobody seems necessarily explain why? Think you could elaborate a little bit? Would be appreciated.

    The main reason is that when you come to compile PL/SQL code on the database, all explicit references to tables in the code must correspond to an existing table, otherwise a djab error will occur. This is necessary so that Oracle can validate the columns that are referenced, the data types of those columns etc.. These compilation controls are an important element to ensure that the compiled code is as error free as possible (there is no accounting for the logic of programmers though ;)).

    If you start to create tables dynamically in your PL/SQL code, so any time you want to reference this table you must ensure that you write your SQL queries dynamically too. Once you start doing this, then Oracle will not be able to validate your SQL syntax, check the types of data or SQL logic. This makes your code more difficult to write and harder to debug, because inevitably it contains errors. It also means that for example if you want to write a simple query to get that one out in a variable value (which would take a single line of SQL with static tables), you end up writing a dynamic slider all for her. Very heavy and very messy. You also get the situation in which, if you create tables dynamically in the code, you are also likely to drop tables dynamically in code. If it is a fixed table name, then in an environment multi-user, you get in a mess well when different user sessions are trying to determine if the table exists already or is the last one to use so they can drop etc. What headache! If you create tables with table names, then variable Dynamics not only make you a lot end up creating (and falling) of objects on the database, which can cause an overload on the update of the data dictionary, but how can ensure you that you clean the tables, if your code has an exception any. Indeed, you'll find yourself with redundant tables lying around on your database, may contain sensitive data that should be removed.

    With the TWG, you have none of these issues.

    Also, what is the impact on the performance of the dynamic SQL statements in Oracle? I read some contrasting opinions, some indicating that it is not a lot of difference between static SQL and SQL dynamic in more recent versions of Oracle DB (Re: why dynamic sql is slower than static sql is this true?)

    When the query runs on the database, there will be no difference in performance because it is just a request for enforcement in the SQL engine. Performance problems may occur if your dynamic query is not binding variable in the query correctly (because this would cause difficult analysis of the query rather than sweet), and also the extra time, to dynamically write the query running.

    Another risk of dynamic query is SQL injection which may result in a security risk on the database.

    Good programming will have little need for the tables of dynamically created dynamically or SQL.

Maybe you are looking for