Insertion of 2 items in the PL/SQL procedure

Hello

I am writing a database to a control system which is as follows:

Drop table Orders cascade constraints;
Drop type item_type;
Type of projection Item_nested;

Create or replace Type item_type () AS Object
Cat_code Varchar2 (6).
Amount_ord Number (3).
Cost Number (5.2));
/

Create or replace Type item_nested as the item_type table;
/

Create Table orders)
Key primary forced pkorder of Order_no Varchar2 (8).
Client_name Varchar2 (30),
AddressLine1 Varchar2 (20).
AddressLine2 Varchar2 (20).
City Varchar2 (20).
Code postal Varchar2 (10),
Country Varchar2 (20).
Order_items item_nested,
Order_date Date)
The nested Table Order_items
Store nested_items return in the form of index;

I wrote a PL/SQL procedure to enter all the necessary information including 1 item ordered (which is Order_items as a nested table). It's as follows:

CREATE OR REPLACE PROCEDURE add_1order (ordno IN VARCHAR2, Cust_name IN VARCHAR2, add1 IN VARCHAR2,
Add2 IN VARCHAR2, Addtown IN VARCHAR2, Pstcde IN VARCHAR2, addcountry IN VARCHAR2,
cat_cde IN VARCHAR2, Amnt_ord in NUMBERS, itemcost in NUMBER, ord_date IN DATE)
AS
BEGIN

DBMS_OUTPUT. Put_line ('Insert attempted");

INSERT INTO Orders (Order_no, client_name, AddressLine1, AddressLine2, city, postal code, country, order_items, Order_Date)
VALUES (ordno, Cust_name, add1, add2, Addtown, Pstcde, addcountry, item_nested (item_type (cat_cde, Amnt_ord, itemcost))
ord_date);

DBMS_OUTPUT. Put_line ('Insert successful");

EXCEPTION
WHILE OTHER THEN DBMS_OUTPUT. PUT_LINE ('ERROR');
DBMS_OUTPUT. Put_line ('procedure failed");
END;
/

I need to write another procedure that will allow me to insert elements of order 2, but I can't handle

Can anyone help please?

See you soon

SG200407 wrote:

Just another question - is possible in this PL/SQL statement for only 2 articles are updated and not more?

Ensure that:

CREATE OR REPLACE
  PROCEDURE add_order(
                      ordno      IN VARCHAR2,
                      Cust_name  IN VARCHAR2,
                      add1       IN VARCHAR2,
                      add2       IN VARCHAR2,
                      Addtown    IN VARCHAR2,
                      Pstcde     IN VARCHAR2,
                      addcountry IN VARCHAR2,
                      item_list  IN item_nested,
                      ord_date   IN DATE
                     )
    AS
    BEGIN
        IF item_list.count > 2
          THEN
            DBMS_OUTPUT.PUT_LINE ('Too many (' || item_list.count ||
                                    ') order items. Maximum number of items per order is 2.'
                                 );
            RAISE_APPLICATION_ERROR(
                                    -20900,
                                    'Too many (' || item_list.count ||
                                    ') order items. Maximum number of items per order is 2.'
                                   );
        END IF;

        DBMS_OUTPUT.PUT_LINE ('Insert attempted');

        INSERT
          INTO Orders
          VALUES(
                 ordno,
                 Cust_name,
                 add1,
                 add2,
                 Addtown,
                 Pstcde,
                 addcountry,
                 item_list,
                 ord_date
                );

        DBMS_OUTPUT.PUT_LINE ('Insert successful');

      EXCEPTION
        WHEN OTHERS
          THEN
            DBMS_OUTPUT.PUT_LINE ('ERROR');
            DBMS_OUTPUT.PUT_LINE ('Procedure failed');
END;
/
BEGIN
    add_order(
              1,
              'Customer1',
              '100 Main Street',
              NULL,
              'New York',
              '12345',
              'USA',
              item_nested(
                          item_type('book',1,45),
                          item_type('dvd',1,15)
                         ),
              sysdate
             );
END;
/
BEGIN
    add_order(
              1,
              'Customer1',
              '100 Main Street',
              NULL,
              'New York',
              '12345',
              'USA',
              item_nested(
                          item_type('book',1,45),
                          item_type('dvd',1,15),
                          item_type('cd',1,10)
                         ),
              sysdate
             );
END;
/
select * from Orders
/
SQL> CREATE OR REPLACE
  2    PROCEDURE add_order(
  3                        ordno      IN VARCHAR2,
  4                        Cust_name  IN VARCHAR2,
  5                        add1       IN VARCHAR2,
  6                        add2       IN VARCHAR2,
  7                        Addtown    IN VARCHAR2,
  8                        Pstcde     IN VARCHAR2,
  9                        addcountry IN VARCHAR2,
 10                        item_list  IN item_nested,
 11                        ord_date   IN DATE
 12                       )
 13      AS
 14      BEGIN
 15          IF item_list.count > 2
 16            THEN
 17              DBMS_OUTPUT.PUT_LINE ('Too many (' || item_list.count ||
 18                                      ') order items. Maximum number of items per order is 2.'
 19                                   );
 20              RAISE_APPLICATION_ERROR(
 21                                      -20900,
 22                                      'Too many (' || item_list.count ||
 23                                      ') order items. Maximum number of items per order is 2.'
 24                                     );
 25          END IF;
 26
 27          DBMS_OUTPUT.PUT_LINE ('Insert attempted');
 28
 29          INSERT
 30            INTO Orders
 31            VALUES(
 32                   ordno,
 33                   Cust_name,
 34                   add1,
 35                   add2,
 36                   Addtown,
 37                   Pstcde,
 38                   addcountry,
 39                   item_list,
 40                   ord_date
 41                  );
 42
 43          DBMS_OUTPUT.PUT_LINE ('Insert successful');
 44
 45        EXCEPTION
 46          WHEN OTHERS
 47            THEN
 48              DBMS_OUTPUT.PUT_LINE ('ERROR');
 49              DBMS_OUTPUT.PUT_LINE ('Procedure failed');
 50  END;
 51  /

Procedure created.

SQL> BEGIN
  2      add_order(
  3                1,
  4                'Customer1',
  5                '100 Main Street',
  6                NULL,
  7                'New York',
  8                '12345',
  9                'USA',
 10                item_nested(
 11                            item_type('book',1,45),
 12                            item_type('dvd',1,15)
 13                           ),
 14                sysdate
 15               );
 16  END;
 17  /
Insert attempted
Insert successful

PL/SQL procedure successfully completed.

SQL> BEGIN
  2      add_order(
  3                1,
  4                'Customer1',
  5                '100 Main Street',
  6                NULL,
  7                'New York',
  8                '12345',
  9                'USA',
 10                item_nested(
 11                            item_type('book',1,45),
 12                            item_type('dvd',1,15),
 13                            item_type('cd',1,10)
 14                           ),
 15                sysdate
 16               );
 17  END;
 18  /
Too many (3) order items. Maximum number of items per order is 2.
ERROR
Procedure failed

PL/SQL procedure successfully completed.

SQL> select * from Orders
  2  /

ORDER_NO CUSTOMER_NAME                  ADDRESSLINE1
-------- ------------------------------ --------------------
ADDRESSLINE2         TOWN                 POSTCODE   COUNTRY
-------------------- -------------------- ---------- --------------------
ORDER_ITEMS(CAT_CODE, AMOUNT_ORD, COST)
--------------------------------------------------------------------------------
ORDER_DAT
---------
1        Customer1                      100 Main Street
                     New York             12345      USA
ITEM_NESTED(ITEM_TYPE('book', 1, 45), ITEM_TYPE('dvd', 1, 15))
24-JAN-09

SQL> 

SY.

Tags: Database

Similar Questions

  • Cannot see the table in the p/sql procedure but can in normal sql

    Hello

    using 11.2.0.3

    that sql format

    Select schema_owner. < table > - it works in good sql and pl/sql get message table or view does not exist.

    Other fine tables.

    Y at - it a permission to have reference to the table in the pl/sql procedure rather than sql?

    Thank you

    Hello

    I'm glad you solved the problem!

    Don't forget to mark it as "answered".  It will help others with a similar problem, and it will save time for people answering questions on this forum.

  • Call the PL/SQL procedure with in out parameter of OIC clob

    Hello

    For a few days, I am facing a problem. I have to call the pl/sql procedure with colb parameter out. I use c ++ and OIC (don't ask me why :)).

    I use a pl/sql problem test procedure:

    create or replace function Test (longField outside clob) return number is
    Number of result;
    Start
    longField: = 'prefix ';
    Result: = 12;
    Return (result);
    end Test;

    So I do all the stuff with the connection to the DB,

    I prepare the statement: "start: res: = test(:param); end; »
    So I OCIHandleAlloc (m_pCtx-> hpEnv,
    (void *) & m_hpStatement,.
    OCI_HTYPE_STMT,
    0,
    (NULL);
    and
    OCIStmtPrepare (m_hpStatement,
    m_pCtx-> hpErr,
    (...),
    (...),
    OCI_NTV_SYNTAX,
    OCI_DEFAULT);

    Before the binding I prepare parameters. For a clob I devote to the lob Locator:

    OCIDescriptorAlloc ((dvoid *) m_pCtx-> hpEnv, (dvoid *) & m_pLobLocator,)
    (ub4) OCI_DTYPE_LOB (size_t) 0, (dvoid *) 0);
    OCILobEnableBuffering (m_pCtx-> hpContext, m_pCtx-> hpErr, (OCILobLocator *) m_pLobLocator);

    that I bind parameters using OCIBindByName and OCIStmtExecute statement execution.

    I get an error
    ---------------------------
    Microsoft Visual C++
    ---------------------------
    Unhandled exception in... (ORAOCIEI11. (DLL): 0xC0000005: Access Violation.

    My question is: is it possible to call the pl/sql procedure with parameter BEAK clob?
    If Yes, what steps I need to do to succeed?

    Thank you for your response.

    Hello

    Of course, it is possible :)

    Show that you are your piece of code that is binding.
    Are you sure you had correctly the lob descriptor in the call to bind?

  • Question: insertion of several lines in the MS Sql Server table using the DB adapter

    Hi all

    I managed to insert a single row in a table of MS SQL Server via the adapter DB to my process BPEL, but when I tried to insert in mutiple lines in the same table of MS SQL server, I encounter the error below.

    I use a DB SQL XA connection to connect to the server.

    Kindly help me to solve the problem. Thanks in advance.

    Error:

    " < bpelFault > < faultType > 0 < / faultType > < remoteFault xmlns =" http://schemas.Oracle.com/BPEL/extension "> < a name ="summary"part > < summary > exemption is is produced when the binding was used." Exception occurred during invocation of the JCA binding: "JCA binding run 'merge' reference operations have to: DBWriteInteractionSpec Execute Failed Exception." the merger failed. The descriptor name: [LoadCmpAggSpendStage.SapTable]. Caused by com.microsoft.sqlserver.jdbc.SQLServerException: incorrect syntax near ')'... Check the logs for the record output full DBAdapter before this exception. This exception is considered as reproducible, probably due to a communication failure. To be classified as not reproducible rather add property nonRetriableErrorCodes with the '102' value in the deployment descriptor (i.e. weblogic - RA.Xml). Auto retry a reproducible fault set composite.xml for this invoke these properties: jca.retry.interval, jca.retry.count and jca.retry.backoff. All properties are integers. ". The called JCA adapter threw an exception of resource. Please examine the error message above carefully to determine a resolution. < /Summary. (> < / piece > < part name = "detail" > < detail syntax > incorrect near ')'. < / details > < / piece > < part name = "code" > < code > 102 < / code > < / piece > < / remoteFault > < / bpelFault >

    Kind regards

    Balaji Rahmani

    It seems that in this case is called merge operation. If existing records (check primary key) are not there then it will be inserted on the other update. Check the syntax of the query that is created. It looks like she may have a supplement "). If you want to only insert then call insert operation and not merge.

  • 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>
    
  • Nested reading XML using XQUERY in the PL/SQL procedure

    I'm using Oracle 11 G.
    I have a PL/SQL procedure, which is reading XML using xquery XMLTYPE column in a table. The XML contains data of the DEPARTMENT and its SECTIONS. DEPARTMENT has a to-many with SECTIONS or a DEPARTMENT can have one or more SECTIONS, and there may be cases where the DEPARTMENT will have all SECTIONS.

    The XML structure is such that
    <DATA>
    label to identify a DEPARTMENT and all its corresponding SECTIONS.

    XML
    <ROWSET> 
    <DATA>
     <DEPARTMENT>
      <DEPARTMENT_ID>DEP1</DEPARTMENT_ID>
      <DEPARTMENT_NAME>myDEPARTMENT1</DEPARTMENT_NAME>
     </DEPARTMENT>
     <SECTIONS>
      <SECTIONS_ID>6390135666643567</SECTIONS_ID>
      <SECTIONS_NAME>mySection1</SECTIONS_NAME>
      </SECTIONS>
       <SECTIONS>
      <SECTIONS_ID>6390135666643567</SECTIONS_ID>
      <SECTIONS_NAME>mySection2</SECTIONS_NAME>
      </SECTIONS>
     </DATA>
     <DATA>
     <DEPARTMENT>
      <DEPARTMENT_ID>DEP2</DEPARTMENT_ID>
      <DEPARTMENT_NAME>myDEPARTMENT2</DEPARTMENT_NAME>
     </DEPARTMENT>
     <SECTIONS>
      <SECTIONS_ID>63902</SECTIONS_ID>
      <SECTIONS_NAME>mySection1</SECTIONS_NAME>
      </SECTIONS>
     </DATA>
    </ROWSET>
    XQUERY
    select
     department_id,
      department_name,
      sections_id,
      sections_name
    from
      OFFLINE_XML xml_list,
      xmltable(
        '
          for $department in $param/ROWSET/DATA
            return $department
        '
        passing xml_list.xml_file as "param"
        columns
          "DEPARTMENT_ID"   varchar2(100) path '//DEPARTMENT/DEPARTMENT_ID',
          "DEPARTMENT_NAME" varchar2(4000) path '//DEPARTMENT/DEPARTMENT_NAME',
          "SECTIONS_ID"     varchar2(100) path '//SECTIONS/SECTIONS_ID',
          "SECTIONS_NAME"   varchar2(4000) path '//SECTIONS/SECTIONS_NAME'
      ) section_list
    where
      xml_list.Status = 5
    The performance of the query, you receive an error
    ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton 
    sequence - got multi-item sequence
    It is natural because I have several sections, now how I'll handle this situation.

    It's the usual approach to manage several nested collections:

    SQL> select d.department_id
      2       , d.department_name
      3       , s.sections_id
      4       , s.sections_name
      5  from offline_xml t
      6     , xmltable(
      7         '/ROWSET/DATA'
      8         passing t.xml_file
      9         columns
     10           DEPARTMENT_ID   varchar2(20) path 'DEPARTMENT/DEPARTMENT_ID'
     11         , DEPARTMENT_NAME varchar2(30) path 'DEPARTMENT/DEPARTMENT_NAME'
     12         , SECTIONS        xmltype      path 'SECTIONS'
     13       ) d
     14     , xmltable(
     15         '/SECTIONS'
     16         passing d.sections
     17         columns
     18           SECTIONS_ID     varchar2(20) path 'SECTIONS_ID'
     19         , SECTIONS_NAME   varchar2(30) path 'SECTIONS_NAME'
     20      ) s
     21  ;
    
    DEPARTMENT_ID        DEPARTMENT_NAME                SECTIONS_ID          SECTIONS_NAME
    -------------------- ------------------------------ -------------------- ------------------------------
    DEP1                 myDEPARTMENT1                  6390135666643567     mySection1
    DEP1                 myDEPARTMENT1                  6390135666643567     mySection2
    DEP2                 myDEPARTMENT2                  63902                mySection1
     
    
  • The problem with ampersand in the PL/SQL procedure

    Dear Oracle experts,

    Please, help me to understand this case. I have the following code
    V_RESPONSE := UTL_HTTP.GET_RESPONSE (V_REQUEST);
    
          LOOP
             UTL_HTTP.READ_LINE (V_RESPONSE, V_BUFFER, FALSE);
             DATA_OUT := DATA_OUT || V_BUFFER;
          --DBMS_OUTPUT.PUT_LINE (V_BUFFER);
          END LOOP;
    And I'm getting DATA_OUT as
    <?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><ns:chargeSubscriberResponse xmlns:ns="http://ws.cube.az"><ns:return>&lt;?xml version="1.0" encoding="UTF-8"?>
    &lt;response>
         &lt;retval>-2200003&lt;/retval>
         &lt;retmsg>Invalid Service&lt;/retmsg>
         &lt;quantity>&lt;/quantity>
         &lt;cube-transaction-id>&lt;/cube-transaction-id>
    &lt;/response></ns:return></ns:chargeSubscriberResponse></soapenv:Body></soapenv:Envelope>
    A don't have to '&' in this output. I need to analyze this variable to clear all ampersands. How can I do?

    Just replace does not work... I tried
    PROCEDURE Clean_up_xml (v_xml IN OUT VARCHAR2)
       IS
       BEGIN
          WHILE INSTR (v_xml, 'lt;') > 0
          LOOP
             v_xml :=
                SUBSTR (v_xml, 1, INSTR (v_xml, 'lt;') - 2)
                || SUBSTR (v_xml, INSTR (v_xml, 'lt;') + 4);
          END LOOP;
       END;
    But no luck...

    Does not erase the procedure '& '. How can I disable ampersand in PL/SQL procedure?

    Thanks in advance.

    PS: I know SET DEFINE OFF. But it only works in SQL * MORE.
    SQL> declare
      2
      3    data_out clob :=
      4  '<?xml version="1.0" encoding="UTF-8"?>
      5  <response>
      6       <retval>-2200003</retval>
      7       <retmsg>Invalid Service</retmsg>
      8       <quantity></quantity>
      9       <cube-transaction-id></cube-transaction-id>
     10  > </response>' ;
     11
     12  begin
     13
     14    for rec in (
     15        select r.*
     16        from xmltable(
     17               xmlnamespaces(
     18                 'http://www.w3.org/2003/05/soap-envelope' as "soap"
     19               , 'http://ws.cube.az' as "ns"
     20               )
     21             , '/soap:Envelope/soap:Body/ns:chargeSubscriberResponse'
     22               passing xmlparse(document data_out)
     23               columns xml_return clob path 'ns:return'
     24             ) x
     25           , xmltable('/response'
     26               passing xmlparse(document x.xml_return)
     27               columns retval              number       path 'retval'
     28                     , retmsg              varchar2(30) path 'retmsg'
     29                     , quantity            number       path 'quantity'
     30                     , cube_transaction_id varchar2(30) path 'cube-transaction-id'
     31             ) r
     32    )
     33    loop
     34
     35      dbms_output.put_line('retval = '||rec.retval);
     36      dbms_output.put_line('retmsg = '||rec.retmsg);
     37      dbms_output.put_line('quantity = '||rec.quantity);
     38      dbms_output.put_line('cube_transaction_id = '||rec.cube_transaction_id);
     39
     40    end loop ;
     41
     42  end;
     43  /
    
    retval = -2200003
    retmsg = Invalid Service
    quantity =
    cube_transaction_id = 
    
    PL/SQL procedure successfully completed
     
    
  • How to call sql loader control file with in the pl/sql procedure

    Hi friends,

    I am doing a project in relation to the transfer data using queues. In the queue, I'll get a data delimited by tabs in the form of CLOB variable/message. I don't want to keep this dat in the oracle table.
    During the updating of the data in the table.

    1. don't want to write data to a file. (You want to access directly after the specific queue).

    2. as the data is in the form of delimited by tabs, I want to use sql loader concept.

    How can I call the ctrl charger sql file with in my pl/sql procedure. When I searched, most forums recommending the external procedure or a Java program.

    Please guide me on this issue. My preferrence is pl sql, but don't know the external procedure. If no other way, I'll try Java.

    I'm using oracle 9.2.0.8.0.

    Thanks in advance,
    Vimal...

    Or SQL * Loader, or external tables are designed to read data from a CLOB stored in the database. They both work on files stored on the file system. If you don't want the data to be written to a file, you have to roll your own parsing code. It is certainly possible. But it will be much less effective than SQL * Loader or external tables. And it is likely to lead to a little more code.

    The simplest possible thing that might work would be to use something like Tom Kyte string tokenization package to read a line in the CLOB, divide the component parts and save the different chips in a significant collection (i.e. an object type or a record type that matches the table definition). Of course, you need manage things like the conversion of strings to numbers or dates, rejecting the lines, writing to log files, etc.

    Justin

  • Call the PL/SQL procedure with different parameters?

    I use PL/SQL for web development. I have a page of PL/SQL which collects information and returns the user off site with one return url (another PL/SQL procedure).

    I have the return procedure with every documented return variable (default null) in order to always take the return. However, there are (reported... cannot reproduce because of the nature of the business) cases where a 404 error is returned because of the incompatibility of parameter.

    Is it possible to proceed regardless of the parameters? Someone at - it suggestions?

    Thank you!

    user2960509 wrote:

    My problem is that they sometimes send back of settings that do not match what I expect.

    Use the interface "+ flexible +" mod_plsql - see the Oracle® HTTP Server mod_plsql user's Guide for the documented details.

    The signature of the procedure parameter is as follows (it is called by mod_plsql using tables of name value pairs):

    create or replace procedure Scott.MyWebProc( name_array owa.vc_arr, value_array owa.vc_arr) is
    ...
    

    In your code, you just browse the berries to get the name values passed query string. You can even filled an associative array in your code (a table indexed by string and no number, where the index string represents the name of param)-this approach can make it pretty easy for the code make reference to a parameter, with little effort on your part to provide an interface to query by name for code to get the value of a parameter name.

    To enable the flexible (aka parameter 2) call interface, precede the call to web with an exclamation character. For example

    http://my-webserbver.my-domain.com/pls/dad/!scott.mywebproc?name-1=val-1&name-2=val-2..,name-n=val=n
    
  • Run the PL/SQL procedure periodically

    Hello everyone.

    Im working with Oracle 10 G R1.

    I need execute a PL/SQL procedure every 5 minutes.

    Can anyone send me an example or a link where I can study how to proceed?

    Thanks in advance and greetings to all.

    Hello

    From the point of view Os you use crontab - to run a script
    Refer to:
    http://dbamac.WordPress.com/2008/08/01/running-sqlplus-and-PLSQL-commands-from-a-shell-script/
    sqlplus and Unix crontab - example

    With the help of planners you can do
    Please visit: http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sched.htm
    http://www.Oracle-base.com/articles/10G/Scheduler10g.php

    -Pavan Kumar N

  • Thread safe operations on the table in the pl/sql procedure?

    I develop java application that will run in N locations simultaneously, each application will be of the sons of Mr. each thread takes a unique ID with the NOT_TAKEN State of the queue table and changes its status to TAKEN.
    Problem:
    How to prevent situation like this thread:
    1 get a first select ID with NOT_TAKEN status
    2. at the same time thread B select first (so it will be the same ID chosen thread A) ID have the status of NOT_TAKEN.
    3 put on a status of changes of identity and
    4 thread B status of the TAKEN ID changes
    After this thread A and B using the same ID.

    What I did:
    I've written pl/sql procedure that queue table in exclusive mode lock, selects the first ID, changes its status to CATCH and unlocks the table. Because it is lock in exclusive mode for a single thread can run this procedure at the same time.

    Question:
    Optimal how must it be resolved, because mine solution prevents to perform all the other updates on the queue table, while it is locked, as the change in status of OPERATION_DONE TAKEN so there performance problem.

    As Centinul said, you need to lock just one line.
    I would just add NOWAIT to the select statement to let the Java thread go and try again, rather than wait for other threads.
    Example: (not tested)

    
    --
    -- Assuming structure of your QueueTable: ( IDCol is PK , StatusCol is VARCHAR2, ... )
    --
    --
    -- or make it part of the package....
    CREATE OF REPLACE
    FUNCTION updateQueue( nQID QueueTable.IDCol%TYPE) RETURN VARCHAR2 AS
       eLocked EXCEPTION;
       PRAGMA EXCEPTION_INIT(eLocked,-54);
       CURSOR curQueueTable IS SELECT 1 CNTR FROM QueueTable WHERE IDCol=nQID AND StatusCol='NOT_TAKEN' FOR UPDATE OF StatusCol NOWAIT;
       recQueueTable curQueueTable%ROWTYPE;
       cRtn VARCHAR2(1); 
    
    BEGIN 
    
       cRtn := 'Y';
       BEGIN 
    
          OPEN curQueueTable;
          FETCH curBuffSummary INTO recQueueTable;
          CLOSE curQueueTable; 
    
          IF recQueueTable.CNTR IS NOT NULL AND recQueueTable.CNTR = 1 THEN
              UPDATE QueueTable SET StatusCol = 'TAKEN' WHERE IDCol=nQID;
          ELSE
              -- Already updated
              cRtn := 'N';
          END IF; 
    
             -- You can control your transaction here as well
             -- COMMIT;
             -- But if realy should be done in the Java thread. 
    
        EXCEPTION
           WHEN eLocked OR STANDARD.TIMEOUT_ON_RESOURCE THEN
           -- Thread could not get exclusice row lock. Ignore error.
             cRtn := 'N';
             NULL; 
    
          WHEN OTHERS THEN
             -- Handle other errors...
             -- NULL; just kidding...
             RAISE;
       END;
       RETURN cRtn; 
    
    END; 
    

    Published by: thomaso September 18, 2009 10:30

  • Accept user entries in the pl/sql procedure

    Someone would want to explain to me how can I accept user entries in the following stored procedure
    CREATE OR REPLACE PROCEDURE calsal
    IS
       CURSOR maxsal
       IS
          SELECT *
            FROM emp;
    
       max_sal   emp.sal%TYPE;
    BEGIN
       SELECT MAX (sal)
         INTO max_sal
         FROM emp;
    
       FOR i IN maxsal
       LOOP
          IF i.sal = max_sal
          THEN
             DBMS_OUTPUT.put_line (   ' Maximum salary plus bonus of '
                                   || i.empno
                                   || ' is '
                                   || (i.sal + i.sal * 0.5)
                                  );
          END IF;
       END LOOP;
    END;
    The above program works very well, but if I want to keep a condition WHERE No. 12 online which is WHERE deptno: = & deptno... My logic does not work with just like that. So, can anyone tell me what can I do to accept a number of the user Department.

    Thanks in advance!

    And what happens if there are several employees who earn max or min. I'll assume that all get award-winning correspondent. I will also assume that if all employees of the Department get the same salary (so they are min and max), they will get. 5% bonus:

    CREATE OR REPLACE
      PROCEDURE calsal(p_deptno number)
        IS
            CURSOR maxsal
              IS
                SELECT  empno,
                        CASE
                          WHEN cnt = 1 THEN SAL * 1.005
                          WHEN rank_max = 1 THEN SAL * 1.005
                          WHEN rank_min = 1 THEN SAL * 1.1
                        END sal_and_bonus
                  FROM  (
                         SELECT  empno,
                                 COUNT(DISTINCT SAL) OVER() cnt,
                                 RANK() OVER(ORDER BY SAL DESC) rank_max,
                                 RANK() OVER(ORDER BY SAL) rank_min,
                                 sal
                           FROM  emp
                           WHERE deptno = p_deptno
                        )
                 WHERE rank_max = 1
                    OR rank_min = 1;
        BEGIN
            FOR v_rec IN maxsal LOOP
              DBMS_OUTPUT.put_line (   ' Salary plus bonus of '
                                   || v_rec.empno
                                   || ' is '
                                   || v_rec.sal_and_bonus
                                  );
            END LOOP;
    END;
    /
    

    SY.

    Published by: Solomon Yakobson August 1, 2011 13:50

  • helps the pl sql procedure

    Hi guys I have 4 tables, I have a table bills, lineitem and a stock table, I need to write a procedure to add an item to an invoice created previously, I am having a lot of problems to do this together, any help will be appreciated.
    assuming that my invoice table looks like this, inv_id (pk)
    cust_id
    in_amount
    and lineitem,
    item_id (PK)
    item_desc
    inv_id (fk)
    stock_id (FK),

    Table of actions
    stock_id (pk)
    st_name
    st_qoh
    st_pmin

    How can I go about it, I can also add atrigger fire when the stock is low. any help will be appreciated to greattly

    Trigger won't work for records which will be inserted after a trigger is created.
    It will not work for files that are already in the table.

  • How to use the pl/sql procedure

    Hi all,

    How to use pl/sql packages and especially in what situations we are pl/sql, which is the cause of the procedure. Please explain with precision using small example.

    Thanks and greetings

    RAM

    I could tell this at a very high level.

    PL/SQL's procedural extension to SQL. SQL (structured query language) has no procedural capacity. They are executed as a stand-alone statement. When you want to generate a process flow with several SQL statement that you need to have a procedural language that could accommodate your SQL. PL/SQL is something similar to Java and Dot Net in this aspect. Said that PL/SQL is Oracle DB. This has some advantages. The most important thing is that when you have your SQL in PL/SQL oracle maintains its reliance on the object. Any database oracle related so you want to build, then you can consider to PL/SQL as the best way to use process flows.

    PL/SQL provides various methods such as the PROCEDURE, FUNCTION and the PACKAGE. The only thing that race stands is in its ability to modularize your code. So, using the package you can create process workflows that is modular and easy to understand.

  • Caveats in the PL/SQL procedure

    Could Hi you help me with this procedure?
    CREATE OR REPLACE
    PROCEDURE last_analyzed_idx(
        own1 IN VARCHAR,
        part IN VARCHAR)
    AS
      j NUMBER;
      f UTL_FILE.FILE_TYPE;
      str VARCHAR(120);
      CURSOR analyzed_cur
      IS
        SELECT t.table_name table_name,
          i.INDEX_NAME INDEX_NAME,
          i.INDEX_TYPE INDEX_TYPE,
          i.num_rows idx_rows,
          t.num_rows tab_rows,
          t.last_analyzed tab_last,
          i.last_analyzed idx_last,
          i.LEAF_BLOCKS LEAF_BLOCKS,
          i.DISTINCT_KEYS DISTINCT_KEYS,
          SUM(s.bytes)/1024/1024 S_MB,
          SUM(s.blocks) S_BLK
        FROM dba_tables t,
          dba_indexes i,
          dba_segments s
        WHERE t.table_name    = i.table_name
        AND t.owner           = i.TABLE_OWNER
        AND t.owner           = own1
        AND t.PARTITIONED     ='NO'
        AND s.segment_name    = i.index_name
        AND s.partition_name IS NULL
        GROUP BY t.table_name,
          i.INDEX_NAME,
          i.INDEX_TYPE,
          i.num_rows,
          t.num_rows,
          t.last_analyzed,
          i.last_analyzed,
          i.LEAF_BLOCKS,
          i.DISTINCT_KEYS;
      CURSOR analyzed_cur1
      IS
        SELECT t.table_name table_name,
          i.INDEX_NAME index_name,
          i.partition_name part_name,
          i.num_rows index_rows,
          t.num_rows table_rows,
          t.last_analyzed tab_last,
          i.last_analyzed idx_last,
          i.LEAF_BLOCKS leaf_blocks,
          i.DISTINCT_KEYS distinct_keys,
          SUM(s.bytes)/1024/1024 S_MB ,
          SUM(s.blocks) S_BLK
        FROM dba_tab_partitions t,
          dba_ind_partitions i,
          dba_segments spartition_name
        WHERE t.table_name IN
          (SELECT table_name FROM dba_indexes WHERE index_name = i.index_name
          )
      AND t.PARTITION_POSITION = i.PARTITION_POSITION
      AND t.table_owner        = i.index_OWNER
      AND t.table_owner        = own1
      AND s.segment_name       = i.index_name
      AND s.partition_name     = i.partition_name
      GROUP BY t.table_name,
        i.INDEX_NAME,
        i.partition_name,
        i.num_rows,
        t.num_rows,
        t.last_analyzed,
        i.last_analyzed,
        i.LEAF_BLOCKS,
        i.DISTINCT_KEYS;
    BEGIN
      IF part='YES' THEN
        f   := UTL_FILE.FOPEN('DIR','last_analyzed_indexes_'||own1||'_'||part,'W',1000);
        FOR j IN analyzed_cur1
        LOOP
           str:=j.table_name||','||j.INDEX_NAME||','||j.part_name||','||j.index_rows||','||j.table_rows||','|| j.tab_last||','||j.idx_last||','||j.LEAF_BLOCKS||','||j.DISTINCT_KEYS||','|| j.S_MB||','|| j.S_BLK;
          UTL_FILE.PUT_LINE(f,str);
        END LOOP;
        UTL_FILE.FCLOSE(f);
      ELSE
        f := UTL_FILE.FOPEN('DIR','last_analyzed_indexes_'||own1,'W',1000);
        FOR j IN analyzed_cur
        LOOP
          str:=j.table_name||','||j.INDEX_NAME||','||j.index_type||','||j.idx_rows||','||j.tab_rows||','|| j.tab_last||','||j.idx_last||','||j.LEAF_BLOCKS||','||j.DISTINCT_KEYS||','|| j.S_MB||','|| j.S_BLK;
          UTL_FILE.PUT_LINE(f,str);
        END LOOP;
        UTL_FILE.FCLOSE(f);
      END IF;
    END last_analyzed_idx;
    Errors:
    NAME                                     TYPE                    LINE   POSITION                            TEXT
    LAST_ANALYZED_IDX     PROCEDURE          62     7     PL/SQL: ORA-00904: "S"."PARTITION_NAME": invalid identifier     ERROR     0
    LAST_ANALYZED_IDX     PROCEDURE          41     5     PL/SQL: SQL Statement ignored     ERROR     0
    LAST_ANALYZED_IDX     PROCEDURE          78     12     PLS-00364: loop index variable 'J' use is invalid     ERROR     364
    LAST_ANALYZED_IDX     PROCEDURE          78     7     PL/SQL: Statement ignored     ERROR     0
    Thank you

    FROM dba_tab_partitions t,.
    dba_ind_partitions I,.
    dba_segments spartition_name

    "BOLD" is the source of the problem.

Maybe you are looking for

  • size of the thumbnail iMovie 10.11

    I use the El Capitan operating system and the version of iMovie 10.11 I found more or less functions equivalent to those that are present in previous versions. But, in the area of work-Assembly (lower part of the screen), the thumbnails are smaller t

  • Division by zero weird problem on HP 8200 Elite SFF

    Greetings, I posted my message here, it appears now that my problem is hardware specific.  My machine has the following specifications:HP Compaq 8200 Elite SFFIntel Core i5-2500 Duo @3.3 GHz processor8 GB memory Windows 7 x 64 (I can provide more det

  • won'tplay ultraviolet movies?

    Why can't I play movies from my ultraviolet account?  Right now, I can't play movies using the primary application.  And then only paramount movies.   On my ANDROID phone, I can run all my movies using the flixster app, but the app flixter on the sur

  • Card Mac for adobe suite cc

    Hello, I have a late book 2013 mac pro and I was wondering if these are the specs right to use the suite complete adobe (mainly first pro, after effects and photoshop) or if I should switch my mac to a newer model. Here are my specs: 2.8 GHz i7 proce

  • Latest XAMPP phpMyAdmin problem

    I upgraded to XAMPP version 5.6.14 yesterday and using phpMyAdmin, I get an error going to user accounts.  The analysis shows this sql query saying there are 5 hooks to close unexpectedly.  This is the query:(SELECT DISTINCT 'User', 'Host' IN 'mysql'