How to use sets in PL/SQL

Hi all,
I want to know how to implement algebraic sets in PL/SQl.
I mean for example if there is a table R(A,B) where A is aprimary key having the data :-
{(1,2),(2,1),(2,3),(3,1)}
i want to have a data type that represents sets of data corresponding to attribute B.
i.e the data type should have the value {1,2,3}
Thanks.

Not sure that I understand correctly.. and how you want to fit PL/SQL into this.
Sets are best handles as Oracle tables. The best language to deal with sets are SQL. So to get the results you want should be a simple:
SELECT DISTINCT b FROM table_r ORDER BY 1
The results of this can be a cursor that needs to be stepped (fetch) through.
The results can be bulk collected into a dynamic array, e.g.
create or replace type TArray is table of number;
And then in PL/SQL:declare
  array TArray;
begin
  SELECT DISTINCT b BULK COLLECT INTO array FROM table_r ORDER BY 1;
end;The array object will now contain TArray(1,2,3).

Similar Messages

  • How to use SET & GET Parameters in Module Pool

    Hi Friends,
    Can anyone please tell how to use SET / GET parameters and PARAMETER ID for a text box (Input / Output field ) in module pool? What is the purpose and where do we need to do coding for it?
    Note : I will definitely give the marks for good responses.
    Thanks in advance,
    Pradeep

    Hi Pradeep,
    You can save values in the SAP memory using a parameter ID. These
    are user and terminal-session specific, but available to all internal and
    external sessions.
    SET Parameter copies the corresponding field contents into the SAP
    System memory in the PAI processing block.
    GET Parameter copies the corresponding field contents from the SAP
    memory at the end of the PBO processing block, after data has been
    transferred from the program, if the screen field still has its initial value
    You can link an input/output field to an area of the SAP memory in the
    ABAP Dictionary.
    When you use an input/output field that is defined in the ABAP
    Dictionary, its parameter ID is displayed in the Dictionary attribute
    Parameter ID in the Screen Painter.
    Usage
    SET PARAMETER ID: ’CAR’ FIELD space,
    ’CON’ FIELD space,
    ’DAY’ FIELD space.
    Here is the link that explains the usage of GET/SET in detail
    <a href="http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db9e0435c111d1829f0000e829fbfe/content.htm">http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db9e0435c111d1829f0000e829fbfe/content.htm</a>
    Regards,
    Sharadha

  • Plase can anybody tell me how to use SETS (GS01/02/03) in ABAP program

    Plase can anybody tell me how to use SETS (GS01/02/03) in ABAP program

    http://wiki.sdn.sap.com/wiki/display/Snippets/Reading+Sets+-+GS01+-+GS02+-+GS03

  • How to use OEM to moniter sql server 2000

    Hi,
    I need to learn How to use OEM to moniter sql server 2000.
    Can anyone help me and give me some website or documents
    to read?
    So I can learn to do this job.
    Thanks.

    See Note 115302.1 in Metalink.oracle.com
    in how to use OEM Diagnostic pack addon for SQL Server
    Or search for
    oem "user events"
    to build your own monitor script.

  • How to use "Set Enterprise Call Info" step in the script ?

    Hi all
    Can anyone please suggest how to use "Set Enterprise Call Info" step in the script.
    Does anyone has any example script with the same (a complete example script) ?

    Hi
    go to this guide
    http://www.cisco.com/c/dam/en/us/td/docs/voice_ip_comm/cust_contact/contact_center/crs/express_7_0/user/guide/uccx70edgs.pdf
    and see the chapter
    "Designing Scripts for use with the Cisco Application Gateway"

  • How to use INSERT in EXEC SQL ...... ENDEXEC ?

    Hi,
    The following code;
    DATA: BEGIN OF str_insert,
            a(3) TYPE c,
            b(3) TYPE c,
          END OF str_insert.
    EXEC SQL.
      SET CONNECTION DEFAULT
    ENDEXEC.
    str_insert-a = 'a'.
    str_insert-b = 'b'.
    EXEC SQL.
    INSERT INTO ZSAP  VALUES :str_insert
    ENDEXEC.
    The Structure of the ZSAP table (There is no data in ZSAP);
    A CHAR 3 (Primary Key)
    B CHAR 3
    I cannot instert a record to this table it throughs the following error;
    Runtime Errors         DBIF_DSQL2_SQL_ERROR  
    Exceptn                CX_SY_NATIVE_SQL_ERROR
    How could use a structure to insert values into ZSAP?
    Thanks,
    Kishan

    Hello..
      loop at T_PC.
        loop at T_PCD .
          at new NUMREFERENCIA.
            exec sql.
             INSERT INTO tblPolizaContableR3
                (LibroMayor, PeriodoContable, Prefijo, NumReferencia,
                Fecha, FuenteDiario, ComentarioPoliza, Moneda,
                TipoCambio, RefExternaID1, RefExternaID2, RefExterna1,
                RefExterna2, DescRefExterna)
             VALUES (:T_PC-LIBROMAYOR, :T_PC-PERIODOCONTABLE,
              :T_PC-PREFIJO, :T_PC-NUMREFERENCIA, :T_PC-FECHA,
              :T_PC-FUENTEDIARIO, :T_PC-COMENTARIOPLIZA, :T_PC-MONEDA,
              :T_PC-TIPOCAMBIO, :T_PC-REFEXTARNAID1, :T_PC-REFEXTERNAID2,
              :T_PC-REFEXTERNA1, :T_PC-REFEXTERNA2, :T_PC-DESCREFEXTERNA)
            endexec.
          endat.
            exec sql.
             INSERT INTO tblPolizaContableDetR3
                (LibroMayor, PeriodoContable, Prefijo, NumReferencia,
                Partida, Cuenta, CuentaIMSA, CCostoIMSA,
                Cargo, Abono, ComentarioPartida)
             VALUES (:T_PCD-LIBROMAYOR, :T_PCD-PERIODOCONTABLE,
              :T_PCD-PREFIJO, :T_PCD-NUMREFERENCIA, :T_PCD-PARTIDA,
              :T_PCD-CUENTA, :T_PCD-CUENTAIMSA, :T_PCD-CCOSTOIMSA,
              :T_PCD-CARGO, :T_PCD-ABONO, :T_PCD-COMENPARTIDA)
            endexec.   
        endloop.
    Hope this help you.
    Regards, Gustavo Estrada

  • How to use parameters in oracle SQL script????

    Right now I am writing a SQL script to create a schema and build the objects of this schema....
    I use a .net winform program to run sqlplus to parse this sql script ...
    The problem is that the schema name and the tablespace's location and the sys password must be input by the user, so my SQL script should use these runtime input parameters instead of const parameters....
    So, how to use parameter in SQL script ...........
    Are there some example scripts in oracle home directory for me to refer to????

    Hi,
    UNISTD wrote:
    thanks .....
    what's the difference between variable , define, accept in sqlplus ???VARIABLE declares (but does not assign a value to) a bind variable. Unlike substitution variables, bind variables are passed to the back end to be compiled, and they can only be values in certain data types. You can not use a bind vaiable in place of an identifier, so to do something like
    CREATE USER  &1 ...a bind variable won't work.
    "DEFINE x = y" sets the substitution variable &x to have the value y. There is no user interaction (unless x or y happen to contain undefined substtiution variables).
    "DEFINE x" shiows the value of the substitution variable &x, or, if it is undefined, raises a SQL*Plus error. I use this feature below.
    ACCEPT sets a substitution variable with user interaction.
    And if the user miss some parameters in “sqlplus /nolog ssss.sql par1 par2 par5 par6”, how to use default value of the miss parameters??Don't you need a @ befiore the script name, e.g.
    sqlplus /nolog @ssss.sql par1 par2 par5 par6Sorry, I don't know of any good way to use default values.
    The foloowing works, but, as you can see, it's ugly.
    "DEFINE 1" display a message like
    DEFINE 1            = "par1" (CHAR)if &1 is defined; otherwise,it will display a SQL*Plus error message like
    SP2-035: symbol 1 is UNDEFINEDNotice that the former contains an '=' sign, but the latter does not.
    The best way I know to use default values is to run the DEFINE command, save the output to a filee, read the file, and see if it's an error message or not.
    So you can use a script like this:
    --     This is  DEFINE_DEFAULT.SQL
    SPOOL     got_define_txt.sql
    DEFINE     &dd_old
    SPOOL     OFF
    COLUMN     dd_new_col     NEW_VALUE     &dd_new
    WITH     got_define_txt     AS
         SELECT  q'[
              @got_define_txt
    ]'               AS define_txt
         FROM    dual
    SELECT     CASE
             WHEN  define_txt LIKE '%=%'
             THEN  REGEXP_REPLACE ( define_txt
                               , '.+"
    ([^"]*)
                         , '\1'
             ELSE  '&dd_default'
         END        AS dd_new_col
    FROM     got_define_txt
    {code}
    and start your real script, ssss.sql, something like this:
    {code}
    DEFINE          dd_new     = sv1
    DEFINE          dd_old     = 1
    DEFINE          dd_default     = FOO
    @DEFINE_DEFAULT
    DEFINE          dd_new     = sv2
    DEFINE          dd_old     = 2
    DEFINE          dd_default     = "Testing spaces in value"
    @DEFINE_DEFAULT
    {code}
    when this finishes running, the substitution variable &sv1 will either have the value you passed in &1 or, if you didn't pass anything, the default value you specified, that is FOO.
    Likewise, &sw2 will have the value you passed, or, if you didn't pass anything, the 23-character string 'Testing spaces in value'.
    Here's how it works:
    Define_default.sql puts the output of the "DEFINE x" command into a column, define_txt, in a query.  That query displays either the existing value of the substitution variable indicated by &dd_old or, if it is undefined, the default value you want to use, which is stored in the substitution variable &dd_default.  The substitution variable named in &dd_new is always set to something, but that something may be its existing value.
    Notice that the paramerters to define_default.sql must be passed as global varibales.
    Why didn't I just use arguments, so that we could simply say:
    {code}
    @DEFINE_DEFAULT  sv1  1  FOO
    {code}
    ?  Because that would set the substitution variables &1, &2 and &3, which are miost likely the very ones in which you're interested.
    I repeat: there must be a better way, but I'm sorry, I don't know what it is.
    I usually don't do the method above.  Instead, I always pass the required number of parameters, but I pass dummy or plce-holder values.
    For example, if I wanted to call ssss.sql, but use defulat vlaues for &1 and &3, then I would say something like:
    {code}
    @ssss  ?  par2  ?
    {code}
    and, inside ssss.sql, test to see if the values are the place holder '?', and, if so, replace them with some real default value.  The use has  to remember what the special place holder-value is, but does not need to know anything more, and only ssss.sql itself needs to change if the default values change.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to use variables in an sql select statement.

    Hi, I have seen examples using the update, but nothing using a select statement.
    I have four variables I am getting from drop down menus in my JSP I set the user selected items to strings.
    How would I create the select statement like this:
    .String XName = request.getParameter("UserInputX");
    rsInResult = stmtInResult.executeQuery("SELECT ColumxX FROM TableZ WHERE ColumnX = XName")Obviously it tries to read "XName" as a column and of course can't find it, how would I set it up to have it see the Value of XName and not the literal XName.

    read this:
    rsInResult = stmtInResult.executeQuery("SELECT ColumxX FROM TableZ WHERE ColumnX = '"+XName+"')
    {code}
    better way is PreparedStatement:
    {code}
         // example code to change password to an user in the USERS table
         String newPWD = "my password";
         String user = "luxjava";
         PreparedStatement prepStat;
         String updatePWD = "UPDATE LOGISTIC.USERS "+
                                  "SET logistic.users.password = ? "+
                                  "WHERE logistic.users.username = ?";
         prepStat = ql.conDb.prepareStatement(updatePWD);
         prepStat.setString(1, newPwd);
         prepStat.setString(2, user);
         int zeroNotFound = prepStat.executeUpdate();
         if (zeroNotFound==0)
              ql.conDb.rollback();
              prepStat.close();
         else
              ql.conDb.commit();
              prepStat.close();
    {code}
    ... use the SQLException to capture errors                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How do I set up Azure Sql Server to have multiple instances?

    Hi all;
    We are setting up a new SAAS application on Azure and while we have used Azure before, not at this level of multiple apps, etc.
    We plan to have both a web app and a cloud app in both a US and EU data center. They need to hit a common database because requests will go to the closest data center via traffic manager and a lot of the data works off of the customer table. And a customer
    (company) can have users in both the U.S. and E.U.
    Is there a way to set up Azure Sql Server so it has instances in both data centers, and Azure keeps them synchronized? If I understand sharding right, that is not what we need as someone hitting either data center could be requesting any of the data in the
    DB.
    thanks - dave
    What we did for the last 6 months -
    Made the world's coolest reporting & docgen system even more amazing

    Hi,
    As far as I am aware, when you set the webapp/cloudapp to connect to a database you will have to specify the connection string in the app. The app will hit the database which is mentioned in the  connection string you have specified. So it is not automatic
    or Traffic manager. You have full control over it as you can tell your app to connect whichever database you want.The database could be located in any region, however the you have to keep latency in mind as the app in US Datacenter could be calling the Database
    in EU, if that is  they way it is setup.
    You can have separate databases in each region and use Azure Data Sync
    to have the database synchronized, however please keep in mind that Azure Data Sync is in Preview.
    Regards,
    Mekh.

  • How to use Java with PL/SQL commands to send an email with attachment

    Apologizes in advance if this is the wrong place to ask the question.
    I need to use Java with PL/SQL commands to send an email with attachment. My java application runs from the command line and does some magic to gather info from an Oracle 11g db. If the DB has sendmail configured, I'd like to send the results of the data gathering as an attachment to the email addresses. I'm not sure how to do this. I've been reading up on on PL/SQL can send email with UTL_SMTP - with attachments. I'm just not sure how to translate that into being triggered by my Java application. Any suggestions or pointers on what I should read would be appreciated.
    Background - I've been programming in Java for 10+ years, but this is my first time using databases. I also have been on these forums for a long time, but lost my profile when it was switched to Oracle.
    Thanks for all help.

    user13726880 wrote:
    The original requirements were put together and given to me, an Oracle newbie. They expected the Java app to use something intrinsic to Oracle and Unix sendmail. To solve my problem, I use a JDBC connection to run some SQL commands. I take that data, format it and send the results by email to the user. By default the requirement is to send it as an HTML attachment using Unix 'sendmail'. So I do that using Runtime exec. I have also added JavaMail functionality as an alternative to sendmail. It works great and as expected.Sounds like a reasonable solution.
    Note however that PL/SQL itself can send email. And PL/SQL can call unix sendmail too.
    However myself I would have done it in java with JavaMail.

  • How to use Image field in SQL-7 for curvs

    I sampling data from a NI-card. There will be a lot of data so I thought I should use Image-field in SQL-7 to save the hole curve. How do you do that?

    I would suggest looking into the Database Connectivity Toolset. It has complete SQL functionality and uses ADO to connect to many types of databases. I have it and it comes with example programs which demonstrate how to write to and read from databases using SQL.
    J.R. Allen

  • [DW 8.02 + PHP] how to use variables in advanced SQL queries

    Hi all,
    I can't find a way to use variables in an SQL query after
    updating
    dreamweaver 8.02.
    I always get error messages that says: 'missing variable
    type:myvariablename', undefined#myvariablename... and so on.
    What is the correct way to use variables?
    I usually set a variable in a PHP statement (example: <?
    $today=date('Y-m-d'); ?>)
    and then I compare this variable in the SQL query.
    What is the correct syntax for variable in DW 8.02 in
    advanced SQL
    queries?
    TIA
    tony

    sweetman wrote:
    > I'm editing a website created with DW 8.01 and MX
    Kollection.
    >
    > I updated DW to 8.02 and now I can't edit an existing
    SQL query.
    > I always get an error message 'Missing variable type'
    and I can't go
    > on.
    InterAKT released a new version of Kollection to cope with
    the 8.0.2
    changes. AFAIK, you should be able to download the updated
    version from
    your InterAKT account area.
    David Powers, Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • How to use hints in PL/SQL

    Hi,
    If I want to use hints in PL/SQL procedure, it is valid to write it this way:
    begin
    update /*+  INDEX(opp DIM_OPP_REFDB_IDX) */
            scott.rec_dim_opportunity opp
            set opp.mp_opportunity_re ....
    endI doubt when I tried it that the optimizer didn't actually use the index.
    Thanks in advance.
    Oracle 10g R1
    Windows 2003 32-bit

    the table is of 90MB and when the UPDATE statement is used in SQL, the explain plan output shows that the index is used.
    When I execute it from a procedure, the Current Statement show in TOAD doesn't show that the index is used and the update takes forever. Explain plan of the statement (as show in TOAD) shows that full table scan is being used.

  • How to use SET CURSOR in REUSE_ALV_HIERSEQ_LIST_DISPLAY

    Hi,
    I have added new fields in Standard VL10C ALV report , I have added one editable field in this standard ALV output.
    I want to set the cursor by default on the editable column on the specific row depending on some condition also if possible
    i want to highlight only that particular row.
    Please reply if anybody knows how to do this.
    Thanks,
    Pawan

    Hİ Pawan
    You can see the list of events supported by reusable alv with function REUSE_ALV_EVENTS_GET
    when I run this function in se37 I see the some events maybe helpful for your question
    PF_STATUS_SET : this has to be called from PBO of your screen, so you can try to use SET CURSOR
    command to put cursor on the selected field
    BEFORE_LINE_OUTPUT : It's called before the output of every single line so you should use command
    "FORMAT COLOR COL_POSITIVE INTENSIFIED ON.  "for highlighting the line
    AFTER_LINE_OUTPUT : than u can use "FORMAT COLOR COL_POSITIVE INTENSIFIED OFF." command
    I hope it'll be helpful.

  • How to use  SET and GET parameter commands ?

    Explain these two giving an example?As which is used for what?

    Hi Albert,
             SAP allows you to make use of SPA/GPA technique to fill the input fields of a called transaction with data from the calling program.SPA/GPA parameters are values that the system stores in the global, user-specific SAP memory. SAP memory allows you to pass values between programs. A user can access the values stored in the SAP memory during one terminal session for all parallel sessions. Each SPA/GPA parameter is identified by a 20-character code. You can maintain them in the Repository Browser in the ABAP Workbench. The values in SPA/GPA parameters are user-specific.
    ABAP programs can access the parameters using the SET PARAMETER and GET PARAMETER statements.
    To fill one, use:
    SET PARAMETER ID <pid> FIELD <f>.
    This statement saves the contents of field <f> under the ID <pid> in the SAP memory. The code <pid> can be up to 20 characters long. If there was already a value stored under <pid>, this statement overwrites it. If the ID <pid> does not exist, double-click <pid> in the ABAP Editor to create a new parameter object.
    To read an SPA/GPA parameter, use:
    GET PARAMETER ID <pid> FIELD <f>.
    This statement fills the value stored under the ID <pid> into the variable <f>. If the system does not find a value for <pid> in the SAP memory, it sets SY-SUBRC to 4, otherwise to 0.
    To fill the initial screen of a program using SPA/GPA parameters, you normally only need the SET PARAMETER statement.
    The relevant fields must each be linked to an SPA/GPA parameter.
    On a selection screen, you link fields to parameters using the MEMORY ID addition in the PARAMETERS or SELECT-OPTIONS statement. If you specify an SPA/GPA parameter ID when you declare a parameter or selection option, the corresponding input field is linked to that input field.
    On a screen, you link fields to parameters in the Screen Painter. When you define the field attributes of an input field, you can enter the name of an SPA/GPA parameter in the Parameter ID field in the screen attributes. The SET parameter and GET parameter checkboxes allow you to specify whether the field should be filled from the corresponding SPA/GPA parameter in the PBO event, and whether the SPA/GPA parameter should be filled with the value from the screen in the PAI event.
    When an input field is linked to an SPA/GPA parameter, it is initialized with the current value of the parameter each time the screen is displayed. This is the reason why fields on screens in the R/3 System often already contain values when you call them more than once.
    When you call programs, you can use SPA/GPA parameters with no additional programming overhead if, for example, you need to fill obligatory fields on the initial screen of the called program. The system simply transfers the values from the parameters into the input fields of the called program.
    However, you can control the contents of the parameters from your program by using the SET PARAMETER statement before the actual program call. This technique is particularly useful if you want to skip the initial screen of the called program and that screen contains obligatory fields.
    If you want to set SPA/GPA parameters before a program call, you need to know which parameters are linked to which fields on the initial screen. A simple way of doing this is to start the program that you want to call, place the cursor on the input fields, and choose F1 followed by Technical info. The Parameter ID field contains the name of the corresponding SPA/GPA parameter. Alternatively, you can look at the screen definition in the Screen Painter.
    The SPA/GPA parameter for the input field Company has the ID CAR. Use this method to find the IDs CON, DAY, and BOK for the other input fields.
    The following executable program is connected to the logical database F1S and calls an update transaction:
    REPORT BOOKINGS NO STANDARD PAGE HEADING.
    TABLES SBOOK.
    START-OF-SELECTION.
      WRITE: 'Select a booking',
      SKIP.
    GET SBOOK.
      WRITE: SBOOK-CARRID, SBOOK-CONNID,
             SBOOK-FLDATE, SBOOK-BOOKID.
      HIDE:  SBOOK-CARRID, SBOOK-CONNID,
             SBOOK-FLDATE, SBOOK-BOOKID.
    AT LINE-SELECTION.
      SET PARAMETER ID: 'CAR' FIELD SBOOK-CARRID,
                        'CON' FIELD SBOOK-CONNID,
                        'DAY' FIELD SBOOK-FLDATE,
                        'BOK' FIELD SBOOK-BOOKID.
      CALL TRANSACTION 'BOOK'.
    The basic list of the program shows fields from the database table SBOOK according to the user entries on the selection screen. These data are also stored in the HIDE areas of each line.
    Cheers
    Nishanth

Maybe you are looking for

  • W540 piece of junk DO NOT BUY!!!

    Hi, we've ordered two W540's for one of our larger clients. One unit was DOA. still waiting to hear back from Synnex if it's approved to be replace or not BUT now I'm not sure if I want another one of these units. The 2nd unit we have had seemed to w

  • Function Modules for creation of characteristics and Measurement Points

    Hello everybody I'm new in ABAP (trainee) and especially the use of characteristics. I'd be very happy if somebody could help me :). Can anybody out there with some experience in creating characteristics and measurement points tell me how to create t

  • Print more than one page at a time

    I need help configuring my printer to permanently print 2 pages every time.

  • Problems with many things.

    Hello, sorry for my englisch, there are a few topics that not work with the new aperture i just want to give some feedback. Import with my camera is neerly inposseble, aperture do not find my D700 and i use now Nikon transfer and then i import it in

  • My macbook pro is crashing!!

    My macbook pro is crashing and closing down running applicatione after approx 5 mins of opening them. its bringing up an error report that makes no sence to me and i am very confused, it has done this approx 10 times over 3 days and i have never had