Newbie: PL/SQL, combining values of columns of different recordings?

Hello

I want to extract a certain number of documents and then combine the value of one of their columns in a single record.

Leash so tell the following sql statement returns multiple records:

Select NAME, ADDRESS from userstable where ADDRESS = 'N6 0JG.


What I get in return is a file that looks like this

John Jack Jane Florian William Ann Helena, N6 0JG

Note that the name of each must come from another record and then get concatenated into one record for the output.

Thank you
J

Hello

Since you already have it in a cursor, we will just add another and make the two loops.

First let's make a cursor to address list

cursor c_address is
Select distinct ADDRESS
of userstable;

Now, let's make another slider that will loop through all the names to each address. I guess that your table contains multiple addresses. Note You can pass parameters to the cursor.

cursor c_names (p_addr in varchar2) is
Select NAME, ADDRESS
of userstable when the ADDRESS = p_addr;

Now we can put it all together. You can do everything you need with the result. I just stuck to a release on the subject.

DECLARE
CURSOR c_address
IS
SELECT DISTINCT address
Of userstable;

CURSOR c_names (p_addr IN VARCHAR2)
IS
SELECT NAME, address
Of userstable
WHEN address = p_addr;

v_namelist VARCHAR2 (2000); -Do this as large as you want
BEGIN
FOR x IN c_address
LOOP
FOR y IN c_names (x.address)
LOOP
-make a list of names with spaces
v_namelist: = v_namelist | ' ' || y.NAME;
END LOOP;

-Add address and a comma at the end of the list
v_namelist: = v_namelist | ', ' || x.Address;
Dbms_output.put_line ('v_namelist =' | v_namelist);
END LOOP;
END;

Tags: Database

Similar Questions

  • Can sql RS only 1 column of return can be printed as a separate column value

    Hello
    I wonder if the result set sql returning only one column can be printed as a separate values column?

    IE.with a simple change to select empno, emp; It should be able to print.
    101,102,103

    Instead of
    EmpNo
    ----------
    101
    102
    103

    Thank you
    Jean Claude

    Here is an example with the EMP table in the Scott schema.

    select ltrim(sys_connect_by_path(empno,','),',') empno_list
      from (select e.*, row_number() over(order by empno) rno from emp e)
     where connect_by_isleaf = 1
     start with rno = 1
    connect by rno = prior rno+1
    
  • Requirement of Beeping - how to get subtotals for each combination of 2 columns val

    Hi gurus, Experts and all,.

    Help me please with my reporting requirement, on how to code this in PIF. Thank you.

    Requirement: I need to get the subtotals for each value of the combination of two columns.

    Columns example: team group AMOUNT

    Sample column values: placed Team1 100
    Group b... Team2... 200

    GroupA - Team1 Subtotals = 500 (value of the sample only)
    GroupA - Team2 Subtotals = 400 (value of the sample only)
    Group b - Team1 Subtotals = 600 (value of the sample only)
    Group b - Team2 Subtotals = 200 (value of the sample only)

    GrandTotal = 1700

    Thank you.

    Jean Paul
    BEEP newbie

    Published by: user10955574 on October 28, 2010 05:40
    
     -  - 
    
    

    output for data

    GROUPA - TEAM1 - 200
    GROUPB - TEAM1 - 300
    GROUPC - TEAM2 - 400
    GROUPD - TEAM2 - 500
    GROUPA - TEAM3 - 600
    GROUPB - TEAM3 - 700
    GROUPC - TEAM4 - 800
    GROUPD - TEAM4 - 900
    GROUPA - TEAM5 - 1000
    
  • Validation for combinations of unique columns in a report

    Hello

    I have a form on a Table with report 'C' (columns C1_pk, A1_fk, B1_fk) where I connect the primary keys of the table (columns A1_pk, A2, A3) 'A' and 'B' (columns B1_pk, B2, B3) table.

    I want to create a Validation process to have combinations of single column for the table C.

    Basically, table A represents users, table B represents groups, table C assigns users to the groups. I need a validation to avoid duplication of Group of users associations in table C.

    My form table C has just 2 LOV points (P11_A, P11_B) to call A table and values in table B, I need a validation process after 'create' button click, but I do not know how to write code.

    Any suggestion please?

    Thank you

    K

    Jesse wrote:

    I have a form on a Table with report 'C' (columns C1_pk, A1_fk, B1_fk) where I connect the primary keys of the table (columns A1_pk, A2, A3) 'A' and 'B' (columns B1_pk, B2, B3) table.

    I want to create a Validation process to have combinations of single column for the table C.

    Basically, table A represents users, table B represents groups, table C assigns users to the groups. I need a validation to avoid duplication of Group of users associations in table C.

    My form table C has just 2 LOV points (P11_A, P11_B) to call A table and values in table B, I need a validation process after 'create' button click, but I do not know how to write code.

    Any suggestion please?

    I suggest you:

    • Add a unique constraint on the table C for (A1_FK, B1_FK) to make sure that the table cannot contain duplicates.
    • Instead of validation, it is easier to use to prevent the selection of existing combinations. Create the P11_B element under a shuttle, so that users cannot select a group more than once.
  • If the default value in columns on slot form of table does not work.

    Hello

    I created a tabular form and I want to set some default values to columns that are based on the values of page elements.

    so I put the page element to the value of the column in the attributes in a table by selecting the value & P24_ISSUE_ID. default type as Expression PLSQL & DEFAULT function there but
    in the same way, I tried for the other column by selecting the type default as pl/sql expression and function by default the value & P24_CASE_NAME.

    but it throw an error of this type could not parse the SQL query: ORA-00904: "C254DB": invalid identifier

    I don't understand where I did wrong, I checked for the data types of columns, all right.

    so please help me out of this problem.

    1243 Tulasi wrote:
    for the first column

    I chose
    The DEFAULT TYPE as PL/SQL Expression & FUNCTION

    As the default * & P24_ISSUE_ID.* it is a number data type column

    2nd column

    The default Type as PL/SQL Expression & function

    As the default * & P24_CASE_NAME.* it's column of type Varchar2.

    Element (name of the page element or application) for the default Type and the name of the default item ( P24_ISSUE_ID, P24_CASE_NAME etc.) options appropriate for a default value for a page element.

    * & P24_ISSUE_ID.* is not a "PL/SQL Expression or function.

    but it throws an error, because this guy could not parse the SQL query: ORA-00904: "C254DB": invalid identifier

    What you're doing results in the engine of the APEX, P24_CASE_NAME 'C254DB' value in the default value and then try to assess this string as a piece of PL/SQL. Outside a block in which it is defined as a variable, constant, or a function 'C254DB' is not a valid expression of PL/SQL.

  • Change the default value of column NOT NULL to NULL

    Hi all
    How can I change the default value of column not NULL to NULL?
    Suppose I have run the following commands:
    SQL> alter table hr.test modify temp_num2 default null;
    
    Table altered.
    
    SQL> desc hr.test;
     Name                            Null?    Type
     ----------------------------------------- -------- ----------------------------
     TEMP_NUM                             NUMBER
     TEMP_NUM2                       NOT NULL NUMBER
    Why forced temp_num2 has not changed with the NULL value? I'm under 11.g rel2

    Best regards
    Valerie

    You can NOT change the column constraint NULL to contain NULL values by:

    alter table table_name modify column_name null; 
    

    After this change, the column can contain null values. In Oracle, not null constraints are created automatically when not null is specified for a column. Similarly, they are deleted automatically when the column is changed to allow NULL values.

  • Requirement of Beeping - how to get the number of combination of several columns

    Hi gurus, Experts and all,.

    Help me please how this code to the BEEP.

    I need to get the number of each combination of 6 columns if the combination is repeated.

    Columns example: number team responsible for Group Type reason
    The example columns: placed Team1 M1 M1 T1 won 2
    GroupA Team1 H2 M2 T1 loss 1
    GroupB Team2 H2 M3 T2 won 1
    GroupB Team2 H3 M3 T2 loss 2

    Thank you very much

    Jean Paul
    BEEP newbie

    Published by: user10955574 on October 28, 2010 20:15

    Published by: user10955574 on October 29, 2010 03:06

    I sent you the file. Check your mailbox.

  • The coldfusion.sql.QueryTable value cannot be converted to a number

    Hello

    I have two queries, in two different functions, who both return the SUM of a column based on the values of the arguments

    I need to subtract query from a query of 1 2.

    The arguments for the two motions are passed using the CreateObject function

    < cfset qry1 = createObject ("component", "components.adminobjects"). Func1(#argument1#,#argument2#) >

    < cfset qry2 = createObject ("component", "components.adminobjects"). Func1(#argument1#,#argument2#) >

    Queries executed accordingly and returns the results accordingly.

    The problem occurs when I try to calculate by subtracting the 2nd request form 1.

    So, to get the results I need, that's what I do:

    < cfset results = ' #qry1.sum # '-' #qry1.sum2 # ' >

    < cfoutput > #results # < / cfoutput >

    When I do this, it is said:

    The coldfusion.sql.QueryTable value cannot be converted to a number

    I don't understand, it is because when I exit #qry1.sum # or #qry1.sum2 # I get the numbers right and they are numbers, but when I do some math on them, I get the error.

    Any ideas?

    Thank you.

    Assuming that the qry1 object has a column named "sum1" and "sum2" try:

    Also note that the "sum" is a reserved word, try to change the column "sum" "sum1".

    http://help.Adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec173d0-7F ff.html

  • Combine the two columns of text

    I have two columns of text (say that name is a column and the name is the other)

    I would like to combine the two columns for the text of these two columns are in a column. (First name and last name in the same column)

    Is this possible? If so is there a tutorial somewhere?

    Hi Danielle,

    The & (concatenation operator) is your friend.

    Formula in D2 (fill down)

    "B2 &" "& C2.

    & joins elements into a single string.

    "" inserts a space.

    Kind regards

    Ian.

  • SQL monitor help with column of chronology

    monitor_test.jpg

    In the report attached to sql, in the timeline column means the whole last 3 began simultaneously and hash join is the first exploited who started?

    my understanding is 'index range scan' should start first and give the data to "Single Partition range". Only once this step completed, he should 'TABLE ACCESS Full'. Isn't this correct?

    Thanks for your time!

    Your description is correct - and I think that you just have to allow some defects in the rounded, graphic display of errors and inconsistencies in what is "the order of execution.

    If it is still possible, you can watch dbms_sqltune.report_sql_monitor output text () as numbers COULD clarify the sequence - on the other hand, the granularity of the timer is not very fine.

    You may find that the chronology of hash join begins before the access times two table - which highlights the problem of "means to launch an operation."  The subroutine "do a hash join" must begin before the two tablescans, on the other hand the mechanism 'return rowsource to parent' cannot start until after the second table access began to return the hash join lines.

    Another sign of the available seeds, of course, is that the select statement does not seem to have started until a few seconds after the hash join has started!

    Concerning

    Jonathan Lewis

  • change the color of line based on the value of column 5 Apex in the classic report

    Version of the apex 5.0.0.00.31

    Standard universal theme

    Page theme default template

    Classic report

    Foldable report template

    Hello

    I know this question has been asked several times here, but I'm working on 5 Apex and need to know the correct way to do it in this version.

    I need to change the color of the text of the entire line (no background color) based on the value in one of the columns of the classic report. I have just two conditions, if the value of column = Yes, color should be red, otherwise it must be green.

    I am new to jscript and css, so appreciate if someone can tell me the solution with steps.

    I have already checked this link that changes the value of the column, need to do something similar to the whole line.

    https://tylermuth.WordPress.com/2007/12/01/conditional-column-formatting-in-apex/

    Hi coolmaddy007-Oracle,.

    Here's an example set up on the apex.oracle.com according to the specifications you gave: https://apex.oracle.com/pls/apex/f?p=35467:1

    Version of the apex 5.0.0.00.31

    Standard universal theme

    Page theme default template

    Classic report

    Foldable report template

    Here is how it is done:

    Create a dynamic action with the following specifications:

    Name: Give the appropriate name

    Event: After refresh

    Selection type: region

    Region: select your region classic report

    Condition: No strings attached

    Action: Run the JavaScript Code

    Fire on loading the Page: Yes

    Code:

    $('td[headers="JOB"]').each(function() {
      if ( $(this).text() === 'MANAGER' ) {
        $(this).closest('tr').find('td').css({"color":"red"});
      }
      if ( $(this).text() === 'SALESMAN' ) {
        $(this).closest('tr').find('td').css({"color":"green"});
      }
      if ( $(this).text() === 'CLERK' ) {
        $(this).closest('tr').find('td').css({"color":"blue"});
      }
    });
    

    NOTE: Download the selector appropriate for your knowledge $('td[headers="JOB"]') case using firebug/browser development tools.

    Items concerned: leave blank.

    PS: Changed the example to change the color of text instead of the background color.

    I hope this helps!

    Kind regards

    Kiran

  • Incorrect SQL % RowCount value

    Hello.

    I created dblink of Oracle 11 g (11.2.0.4.3) for Sybase ASE database (15.5) using gateway of Oracle database for Sybase (11.2.0.4.3) on x 64 OEL (6.5).

    When I make changes to a remote table with triggers and use the variable in the WHERE clause, SQL % RowCount value is miscalculated.
    Found the antidote on the side of Sybase - the use of "set nocount on" within a trigger.
    Is there a solution on the side of Oracle (database or gateway)?

    Detailed description is given below:

    Description table and relaxing 1) (Sybase)
    create table test_TR)
    identity of whole ID,
    oper_id integer not null,
    counter integer not null,
    constraint XPKtest_TR primary key clustered (id))
    go
    insert into test_TR (oper_id, meter) values (1,10)
    insert into test_TR (oper_id, meter) values (2.21)
    insert into test_TR (oper_id, meter) values (2.36)
    go

    create trigger tUtest_TR on test_TR for UPDATE as
    Start
    declare @numrows int
    Select @numrows = @@rowcount
    return
    error:
    RAISERROR 31000 "UPDATE."
    ROLLBACK transaction statement
    end
    go

    (2) description gateway (gateway)
    HS_FDS_CONNECT_INFO=xxx.xxx.xxx.xxx.xxx:XXXX/test
    HS_FDS_RECOVERY_ACCOUNT = RECOVERY
    HS_FDS_RECOVERY_PWD = *.
    HS_FDS_TRANSACTION_MODEL = COMMIT_CONFIRM
    HS_FDS_TRANSACTION_LOG = HS_TRANSACTION_LOG
    HS_FDS_RESULTSET_SUPPORT = TRUE
    HS_FDS_PROC_IS_FUNC = FALSE

    (3) description Dblink (Oracle)
    CREATE DATABASE LINK PUBLIC 'SYB_TEST' CONNECT TO ' * ' IDENTIFIED by ' * ' using 'SYB_TEST ';

    (4) test query (Oracle)
    declare per_id digital;
    Start
    Update "test_TR"@SYB_TEST "counter" value = "counter" + 1 where 'oper_id' = 0;
    dbms_output.put_line ('0 rows =' |) SQL % number of lines);
    PER_ID: = 0;
    Update "test_TR"@SYB_TEST "counter" value = "counter" + 1 where 'oper_id' = per_id;
    dbms_output.put_line ('0 rows =' |) SQL % number of lines);
    Rollback;
    end;
    /

    0 rows = 0
    0 line = 1

    Thanks in advance for any information!

    filed Bug 19844303 - SQL % ROWCOUN RETURNS a VALUE INCORRECTE

  • Combine values separated by '&amp;' only if the second field has a value.

    I try to combine the 2 fields and add & symbol between the two, but only if there is in the second text field.  In this way, I wouldn't end up with "names of seller: Joe Smith &" If there was only one seller name.

    Here is my current script is add automatically of course "and" all the time.

    Get the field values as strings

    var s1 = getField("s1").valueAsString;

    var S2 = getField("s2").valueAsString;

    Combine values, separated by &

    Event.Value = s1 + '&' + s2;

    Replace the last line with:

    Event.Value = s1;

    If (s2! = "" ") event.value +="&"+ s2;

  • Dictionary of data values in column view (s)

    The following query is the list of the most fragmented tables.

    My question is that I do not understand why the value of the blocks is multiplied by 8. Is because the value of column of blocks show a kilo byte? so convert us kilo bits?

    My second question is, what is the value of these columns represent in general? In other words, when I look at the data of avg_row_len how can I understand the which type of data it represent?

    For example: avg_row_len, the number in this column represents byte? or kilobye?

    select table_name,round((blocks*8),2) "size (kb)" ,
                      round((num_rows*avg_row_len/1024),2) "actual_data (kb)",
                     (round((blocks*8),2) - round((num_rows*avg_row_len/1024),2)) "wasted_space (kb)"
    from dba_tables
    where (round((blocks*8),2) > round((num_rows*avg_row_len/1024),2))
    order by 4 desc

    Thanks in advance.

    So what you don't understand? Num_Rows * avg_row_len gives "average you" number of bytes occupied by the data in the table. Num_Rows * avg_row_len/1024 is same in KB. And round ((num_rows*avg_row_len/1024), 2) round it to two decimal places. blocks * 8 (as I said, code you posted assume table block size is 8K) is the space allocated to the table in KB. And I have no idea why code is rounded, something that is whole number to start.

    SY.

  • Request to remove row where the value of column contains alphabets

    Hello

    Could someone please help me to get this application working.

    Request to remove row where the value of column contains alphabets.

    DELETE FROM BIN_ITEM WHERE order_nmb LIKE '% [A - Z] % ' | LIKE '% [a - z] %'

    Thank you and best regards,

    Madam.

    SELECT order_nmb FROM BIN_ITEM WHERE regexp_count(order_nmb,'[0-9]') = 0

    ----

    Ramin Hashimzade

Maybe you are looking for