Using a varchar field to select statement

Hi all
I have a single row and single column table
T(command varchar2(4000))
and the row is
sno,name
And I have another table T1(sno number,name varchar)
Now can any body tell how can i use command column in table T to query T1 to get sno,name from T1
I am looking for a select statement like this
select (select command from T) from T1;
but it is printing out the data in T i mean sno, name
This is a copy of thread Selecting output of a select statement
but explained more clearly
Thanks,
ganesh.

I don't know why your tables are designed like this but what I think you want to do is join T1 with the data in T.
select sno, name from T1
where sno in (select substr(command,0,instr(command,',')-1) from T)
and name in (select substr(command,instr(command,',')+1) from T);
substr returns a string up to a position
instr returns the position of a string
and the other post you refer to as about as confusing as your one.

Similar Messages

  • Using pop-up value in select statement

    Hello.
    I want to select a value from a pop-up box and then use that value in a select statement for another pop-up. Is that possible?
    The first pop-up is P39_PIIN_CALL but it is not recognized in the second pop-up when I use it in the select statemnt... select * from table where PIIN = :P39_PIIN_CALL. I get nothing back because it has no idea what :P39_PIIN_CALL is. I'm desperate and on a timeline.
    Thanks,
    Mark E

    Hi,
    After fetching the value from first popup the page should submit so that the value is availble to the second popup..
    Edit the first popup.. and in HTML Form Element Attributes and enter onchange="doSubmit('MyRequest')"
    Regards,
    Shijesh

  • Limitations in using a function within a select statement

    I have a function which retrieves various data elements from the
    database and formats it accordingly. The data (varchar2)
    returned could be in excess of 2,000 characters length.
    I need to use the returned data as part of a view. I am able to
    use the function in a "select" statement, but when I use it with
    returned data in excess of 2,000 chars, I get the following
    error:
    ORA-06502: PL/SQL: numeric or value error
    This error is occurring whenever the returned data is in excess
    of 2,000 characters.
    Is there an alternative method to what I am proposing, I have
    tried alternative data types but if I am able to use it in a
    "select" statement, I get the above error when the returned
    length exceeds 2,000 chars.
    Thanks
    Peter

    are u using oracle 7. varchar2 limit in 8 is 4000.

  • Use of cursors insted of select statements

    could any one please explain what is the advantage of using cursors instead of simple select statements
    thanks
    siby

    A benefit to using an explicit cursor rather than a select statement, is for the NO_DATA_FOUND exception. Its kind of like a free IF statment. IF no data is found, then stop.
    if you write a select statement, and no data is returned, you SHOULD code for the NO_DATA_FOUND exception. Often people say, "i'll ALWAYS get a row returned". but you should always cover your code "just in case". so you must code an exception...
    declare
    v_var varchar2(1);
    procedure do_something(p_parm varchar2) is
    begin
    null;
    end do_something;
    procedure log_error is
    begin
    null;
    end log_error;
    begin <<main>>
    do_something('x');
    begin <<selectblock>>
    select dummy
    into v_var
    from dual
    where dummy = 'a';
    do_something(v_var);
    exception
    when no_data_found then
    log_error;
    end selectblock;
    do_something (v_var||'abc');
    end main;
    if you use an explicit cursor instead, you don't need to code for the NO_DATA_FOUND. If an explicit cursor opens and finds no rows, there are simply no rows. of course, you don't need a loop if you expect only 1 row returned under normal circumstances.
    BTW, don' forget that SQL%ROWCOUNT and your_cursor%ROWCOUNT are not initialized. There is a null, until a row is successfully fetched. therefore if no rows are returned at all, %ROWCOUNT is NULL.
    declare
    v_var varchar2(1);
    cursor my_cur is
    select dummy
    from dual
    where dummy = 'a';
    procedure do_something(p_parm varchar2) is
    begin
    null;
    end do_something;
    procedure log_error is
    begin
    null;
    end log_error;
    begin << main>>
    for cur_rec in my_cur loop
    dbms_output.put_line('inside');
    begin <<loop_block>>
    if nvl(my_cur%rowcount,0) > 1 then
    do_something(cur_rec.dummy);
    else
    log_error;
    end if;
    end loop_block;
    end loop;
    end main;
    /

  • Using a varchar field as number on ui

    Hello
    In one of the requirements we got to use a varchar field in db to store as number in UI. The user may specify + or - in the begining and it can be number up to 2 decimal places.
    So, how to achieve this?
    We are using jdev 11.1.1.6.2

    may be have a transient field with number datatype and use af:convertNumber with minFractionDigits and maxFractionDigits to 2. it would take - not sure about + sign (might remove automatically). convert this as string and try saving it with your actual field.

  • Can we use is null in our select statement in ABAP program

    hi,
    I want to use 'is nul' or 'not null' in select statement of my ABAP program for any field. I have written below query but I am getting sy-subrc = 4 and getting no data. Can anyone resolve this.

    Hi,
    I think you've posted your question on the wrong forum. This is the SAP Business One development forum which is not part of ERP and doesn't include any ABAP or Netweaver programming.
    For a list of forums please see here:
    http://forums.sdn.sap.com/index.jspa
    Kind Regards,
    Owen

  • Dynamic fields in select statement

    Hi all,
       In selection screen we are having period as select option.The values for period are 01 to 16. Based on 
          the values entered in selection screen for period we need to select HSLXX from FAGLFLEXT.
       For example if we enter 01 to 03 in selection screen then we need to select HSL01 HSL02 HSL03  
           from FAGLFLEXT.
      Like this we need to select fields dynamically in select statement. Can any one tell me how to restrict fields dynamically.
    Regards,
    Swetha

    hi Swetha,
    the  third select statemnet will work for  you..
    try this..
    _Dynamic where clause in select query.._
    * With a variable, result: AND rbusa = '5145'
    concatenate 'AND rbusa = '  ''''  i_tab-zgsber  ''''
    append where_clause to where_tab.                                  
    * Select
    select * from zcostfreq                                           
         where (where_tab).                                              
    endselect.
    _Using a dynamic table name_
    parameters:
    p_tab type tabname.
    start-of-selection.
      select count(*) from (p_tab) into l_count.
    _Dynamic retrieval and writing of data_
    FIELD-SYMBOLS:
      <row>         TYPE ANY,
      <component>   TYPE ANY.
    PARAMETERS:
    p_tab TYPE tabname.
    CREATE DATA dataref TYPE (p_tab).
    * The variable dataref cannot be accessed directly, so a field symbol is
    * used
      ASSIGN dataref->* TO <row>.
      SELECT *
        FROM (p_tab) UP TO 10 ROWS
        INTO <row>.
        NEW-LINE.
        DO.
    *     Write all the fields in the record   
          ASSIGN COMPONENT sy-index
            OF STRUCTURE <row>
            TO <component>.
          IF sy-subrc <> 0.
            EXIT.
          ENDIF.
          WRITE <component>.
        ENDDO.
      ENDSELECT.
    Regards,
    Prabhduas

  • Where condition with optional fields in select statement

    Hi,
    In a function module I have to fetch data based on 7 fields out of which 6 are optional.
    If we won't enter values for optional fields it will take default values as zeroes .
    So this is not fetching data. But for some fields some values has zero values.
    How to solve this condition?
    Regards,
    maha.

    Hi,
    For those import parameters for which its mentioned as optional, use like condition in the where clause of select statement in the function module.
    try like this,
    concatenate pfield2 '%' into pfield2.
    concatenate pfield3 '%' into pfield3.
    concatenate pfield4 '%' into pfield4.
    concatenate pfield5 '%' into pfield5.
    concatenate pfield6 '%' into pfield6.
    concatenate pfield7 '%' into pfield7.
    select *
    from db table
    into itab
    where field1 = pfield1 and
               field2  like pfield2 and
               field3  like pfield3 and
               field7 like pfield7.
    Now even if the optional fields are blank, data will be selected
    Regards,
    Vik

  • How to use bind variable in this select statement

    Hi,
    I have created this procedure where table name and fieldname is variable as they vary, therefore i passed them as parameter. This procedure will trim leading (.) if first five char is '.THE''. The procedure performs the required task. I want to make select statement with bind variable is there any possibility to use a bind variable in this select statement.
    the procedure is given below:
    create or replace procedure test(tablename in varchar2, fieldname IN varchar2)
    authid current_user
    is
    type poicurtype is ref cursor;
    poi_cur poicurtype;
    sqlst varchar2(250);
    THEVALUE NUMBER;
    begin
         sqlst:='SELECT EMPNO FROM '||TABLENAME||' WHERE SUBSTR('||FIELDNAME||',1,5)=''.THE ''';
         DBMS_OUTPUT.PUT_LINE(SQLST);
    OPEN POI_CUR FOR SQLST ;
    LOOP
         FETCH POI_CUR INTO THEVALUE;
              EXIT WHEN POI_CUR%NOTFOUND;
              DBMS_OUTPUT.PUT_LINE(THEVALUE);
              SQLST:='UPDATE '||TABLENAME|| ' SET '||FIELDNAME||'=LTRIM('||FIELDNAME||',''.'')';
              SQLST:=SQLST|| ' WHERE EMPNO=:X';
              DBMS_OUTPUT.PUT_LINE(SQLST);
                   EXECUTE IMMEDIATE SQLST USING THEVALUE;
    END LOOP;
    COMMIT;
    END TEST;
    Best Regards,

    So you want to amend each row individually? Is there some reason you're trying to make this procedure run as slow as possible?
    create or replace procedure test (tablename in varchar2, fieldname in varchar2)
    authid current_user
    is
       sqlst      varchar2 (250);
       thevalue   number := 1234;
    begin
       sqlst := 'update ' || tablename || ' set ' || fieldname || '= ltrim(' || fieldname || ',''.'')  where substr(' || fieldname
          || ',1,5) = ''.THE ''';
       dbms_output.put_line (sqlst);
       execute immediate sqlst;
    end test;will update every row that satisfies the criteria in a single statement. If there are 10 rows that start with '.THE ' then it will update 10 rows.

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Problems with Hints in abap code to use an index in a Select statement

    Hi,
    I want to use an especific index in a select statement but I can´t get it. I use de next statement:
    SELECT ltaklgnum ltaktanum ltakvbeln ltaptapos ltapnltyp ltappvqui
           FROM ltak AS ltak INNER JOIN ltap AS ltap
                            ON  ltaktanum = ltaptanum
                            AND ltaklgnum = ltaplgnum
           INTO TABLE l_t_tanum_silo
           WHERE ltap~lgnum EQ ip_lgnum
             AND ltap~pquit EQ ' '
             AND ltak~lgnum EQ ip_lgnum
             AND ltak~kquit EQ ' '
             AND ltak~queue EQ ip_queue
             %_HINTS DB2 ''.
    We have DB2 for Linux Unix and Windows 9.5 as DB system.
    How can I fix this?
    Thanks a lot.
    Regards

    The DB2 for Linux Unix and Windows is coded DB6 for SAP and not DB2
    Look at the following OSS notes
    - [Note 129385 - Database hints in Open SQL|https://service.sap.com/sap/support/notes/129385]
    - [Note 150037 - Database hints in Open SQL for DB6 (DB2 for LUW)|https://service.sap.com/sap/support/notes/150037]
    - [Note 1270314 - DB6: DB2 9.5 Perf. degrad. for queries with INLIST clause|https://service.sap.com/sap/support/notes/1270314]
    - [Note 868888 - DB6: Optimization Guidelines|https://service.sap.com/sap/support/notes/868888]
    You should use a
    SELECT ltak~lgnum ltak~tanum ltak~vbeln ltap~tapos ltap~nltyp ltap~pvqui
      FROM ltak AS ltak INNER JOIN ltap AS ltap
      ON ltak~tanum = ltap~tanum
        AND ltak~lgnum = ltap~lgnum
      INTO TABLE l_t_tanum_silo
      WHERE ltap~lgnum EQ ip_lgnum
        AND ltap~pquit EQ ' '
        AND ltak~lgnum EQ ip_lgnum
        AND ltak~kquit EQ ' '
        AND ltak~queue EQ ip_queue
      %_HINTS DB6 '<IXSCAN TABLE=''LTAP'' INDEX=''"LTAP~M"'' />'.
    In note 868888 there is a sample for a join.
    SELECT A~TABSPACE
    FROM TADB6 AS A
    JOIN IADB6 AS B ON A~TABART = B~TABART
    %_HINTS DB6 '<NLJOIN><IXSCAN TABLE=''IADB6'' />'
            DB6 '<IXSCAN TABLE=''TADB6'' /></NLJOIN>'.
    Regards

  • Can use place holder (?)in select statement.

    Is it possible to have have a place holder in my select clause or it is possible to have only in where clause?
    Please find the below query I am having place holder in select statement emp_id=? nit it is throwing an error for me.
    select * from(select myrows.*, rownum rn from(select acc as account, es as identity,address as street_address
    state as stae,select id from mytable where emp_id=? as my site from myview
    where ert_id=? and chek=?
    I am getting an error ORA-00936:     missing expression is it possible to have a place holder in select statement
    Please help me on this.
    Regards,
    BA

    user575682 wrote:
    Is it possible to have have a place holder in my select clause or it is possible to have only in where clause?
    Please find the below query I am having place holder in select statement emp_id=? nit it is throwing an error for me.
    select * from(select myrows.*, rownum rn from(select acc as account, es as identity,address as street_address
    state as stae,select id from mytable where emp_id=? as my site from myview
    where ert_id=? and chek=?
    I am getting an error ORA-00936:     missing expression is it possible to have a place holder in select statement
    Please help me on this.
    Regards,
    BAfor clarity and easy to be read i attempted to rearrranged your code and this is what it will look like:
    select *
      from (select myrows.*, rownum rn
              from (select acc as account,
                           es as identity,
                           address as street_address
                           state as stae,
                           select id
                      from mytable
                     where emp_id = ? as my site from myview where ert_id=? and chek=?apparently the syntax is not correct and by that you are missing some comma in your column, ? question mark symbol will not be recognize, and some ')' closed parenthesis.
    are you using a report builder that you want to use a placeholder column?

  • Determine Length of Field in Select Statement

    Hi Experts!
    My officemate has this little problem regarding selection of data based on a certain condition...
    Here is the situation:
    For Example...
    In table KNA1....
    KUNNR       NAME1         Length of Data in Name1
    000001        AA                2           
    000002        AB                2
    000003        ABCD           4
    000004        ABCDE         5
    She only wants to get the records that has the length of 2 in KNA1-NAME1,
    i.e., 'AA' and 'AB' without having to put it in the internal table then make a loop and update the table using the strlen() condition....
    Experts, is this possible? Knowing the length of the data in the select statement? She wants this alternative because it is faster rather than having to loop in internal tables and check if this data has the length of 2 or 3 or 4 and so on....
    Can you please help me out with this one? Thanks in advance!
    <b></b>

    Hi
    If the lenghtn is 6 characters and if you want to fetch only first 2 characters.
    you can use offset
    fetch data from internal table and take variable
    v_var1 = itab-name1+0(2).
    you get only first 2 characters....
    if you want last 2 characters itab-name1+4(2).
    Thanks

  • Usgent: using jsp date in sql select statement

    i have something like this:
    String day;
    String month;
    String year;
    select * from event where date = xxx
    where xxx is supposed to be obtained from the strings (day, month, year) and changed into a format that can be compared to in the select statement.
    what should xxx be?
    thks as lot cos i ahe been figuring out for very long.

    Use PreparedStatement and SimpleDateFormat:
    String year = "2002";
    String month = "9";
    String day = "12";
    String sDate = day + "/" + month + "/" + year;
    SimpleDateFormat df = new SimpleDateFormat("M/d/yyyy");
    Date dDate = df.parse(sDate);
    Connection con = DriverManager.getConnection(user, pw);
    PreparedStatement ps = con.prepareStatement("SELECT * FROM event WHERE date = ?");
    ps.setDate(1, dDate);
    ResultSet rs = ps.executeQuery();
    while (rs.next()) {
    rs.close();
    ps.close();
    con.close();

  • Restrict number of characters in table field for select statement.

    SELECT * FROM table
                    WHERE  column1  = z-column.
    The field column1 is of  type char and size 20
    The field z-column is of type char size 10.
    how do we perform this select?
    Anyone can guide me?
    Edited by: Hadesfx on Sep 11, 2009 3:56 PM
    Edited by: Hadesfx on Sep 11, 2009 3:59 PM

    Hello,
    In your OP did you mention this? Please be specific when you post the next time.
    Can you please post your code?
    I think you have to try a work around:
    DATA:
    RS_STOCKID TYPE SELOPT,
    RT_STOCKID TYPE STANDARD TABLE OF SELOPT.
    LOOP AT GT_ZB1PUT_STOCKTMP.
    RS_STOCKID-SIGN = 'I'.
    RS_STOCKID-OPTION = 'EQ'.
    RS_STOCKID-LOW = GT_ZB1PUT_STOCKTMP-STOCKID.
    APPEND RS_STOCKID TO RT_STOCKID.
    CLEAR RS_STOCKID.
    ENDLOOP.
    You can use this RANGE table to SELECT data from the table.
    SELECT * FROM zb1xxt_param
                FOR ALL ENTRIES IN gt_zb1put_stocktmp[]
                WHERE zzcode    = 'DEV036'
                AND   zzdomain  = 'SD'
                AND   zzdata    = 'INBOUND'
                AND   zzinput1  = 'STOCKID'
                AND   zzinput2  IN RT_STOCKID. "Use RT_STOCKID for SELECT'ing data
    BR,
    Suhas

Maybe you are looking for

  • Problem about execute import button

    This is mdm 5.5 sp4. First, i did field mapping and value mapping in mdm import manager. Then i clicked 'execute import' button. The importing was successful. After that, I added new fields in ‘destination fields’ of ‘field mapping’ panel via ‘add’ b

  • New install of solaris 10 and I cannot see the other 5 harddrives

    I am a bit rusty on solaris but here is the issue and exscuse my clulessness. Just installed 10 on an e450. At the ok prompt you can query the hardware and the hard drives are there. From the OS level, they do not appear. In the solaris console I can

  • Container objects

    With Swing components, Is there an easy way to see if a particular object is contained within another object? For example, how can I tell if one panel is located in another panel?

  • WLS 10.3.4: How to use OS authentication for JDBC Data Source

    Hello all, As a preface, I've tried searching the forum/Google for "OS authentication" and reading the WLS JDBC doc to no avail - if it's documented somewhere, a RTFM link would be much appreciated. I'm trying to set up a JDBC data source on WLS that

  • Firefox 4 opens mail in a non-resizable window on clicking a mail ID of my 1and1webmail list

    My company has provided me a mail account in 1and1 web mail. Whenever I click a mail in the list for display, the mail is opened in a non-re-sizable fixed window that has only a close option. This does not happen for other websites. This problem does