Selecting only columns from a table

Could someone help me with a SQL query to select all the columns in a table as an array?

Hello
if you are on 9i upward, you can define a pl/sql table of the rowtype and use bulk collect to populate that table, otherwise, you can create separate array types for each column:
create table dt_test_tab (id number, col1 varchar2(10));
insert into dt_test_tab values(1, 'X');
insert into dt_test_tab values(2, 'X');
insert into dt_test_tab values(3, 'X');
insert into dt_test_tab values(4, 'X');
insert into dt_test_tab values(5, 'X');
commit;
declare
    type tt_TestTab is table of dt_test_tab%rowtype index by binary_integer;
    type tt_TestTabid IS TABLE OF dt_test_tab.id%type index by binary_integer;
    type tt_TestTabcol1 IS TABLE OF dt_test_tab.col1%type index by binary_integer;
    lt_TestTab     tt_TestTab;
    lt_Id          tt_TestTabId;
    lt_col1        tt_TestTabcol1;
begin
    --use the rowtype array
    select
         id,
         col1
    BULK COLLECT INTO
         lt_testtab
    FROM
        dt_test_tab;
   --use the individual column arrays
    select
         id,
         col1
    BULK COLLECT INTO
         lt_id,
         lt_col1
    FROM
        dt_test_tab;
    dbms_output.put_line('loop through the rowtype array');
    FOR x in lt_TestTab.FIRST..lt_TestTab.LAST LOOP
       dbms_output.put_line(to_char(lt_TestTab(x).id)||to_char(lt_TestTab(x).col1));
    end loop;
    dbms_output.put_line('loop through the two column arrays');
    FOR x in lt_Id.FIRST..lt_Id.LAST LOOP
       dbms_output.put_line(to_char(lt_Id(x))||to_char(lt_Col1(x)));
    end loop;
END;

Similar Messages

  • Selecting a column from a table conditionally

    I'm trying this select statement (example):
    select np.phone_number from name_phone np, reservation_general_view rgv
    where rgv.resort='HVILLA'
    In this table there is a column called "phone_type" and I only want my column to display values that are associated to the column when the "phone_type" = 'EMAIL'
    I tried this:
    select np.phone_number(select np.phone_number from name_phone np where np.phone_type='EMAIL')
    from name_phone np, reservation_general_view rgv
    where rgv.resort='HVILLA'
    This doesn't seem to work...can someone tell me how to do that?
    Message was edited by:
    JonnyOpera

    select phone_number from name_phone
    where resort='HVILLA'
    and phone_type='EMAIL'

  • Select sql running very long when made to select many columns from a table

    Hi,
    I am using an Oracle DB 10g. I have a table with 250 columns and I need to select 200 columns out of them. The table holds around 0.1 million rows. But when I run the select sql it takes 15 mins to return .1 million rows. Where as if I select only 10 or 15 columns the sql runs in less than a minute returning same number of rows. My sql looks like below:
    select p.col1,p.col2,.......,p.col200
    from table Parent p;
    The table also has a Primary key Index but it does not seem to be using it even when I forced an Index hint. Could you pls help?

    961796 wrote:
    I am using an Oracle DB 10g. I have a table with 250 columns and I need to select 200 columns out of them. The table holds around 0.1 million rows. But when I run the select sql it takes 15 mins to return .1 million rows. Where as if I select only 10 or 15 columns the sql runs in less than a minute returning same number of rows. My sql looks like below:
    As Sven points out, it is likely that most of your time is network (and client) time. You are sending 20 times as much data (based on column counts, at any rate) across the network, and concerned that it's taking 15 times as long.
    If you're testing from SQL*Plus then setting the arraysize to a value larger than the default might help.
    If you have control over the SQL*Net settings then you may get some benefit by adjusting the SDU sizes at both ends of the link.
    If you have control over the tcp configuration (transmit and receive buffer sizes) then you may get some benefit by adjusting these.
    Simple test, by the way, if you're on SQL*Plus
    set autotrace traceonly statistics
    select ...This will dump your data in the bit bucket as it arrives giving you
    a) the database time plus network time
    b) some statistics including the volume of data down the network and the number of network round-trips that Oracle saw.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    Author: <b><em>Oracle Core</em></b>

  • Select LONG column from Remote table

    Hi to all.
    I have the following problem: I can't select a LONG column from remote database, when there are Join operation in the query. Example:
    SELECT long_column FROM remote_table@DB
    -> that's OK, but:
    SELECT long_column FROM remote_table@DB INNER JOIN remote_table2@DB ON ...
    -> returns: "ORA-00997: Illegal use of LONG datatype"
    I cannot even perform (because there a LONG column in the joined table):
    SELECT nonlong_column FROM remote_table@DB INNER JOIN remote_table2@DB ON ...
    That's very strange to me because:
    SELECT long_column FROM local_table INNER JOIN local_table2 ON ...
    -> is OK!
    Can someone help me to SELECT a long column from remote in SELECT query with JOIN clause!
    Thanks a lot!

    Hi
    "Distributed queries are currently subject to the restriction that all tables locked by a FOR UPDATE clause and all tables with LONG columns selected by the query must be located on the same database. " by otn docs.
    I have no idea.
    Ott Karesz
    http://www.trendo-kft.hu

  • Selecting date column from a table

    hi
    I have a problem that looks wierd for me.
    I have a table called blog_post which has a date field called publish_date
    I have done this first.
    alter session set nls_date_format='dd/mm/yyyy';
    then
    SQL> select publish_date from blog_post;
    PUBLISH_DA
    09/07/2007
    02/07/2007
    02/07/2007
    02/07/2007
    09/07/2007
    now the wierd thing is that when i am selectin the same date it is not returning anything
    SQL> select publish_date from blog_post where publish_date='09/07/2007';
    no rows selected
    Thanks for any help.
    Ganesh

    I don't know anything about Hibernate, but the reason why you need to specify the trunc(publish_date) = to_date('09/07/2007','dd/mm/yyyy') is because of the way that Oracle stores date/time internally.
    It's labelled as a date field, but the time is automatically stored as well. So, if you're just wanting to compare the date to another date, you need to ignore the time part of the column - the trunc function does this.
    As for the "to_date(<date>, <date mask>)", well, you want to compare a date to a date, not a string. You could rely on the implicit conversion, governed by the nls settings, but I really, really, really wouldn't. In fact, I can't stress enough how much of a bad idea that would be! It's best to make things explicit.

  • Selecting columns from two table is slow but same

    I am selecting 27 columns from two tables
    which running for more than 30 minutes. but
    if I select count(*) with the same query
    except the columns it is coming in seconds.
    Where is the error?

    If you post
    1) The table definitions for the underlying tables
    2) The indexes that are on the tables
    3) The two SQL statements you're running
    4) The explain plan for both statements
    we can probably be of some assistance.
    My guess is that the count(*) is able to return much more quickly because the optimizer is able to use a significantly faster query plan that is based on an index which the longer-running query cannot utilize. Without the information I've requested, though, it's hard to do more than speculate.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • List all columns having only nulls from all tables in a database.

    I want to select columns from all tables having only null values. Each table has 60+ columns and i have 100+ tables in database. Requesting a script to list all tables at a time and their columns having all nulls? Below is my expected output. Thank
    you in advance !
    Table name
    Null valued Column
    Address
    Address Line 2
    Address
    Address Line 3
    Address
    Zip Code
    Product
    Product Desc
    Product
    Product SKU

    Hello,
    In addition to Naomi's reply, you can refer to the following links about loop through all the tables in the database:
    http://www.codeproject.com/Tips/161663/Loop-through-all-tables-in-SQL-Server
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/07b9799e-aeab-442e-99a0-ba76ab051f59/looping-through-databases-and-count-the-number-of-items-in-a-specific-table?forum=transactsql
    Regards,
    Fanny Liu
    Fanny Liu
    TechNet Community Support

  • How can I select columns from a table EMP, using Select statement?.

    Hi Friends,
    How can I select columns from a table EMP?.
    I want to select columns of EMP table, using select statement.
    Please reply me urgently.
    Shahzad

    Something like this:
    scott@DBA> select empno,ename,job from emp;
         EMPNO ENAME      JOB
          7369 SMITH      CLERK
          7499 ALLEN      SALESMAN
          7521 WARD       SALESMAN
          7566 JONES      MANAGER
          7654 MARTIN     SALESMAN
          7698 BLAKE      MANAGER
          7782 CLARK      MANAGER
          7788 SCOTT      ANALYST
          7839 KING       PRESIDENT
          7844 TURNER     SALESMAN
          7876 ADAMS      CLERK
          7900 JAMES      CLERK
          7902 FORD       ANALYST
          7934 MILLER     CLERK
    14 rows selected.Check the documentation:
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#sthref9697
    Message was edited by:
    Delfino Nunez

  • Including column from fact table reduces number of rows returned

    Hello
    I am facing this issue where in a report I select 5 columns from a fact table. Out of these five columns one of the column is "Amount" for which the aggregation rule is defined as Sum in RPD.
    When I include these five column and filter results based on some criterion , I get all the rows (three rows) that satisfy the criterion. No I add a sixth column to my report and suddenly I only see one row returned by my report. Addition of this sixth column does not affect the criterion as the criterion is not based on this column. But this sixth column is a calculated column.
    I tried different things but because the report was just getting columns from one table (fact) and suddenly inclusion of one column leads to reduction in number of rows , I was unable to find any reason why would that happen.
    So I thought that some one in community may know that in what scenario this happens.
    Thanks

    Are there any repeated values? I'm wondering if what you're seeing is actually suppression of repetition in the results. Edit the analysis, go to the criteria tab, click column properties, go to the Column Format tab, and change the setting for value suppression from 'Suppress" to "Repeat". Repeat for each of your 6 columns and check the outcome.
    Otherwise, I would try testing with other calculations and also bring in some columns from dimension tables to see how this affects the result. You should be able to come up with a case-by-case scenario to work out exactly what causes the rows to be suppressed which will get us one step to closer to working out why the rows get suppressed.
    Thanks,
    George

  • Select a row from a table and throw an url

    Hi experts,
    I'm trying to select a row from a table in Visual Composer. What I need to do it's to click over this row and throw an Url. At the moment, I've added a column with a Pushbutton with the formula to show the link; it works fine. But I need to do it without buttons just selecting the row.
    Is there anyboby who knows about that?
    Thanks a lot.
    Belen

    Hi
    To do this you will have to use a data store and a guard condition on the line which is triggered by the select action. You need to store a value in the data store each time a select action is performed. The guard condition should check for this and only perform the action when the value in the data store is greater than 0.
    Jarrod Williams

  • How can I make my query to compare only columns of two tables... not the storage information?

    11GR2
    =-----------------------------------
    I am using below querry to compare two table that has same name, under two different users... But after making storage information false like below and  if the storage information is different on column level than it create "Alter modify " statements for the column ... How can I make my query to compare only columns of two tables... not the storage information?
    begin
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'PRETTY', TRUE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SQLTERMINATOR',TRUE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SEGMENT_ATTRIBUTES', FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE', FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'TABLESPACE',FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'CONSTRAINTS',FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'REF_CONSTRAINTS',FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'CONSTRAINTS_AS_ALTER',FALSE);
    End;
    select REGEXP_REPLACE(dbms_metadata_diff.compare_alter('TABLE','TABLE_NAME_A','TABLE_NAME_A','USER1','USER2'),('USER1...'),'', 1, 0, 'i') from dual

    I am using below querry to compare two table that has same name, under two different users... But after making storage information false like below and  if the storage information is different on column level than it create "Alter modify " statements for the column ... How can I make my query to compare only columns of two tables... not the storage information?
    If you want help you have to SHOW us what you are doing and how you are doing it; you can't just try to tell us in your own words.
    We can't see your computer screen.

  • Columns from different tables displayed in an ADF table format

    I have a many to one relationship between 2 tables (checklist -> subcontract). I would like to display columns from each table on a web page in an ADF Read Only Table format. I created a method that returns the data I need from the tables. When I drag that method over to my page JDev I'm only allowed to select columns from either the checklist table OR the subcontract table. I need one column from the subcontract table and several columns from the checklist table. I'm using JDev 10.1.3.2 and an Oracle 11g database. Thank you in advance.
    -Wade

    Thank you for your response. I ended up creating a new getter in the Checklist table which refers to the column in the Subcontract table. Then I was able to create a table column for that returned value.
    Thanks again!
    -W

  • Combining the same column from 2 tables with distinct result.

    I have 2 tables with identical name columns. One is current people and the other is historical people. I want a select that returns any name that is in either table. I want each name listed only once. I want to see 1 entry for each name if it is in the current table, the historical table, or both tables. I can easily do a select distinct on each table but how do I join the queries to get 1 result set with no duplicates? The name column is not a key field and I don't want any other columns from either table.

    Just a simple UNION:
    select name
      from current
    union
    select name
      from historical;

  • Count(*) , group by with multiple columns from multiple tables involved

    Hi all,
    I am relatively new to SQL.
    Currently I have these few requirements, to display quite a number of fields from 3 tables for display of report.
    In my query I need to:
    1.) count(*)
    2.) select quite a number of fields from table 1,2,3
    However when count(*) is used, grouped by has to be used to.
    How do I actually use group by with so many columns to be selected?
    I have actually used the query below, but the count(*) returns 1, the correct output should be 3 instead.
    select count(*), table1.col1, table1.col2, table1.col3, table2.col3, table2.col4, table2.col6, table3.col1, table3.col4, table3.col5
    from table1, table2, table3
    where
    <conditions>........................
    group by table1.col1, table1.col2, table1.col3, table2.col3, table2.col4, table2.col6, table3.col1, table3.col4, table3.col5
    I know this group by statement looks very unrefined. How can I select multiple fields from different tables, and yet get the count(*) correctly?
    Thank you so much for your time.

    Hmm yes it actually does return count as 1 for each row. But there are 3 rows returned. E.g.
    ctr table1.col1 table1.col2 ..........
    1 value1 value1
    1 value2 value3
    1 value3 value4
    If I put the count(*) outside, it returns 3 , the correct output
    ctr
    3
    select count(*) from
    select table1.col1, table1.col2, table1.col3, table2.col3, table2.col4, table2.col6, table3.col1, table3.col4, table3.col5
    from table1, table2, table3
    where
    <conditions>
    group by table1.col1, table1.col2, table1.col3, table2.col3, table2.col4, table2.col6, table3.col1, table3.col4, table3.col5
    Thus I was wondering if it was the group by of multiple colns that resulted in the count stucked at value 1.

  • Help with this sql. Select only employees from a distinct Org??

    Hi guys, simple query.
    create table balancetest(emp_id number, balance_id number, balance number, org number);
    insert into balancetest values (111, 1, 1, 0);
    insert into balancetest values (111, 1, 1, 0);
    insert into balancetest values (111, 2, 1, 1);
    insert into balancetest values (222, 1, 2, 1);
    insert into balancetest values (333, 3, 4, 3);
    insert into balancetest values (333, 3, 4, 2);
    commit;
    SQL> select * from balancetest;
        EMP_ID BALANCE_ID    BALANCE        ORG
           111          1          1          0
           111          1          1          0
           111          2          1          1
           222          1          2          1
           333          3          4          3
           333          3          4          2
    6 rows selected.As you can see, emp_id 111 appears on different Org (0 and 1). I need to calculate the balance but the requirement says that I need to retrieve employees appearing only in 1 org.. It won't matter which org is selected (the business rules ensure balance will be the same), as long as if an employee is in multiple org, this employee is selected only once for an org. So, my result will be something like:
        EMP_ID BALANCE_ID    BALANCE        ORG
           111          1          1          0
           111          1          1          0
           222          1          2          1
           333          3          4          3
           333          3          4          2or,
        EMP_ID BALANCE_ID    BALANCE        ORG
           111          2          1          1
           222          1          2          1
           333          3          4          3
           333          3          4          2In other words, an employee must appear only in 1 org in my result.
    any ideas? I tried:
    select * from balancetest bal1
    where not exists ( select bal2.emp_id from
                               balancetest bal2
                               where bal2.emp_id = bal1.emp_id
                               and bal2.org <> bal1.org
                               );But I guess it won't be that simple!!

    Hi,
    You can find the lowest-numbered org for each employee like this:
    SELECT    emp_id
    ,         MIN (org)  AS min_org
    FROM      balancetest
    GROUP BY  emp_id;You can get the results you want by selecting only rows from balancetest that match a row in this the result set above. There are many ways to do that, such as a join:
    WITH  g  AS
        SELECT    emp_id
        ,         MIN (org)  AS min_org
        FROM      balancetest
        GROUP BY  emp_id
    SELECT  b.*
    FROM    balancetest  b
    JOIN                 g  ON  b.emp_id = g.emp_id
                            AND b.org    = g.min_org;

Maybe you are looking for