Retrieving numeric values of a column from another table..

Hi there, so i have the following query that returns a label and a value from a database table:
select key_field,value_field from table1 where some_id = 'id1' and key_field is not null;
This will return a result in which the key_field may or may not be numeric, which is fine:
key_field | value_field
2 | street
6 | dog
car | mazda
5 | tea
1 | unknown
I have another table table_num_vals where the value for those numeric fields are stored:
key_field | display_field
2 | address
6 | animal
5 | drink
I want to be able to return the non-numeric fields as they were, all numeric fields translated if it can be found, and if not then leave the original number, desired result:
key_field  | value_field
address | street
animal | dog
car | mazda
drink | tea
1 | unknown
I tried doing the following:
select display_field from table_num_vals where key_field in (
    with numericCol as (
        select key_field from table1 where some_id = 'id1' and key_field is not null;
    ) select case when regexp_like(key_field,'^[[:digit:]]') then key_field else '' end from numericCol
It gives me the labels for the ids that it can find.. (address, animal, drink) but then I can't seem to put it all together with the original query.. could someone please help?
Thanks in advance,

Yes you are right .. Thank you so much
I let it work using
select student_ID, Level from Student where Level ='Graduate'
But when i run different kind of form to Graduate_Student table and try to create a new row , I cant see the Student_ID  !  I see it only if I use Form using SQL but this one doesn't add/delete/update record.
I am new to oracle apex, sorry for that.

Similar Messages

  • Need to compare values in two columns of one table against values in two columns in another table

    Hi, as the title reads, I'm looking for an approach that will allow me to compare values in two columns of one table against values in two columns in another table.
    Say, for instance, here are my tables:
    Table1:
    Server,Login
    ABCDEF,JOHN
    ABCDEF,JANE
    FEDCBA,SEAN
    FEDCBA,SHAWN
    Table2:
    Server,Login
    ABCDEF,JOHN
    ABCDEF,JANE
    FEDCBA,SHAWN
    In comparing the two tables, I'd like my query to report the rows in table1 NOT found in table2. In this case, it'll be the 3rd row of table one:
    Server,Login
    FEDCBA,SEAN
    Thanks.

    create table Table1([Server] varchar(50), Login varchar(50))
    Insert into Table1 values ('ABCDEF','JOHN'),('ABCDEF','JANE'),('FEDCBA','SEAN'),('FEDCBA','SHAWN')
    create table Table2([Server] varchar(50), Login varchar(50))
    Insert into Table2 values ('ABCDEF','JOHN'),('ABCDEF','JANE'), ('FEDCBA','SHAWN')
    select [Server] ,Login from Table1
    Except
    select [Server] ,Login from Table2
    select [Server] ,Login from Table1 t1
    where not exists(Select 1 from Table2 where t1.[Server] = t1.[Server] AND Login=t1.Login)
    drop table Table1,Table2

  • Create a table which has columns from another table in other schema

    Hi All
    I need to create a table which is table driven i.e., the columns of that table need to be inserted from another table in a different schema...Can any one help me with this??

    create table newtab (--column spec here--) as
    Select --columns here-- from otherschema.tablename;max

  • Set Default Value based on Field from another table for a custom object

    I'm trying to set the default value on a custom object field to the value of an account field. I have tried the syntax 50 different ways, and just am getting no where. The account field label displays as DBA, the integration tag is ltDBA_ACCT, and it shows up in reporting fx area as Account.Text_22.
    The custom object field I'm triying to update is also called DBA, which was originally the "NAME" required field. Does the table name, Account, have to be included? Do I need a function in front of the field?
    I have been updating the external ID using the row ID with syntex <ID> (Less than ID greater than) so I know it is possible to set the Default Value, but <DBA>, <ltDBA_ACCT>, "Account"."DBA", and so on just don't not work.
    If anyone knows how to enter this I'd really appreciate the help.

    Ok, so if you want to default a field to the value from another object, you have to use the JoinFieldValue function. I think you understand that, based on your original post, but I want to be sure that you do.
    Next, this will only work as a default if the record is created from the object that you wish to join on because a default works at record creation and the ID needs to be available for it to work properly. It will not work if you choose the related object record after the custom object record is created. You could set the value as a post-default, but that does not seem to meet your requirements.
    The syntax for the Default Value would be as follows: JoinFieldValue(ref_record_type, foreign_key, field_name).
    In your case, ref_record_type is '<Account>', foreign_key is &#91;<AccountId>&#93;, and field_name is '<YourFieldName>'. The best way to determine what the field name is would be to create a new workflow for Account and use the Workflow Rule Condition expression builder to pick your field ("DBA") from the list. The value that is returned by the expression builder should be placed in the field_name variable in the JoinFieldValue function (minus the brackets and in single quotes).
    Give this a shot and let me know how you do.
    Thom

  • Insert into a table with unique columns from another table.

    There are two tables,
    STG_DATA                                                          
    ORDER_NO    DIR_CUST_IND
    1002                     DNA
    1005                     GEN
    1005    
    1008                     NULL
    1001                     NULL
    1001                     NULL
    1006                     NULL
    1000                     ZZZ
    1001                     ZZZ
    FACT_DATA
    ORDER_NO    DIR_CUST_IND
    1005                      NULL
    1006                      NULL
    1008                      NULL
    I need to insert only unique [ORDER_NO] from STG_DATA to FACT_DATA with corresponding [DIR_CUST_IND]. Though STG_DATA has multiple rows with same ORDER_NO, I need to insert only one of that it can be any record.
    Sarvan

    CREATE TABLE #Level(ORDER_NO INT, DIR_CUST_IND CHAR(3))
    INSERT #Level
    SELECT 1002,'DNA' UNION
    SELECT 1005,'GEN' UNION
    SELECT 1005,NULL UNION
    SELECT 1008,NULL UNION
    SELECT 1001,NULL UNION
    SELECT 1001,NULL UNION
    SELECT 1006,NULL UNION
    SELECT 1000,'ZZZ' UNION
    SELECT 1001,'ZZZ'
    SELECT ORDER_NO,DIR_CUST_IND
    FROM( SELECT ROW_NUMBER()OVER(PARTITION BY ORDER_NO ORDER BY ORDER_NO) RowNum,*
    FROM #Level)A
    WHERE RowNum=1
    I hope this would give you enough idea. All you have to do is just write insert statement.
    Next time please post DDL & DML.
    Chaos isn’t a pit. Chaos is a ladder. Many who try to climb it fail and never get to try again. The fall breaks them. And some are given a chance to climb, but they refuse. They cling to the realm, or the gods, or love. Illusions. Only the ladder is real.
    The climb is all there is.

  • Validating Tabular Form Column Against Value From Another Table

    Hi,
    I am brand new to this forum, so please bear with me a little!  I only have a small amount of experience writing PL/SQL, and I've never written Javascript or JQuery before.  I am an Oracle DBA, and I have coding experience in C and PERL, so I do have a solid technical background.  But, I need some advice on the best way to approach a problem.
    I have a database application in Oracle Apex (version 4.2) with a tabular form against a table: let's say Table #1 with cols 1A, 1B, and1C.  I need to ensure that the value entered into col B isn't greater than the value of a column in another table (let's say Table #2 col 2A).  Conceptually, the amount of money available is in Table #2, and the rows of my tabular form are an act of spending money (like orders or invoices), so I need to make sure we don't spend more than we have.  Does that make sense?
    Does anyone have any advice for the best way to do this?  I'm figuring the biggest issue here might be that we have to account for people entering mutliple rows in the tabular form at one time, right?  So, if a person entered 3 orders/invoices, I need a total to make sure they didn't spend more than we have in Table #2.
    I greatly appreciate your help! 
    Best Regards,
    Laurie Baublitz

    Hi!
    You need one process of type ajax callbacks like:
    DECLARE
       l_limit nubmer;
       l_number1 number := apex_application.g_x02;
       l_returnValue VARCHAR2(200);
    BEGIN
       select A2 into l_limit from table2;
       if l_number1 > l_limit then
          l_returnValue := 'LIMIT IS NOT SO BIG';
          if l_returnValue is not null then
             --this will write l_returnValue to the buffer, and the ajax callback will receive this
            htp.p(l_returnValue);
          end if;
      end if;
    END;
    Then you need one javascript on page, code is something like:
    $('input[name=your column in tabular which is change]').live('change', function(){
       //if value of changed field differs from an empty string
       if($(this).val()!=''){
          //put target element in a var to reference it in the ajax success callback
          var num  = $('input[name=your column in tabular with value]');
          $.post('wwv_flow.show',
                 {"p_request"      : "APPLICATION_PROCESS=your ajax callback function",
                  "p_flow_id"      : $v('pFlowId'),
                  "p_flow_step_id" : $v('pFlowStepId'),
                  "p_instance"     : $v('pInstance'),
                  "x01"            : $(this).val(),
                  "x02"            : $(num).val()
                  function(data){
                     if(data !=''){
                     alert(data);
    I can not guarante that code is 100% working, if not you need to do some changes or make an example on apex.oracle.com and provide credentials here.
    Regards,
    drama9346

  • Column names from another table

    Hi All,
    I have a scenario where i need to get names of a column from another table
    for eg,
    Table EMP
    EmpNo EmpName EmpContact EmpPhone
    1 xyz [email protected] 345     
    2 abc [email protected] 897
    3 ttp [email protected] 345
    The column names of this table can be configurable from some other place and its value is stored in another table like
    Table Config (2 Columns)
    Column_Name Value
    EmpName First name
    EmpContact Email
    EmpPhone Mobile
    Now i want to fetch the values from Emp table but with column headers that are changed and have a value in Config table.
    If a column name is not there in config table then the original column name should come.
    As shown below
    EmpNo First name Email Mobile
    1 xyz [email protected] 345
    2 abc     [email protected] 897
    3 ttp [email protected] 345
    Another eg, If EmpName is not changed and entered in second table , then i want to have the same name as the original EMP table has as shown below.
    EmpNo EmpName Email Mobile
    1 xyz [email protected] 345
    2 abc     [email protected] 897
    3 ttp [email protected] 345
    In other words something like this,
    select empno,
    EmpName as (select value from config where column_name=EmpName),
                   EmpContact as (select value from config where column_name=Empcontact),
                   EmpPhone as (select value from config where column_name=EmpPhone)
         From EMP
    Can some one please help me in providing a solution for this.
    Edited by: 941386 on May 30, 2013 6:20 AM

    Unfortunately, I think this is a job for dynamic sql ...
    Build your "query" first:
    (note this won't work "as is", fix the syntax - but you get the idea.)
    lv_str := 'select empno,
    EmpName as ' || (select value from config where column_name=EmpName) || ',
    EmpContact as ' || (select value from config where column_name=Empcontact) || ',
    EmpPhone as ' || (select value from config where column_name=EmpPhone) || '
    From EMP;';
    execute immediate lv_str;Not sure if there's a better way or not.
    Only other way I can think of is to leverage the way UNION [ALL] works.
    So the following query:
    select a, b, c from dual
    union all
    select d, e, f from dual
    /returns data in columns "named" : "a, b, c"
    Effectively renaming columns d, e, f. You just need to turn your data on edge in that first query, then throw out the rows (I don't know how to get it to work, but perhaps somebody else does?)
    [edit]
    another thought is create a view over top of the table, query that view, then drop the view :P
    that would work nicely - avoid the dynamic SQL. shrug
    [edit]
    Edited by: Greg.Spall on May 30, 2013 9:37 AM

  • Add rows from another table

    Hi ,
    I have a table with 20 records and 10 columns.I want to add columns from another table with out cross join.

    As others have said, you need to have some sort of join condition otherwise it is a cross join.
    SQL> ed
    Wrote file afiedt.buf
      1  with T1 as (select 'e' as c1, 2 as c2 from dual union all
      2              select 'd', 3 from dual)
      3      ,T2 as (select 'x' as c3, 5 as c4 from dual union all
      4              select 'y', 6 from dual union all
      5              select 'z', 2 from dual)
      6  --
      7  select T2.c3, T2.c4, T1.c1, T1.c2
      8  FROM (select c1, c2, row_number() over (order by c1) as rn from T1) T1
      9       FULL OUTER JOIN
    10       (select c3, c4, row_number() over (order by c3) as rn from T2) T2
    11*      ON (T1.rn = T2.rn)
    SQL> /
    C         C4 C         C2
    x          5 d          3
    y          6 e          2
    z          2
    SQL>This example assigns a row number to each row within each table and then joins using that row number.
    (I've assumed the row number should be generated based on the order of the first column of each table, but you can change that as required).
    What is the point of your requirement?

  • Sum of values in same column of all tables

    On the same sheet, I have multiple tables with the same column (F) titled "AMOUNT".
    I want to get the sum of all the values in that column, from every table, without having to specify each table.
    Is there a way to do this?

    It would be nice to not have to specify each table but it can't be done that way. Nonetheless, it is easy to get those sums. Type in =SUM( then click on the column letter (F in this case) of each of those tables until you have them all then add the closing parenthesis and hit return.

  • Popup Key LOV, NULL and "Invalid numeric value undefined for column"

    Hello.
    I've created an item based on database column of NUMBER type and set the following properties:
    Display As = Popup Key LOV (Displays description, returns key value)
    List of values definition=select 'display_value' d, 1 r from dual
    Null display value=%
    Null return value=
    Display Null=Yes
    When I select "%" in the LOV and try to apply changes to database I get error:
    ORA-20001: Error in DML: p_rowid=1781, p_alt_rowid=N1, p_rowid2=, p_alt_rowid2=. ORA-20001: Invalid numeric value undefined for column N2
    Error Unable to process row of table TTT.
    If I set Display As = Select List, all works fine. But I need Popup Key LOV.
    Could anybody help me?
    I use Application Express 2.2.1.00.04

    Hi all,
    I did my homework and solved this issue. First I would like to thank Patrick Wolf for the invaluable help he gives out on thread Re: Null value handling in LOVs The code presented here is just a minor edit to his code, but an essential one when dealing with Popup Key LOV items.
    Here's what I did:
    1. Create an Application Process.
    Name: RemoveNulls
    Sequence: 0
    Point: On Submit: After Page Submission - Before Computations and Validations
    Process Text:
    BEGIN
        FOR rItem IN
          ( SELECT ITEM_NAME
              FROM APEX_APPLICATION_PAGE_ITEMS
             WHERE APPLICATION_ID   = TO_NUMBER(:APP_ID)
               AND PAGE_ID          IN (TO_NUMBER(:APP_PAGE_ID), 0)
               AND LOV_DISPLAY_NULL = 'Yes'
               AND LOV_DEFINITION   IS NOT NULL
               AND LOV_NULL_VALUE   IS NULL
        LOOP
            IF (V(rItem.ITEM_NAME) = '%null' || '%' OR V(rItem.ITEM_NAME) = 'undefined')
            THEN
                Apex_Util.set_session_state(rItem.ITEM_NAME, NULL);
            END IF;
        END LOOP;
    END;Error Message: #SQLERRM#Condition: None
    2. You should be able to submit a Popup Key LOV with a NULL value now.
    Once again, THANKS, Patrick! You rock! I'm seriously thinking of trying ApexLib now :)
    Georger

  • FETCHING VALUES IN MULTI RECORD BLOCK FROM ANOTHER TABLE USING SELECT STATEMENT.

    Hi,
    I have one multi record block in which i want to fetch values
    (more then one record) from another table using select statement
    IN KEY NEXT ITEM.I am getting following error.
    ORA-01422: exact fetch returns more than requested number of rows
    Thanks in advance.

    In your case I see no reason to use non-database block and to try to populate it from a trigger with a query, instead of using the default forms functionality where you can associate the block and the fields with table, create where clause using bind variables and simply use execute_query() build-in to populate the block. The power of the forms is to use their build-in functionality to interact with the database.
    Also, you can base your block on a query, not on a table and you dynamically change this query using set_block_property() build-in. You can use any dynamic queries (based on different data sources) and you simply need to control the column's data type, the number of the columns and their aliases. Something like creating inline views as a block data source.
    However, you can replace the explicit cursor with implicit one like
    go_block('non_db_block_name');
    first_record();
    FOR v_tab IN (SELECT *
    FROM tab
    WHERE col_name = :variable)
    LOOP
    :non_db_block_name.field1 := v_tab.col1;
    :non_db_block_name.field2 := v_tab.col2;
    next_record();
    END LOOP;

  • Default value from another table - sql query

    I'm trying to make the default value of a text item as the result from an sql or pl/sql statement. I keep getting errors when I try to use a pl/sql statement to do this. Has anyone else done this?

    OK, here is what I tried to put in. I have a form and I wanted to add a text field that is derived from another table, such as:
    select question from qa_main where seq=:quest_num
    So, what I want is to have a form where questions on tests are answered, and I want the text of the question to be brought over from the question table. I'm not sure if I'm using the correct syntax, but the ":quest_num" would be a reference to a question number in the answer table that is linked to the sequence number (primary key) in the questions table.
    Of course if there are better ideas, please let me know. :)

  • UPDATE SQL string substitution from another table

    Hi - I've come across a tricky situation where I would want to update a column in all the relevant rows of a table with values obtained from another table WITHIN the same column update using string concatenation. im not getting any clean way of doing this.
    The goal is to achieve something like this:
    UPDATE table1 set col1 =
    'LANG_ID=(%s),'||
    '_CHALLENGE_RESPONSE_=(%s),'||
    'CRDN_NAM=(%s),'||
    'CLNT_MODE=(%s),'||
    'PTY_ID=(%s),'||
    'CRDN_VAL=(%s),' ||
    'USER_TZ_COD=(%s),' ||
    'GTS_USER_ID=(%s),'||
    'SP_ID=(%s),' ||
    'SP_ALIAS=(%s),' ||
    'ORIG_CLNT_ID=(%s)'
    where table1.col1 is null
    and to substitute the (%s) with data from another table2*. An example is:
    update table1 set col1=
    'LANG_ID=(select LANG_ID from table2* where USER_ID = (select USER_ID from table1))' ||
    '_CHALLENGE_RESPONSE_=((select CHALLENGERESPONSE_ from table2* where USER_id = (select USER_ID from table1)),' ||
    etc for the rest of the values

    I tried this -although the database shows that the affected rows are updated! but querying the table doesn't show the values in the column!
    select col1 from table1 where col1 is null
    shows back the original content (DESPITE it showing me xxx rows updated!)
    UPDATE table1 t1
    SET col1 = (SELECT 'LANG_ID=('||lang_id||')_CHALLENGE_RESPONSE_=('||
    CHALLENGERESPONSE_|| ...*
    FROM table2 t2
    WHERE t1.user_id = t2.user_id)
    WHERE t1.col1 is null;

  • INSERTING INTO A TABLE FROM ANOTHER TABLE

    Hi,
    I am having a table called emp in which 5 columns are there, I want to insert some rows from another table called employees, only into three columns of emp table through a sub query.
    Is this scenario is possible, I tried so many queries but it is not working out.
    Can any body help me out.
    The columns in emp table is
    empno, ename, doj, designation, salary, deptno, mgrid
    The columns in employees table is
    empno, name, hiredate, post, salary, commission, deptno, mgr
    I want to insert into empno, ename, doj, designation columns of emp table from the employees table empno, name, hiredate, post columns.
    Ramesh.

    It looks like your EMP table has 7 columns, not 5, and you want to insert into 4 columns, not 3.
    insert into emp
      (empno, ename, doj, designation)
      select empno, name, hiredate, post
        from employees;

  • SQL select a concatination of entries from another table

    I am trying to select a few columns from one table and then add another column that is a concatination or names from another table that referances it as below. Is this possible to do in one select statement?
    table x1
    ID NAME
    1 Bob
    1 Tom
    2 Bill
    table x2
    ID NAMES
    1 Bob, Tom
    2 Bill
    3

    You mean string aggregation?
    If yes, then it is possible like this, if you are on 10g.
    SQL> create table x1 (id,name)
      2  as
      3  select 1, 'Bob' from dual union all
      4  select 1, 'Tom' from dual union all
      5  select 2, 'Bill' from dual
      6  /
    Tabel is aangemaakt.
    SQL> select id
      2       , rtrim(n,', ') names
      3    from ( select id
      4                , n
      5                , rn
      6             from x1
      7            model
      8                  partition by (id)
      9                  dimension by (row_number() over (partition by id order by null) rn)
    10                  measures (cast(name as varchar2(20)) n)
    11                  rules
    12                  ( n[any] order by rn desc = n[cv()] || ', ' || n[cv()+1]
    13                  )
    14         )
    15   where rn = 1
    16  /
            ID NAMES
             1 Bob, Tom
             2 Bill
    2 rijen zijn geselecteerd.There are several other (slower) techniques possible as well. You can find them by using the search function on this forum.
    Regards,
    Rob.

Maybe you are looking for

  • I can't open my app store ??? what can i do ??

    i i can't open my app store ??? what can i do ??

  • Applet in a pack

    my java Applet class has package package com.web; import java.applet.Applet; import java.awt.*; public class Display extends Applet ..........i want to use this class in JSP <applet code="Display.class" width="300" height="150"> </applet> How do i wr

  • How to reload games and the collections...please h...

    Ok on the nokia 6300 i accidently deleted the soccer and snakes games and also the world clock and a couple more in that group. I was just wondering on how to find the games and world clock for examplr again because i have looked on the internet and

  • MiniDV - Sony vs Panasonic?

    Wow - so glad I checked this forum...almost bought a HDD camcorder this morning. I want to record and edit using iMovie, so it seems like MiniDV is the format for me, right? I've narrowed it to the SOny DCR-HC96 or the Panasonic PV-Gs80 Any thoughts

  • Executing ALT + right Shift automatically

    Hi, when a user focus in a text field, he would press ALT + right Shift in order to type Arabic letters. Is there a way to make Flex to switch to arabic by executing ALT + right Shift automatically ? Best regards