Query from variable column name?

Running on LAMP
Table - CONTACTS (35 COLUMNS APPROX)
I want to be able to create a results page from a detailed
query.
My first attempt was to include 35 text fields in a form and
then build the query: like '%namesearch%' and like
'%companysearch%' and like '%companytype%' etc. etc. etc.
But this is time consuming and prone to bugs.
I though a much easier way would be to have two fields: one
criteria field and one field representing the column you want to
search in....
Hmm...
This is the query that I thought might work.
SELECT * FROM CONTACTS
WHERE 'colsearch' LIKE '%critsearch%'
ORDER BY COMPANY, FULLNAME
Obviously 'colsearch' is a variable from a menu drop down
field.
Strangely, if I set the default value for colsearch as
COMPANY and default value for critsearch as '%', it does seem to
return a result (all records) on the page load (I have the form and
results on the same page) but if I hit submit, it returns no
recordset!
Is this even possible?
CODE:
$colsearch_recordlookup = "COMPANY";
if (isset($HTTP_POST_VARS['scolumn'])) {
$colsearch_recordlookup = (get_magic_quotes_gpc()) ?
$HTTP_POST_VARS['scolumn'] :
addslashes($HTTP_POST_VARS['scolumn']);
$critsearch_recordlookup = "%";
if (isset($HTTP_POST_VARS['scriteria'])) {
$critsearch_recordlookup = (get_magic_quotes_gpc()) ?
$HTTP_POST_VARS['scriteria'] :
addslashes($HTTP_POST_VARS['scriteria']);
mysql_select_db($database_dbcrm1, $dbcrm1);
$query_recordlookup = sprintf("SELECT * FROM CONTACTS WHERE
'%s' LIKE '%%%s%%' ORDER BY COMPANY, FULLNAME",
$colsearch_recordlookup,$critsearch_recordlookup);

RichardODreamweaver wrote:
> This is the query that I thought might work.
>
> SELECT * FROM CONTACTS
> WHERE 'colsearch' LIKE '%critsearch%'
> ORDER BY COMPANY, FULLNAME
>
> Obviously 'colsearch' is a variable from a menu drop
down field.
The name of the column should not be in quotes:
SELECT * FROM CONTACTS
WHERE colsearch LIKE '%critsearch%'
ORDER BY COMPANY, FULLNAME
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Similar Messages

  • Result of an SQL query as a Column name of another query

    Hi Friends,
    Can we use a result of a SQL Query as a column name of another table to retrieve data. If so please help me.
    For eg :
    I have a table where is store numbers;
    select col1 from table1 where col1='5';
    and i have another table where .. this value of col is a column name..
    select ( select col1 from table1 where col1='5') from table2;
    Thanks in advance.

    Hi,
    ORAFLEX wrote:
    Hi Friends,
    Can we use a result of a SQL Query as a column name of another table to retrieve data. If so please help me.
    For eg :
    I have a table where is store numbers;
    select col1 from table1 where col1='5';
    and i have another table where .. this value of col is a column name..
    select ( select col1 from table1 where col1='5') from table2;
    Thanks in advance.Do you really mean that?
    select col1 from table1 where col1='5';That query will always return either '5' or nothing. Whatever you're trying to accomplish with that, you can do with an EXISTS query.
    Perhaps you meant to reference two different columns in that query:
    select col1 from table1 where col2='5';In that case, sorry, no, you can't do that without resorting to dynamic SQL.
    If the same column is used throughout the query (but could change every time you run the query), then the dynamic SQL might be pretty easy. In SQL*Plus, for example, you could use substitution variables, defined in another query at run-time.
    If there are only a few possible values that the sub-query could possibly return, and you know what they all are, then you can fake a dynamic query like this:
    SELECT     CASE     ( SELECT  col1
                FROM       table1
                WHERE       col2     = '5'
              WHEN  'BONUS'     THEN  bonus
              WHEN  'COMM'     THEN  comm
              WHEN  'SAL'     THEN  sal
         END     AS col1
    FROM     table2
    ;Sorry to give such a vague answer, but it's the best I can do with the information I have.
    It would help if you posted a little sample data (CREATE TABLE and INSERT statments for both tables), and the results you want to get from that data. If you want to pass a parameter to the query, give the results you want for a couple of different parameters.

  • How to make dynamic query using DBMS_SQL variable column names

    First of all i will show a working example of what i intend to do with "EXECUTE IMMEDIATE":
    (EXECUTE IMMEDIATE has 32654 Bytes limit, which isn't enough for me so i'm exploring other methods such as DBMS_SQL)
    -------------------------------------------------CODE-----------------------------------
    create or replace PROCEDURE get_dinamic_query_content
    (query_sql IN VARCHAR2, --any valid sql query ('SELECT name, age FROM table') 
    list_fields IN VARCHAR2) --list of the columns name belonging to the query (  arr_list(1):='name';   arr_list(2):='age';
    -- FOR k IN 1..arr_list.count LOOP
    -- list_fields := list_fields || '||content.'||arr_list(k)||'||'||'''~cs~'''; )
    AS
    sql_stmt varchar (30000);
    BEGIN
                   sql_stmt :=
    'DECLARE
         counter NUMBER:=0;     
    auxcontent VARCHAR2(30000);     
         CURSOR content_cursor IS '|| query_sql ||';
         content content_cursor%rowtype;     
         Begin
              open content_cursor;
              loop
                   fetch content_cursor into content;
                   exit when content_cursor%notfound;
                   begin                              
                        auxcontent := auxcontent || '||list_fields||';                    
                   end;
                   counter:=counter+1;     
              end loop;
              close content_cursor;
              htp.prn(auxcontent);
         END;';
    EXECUTE IMMEDIATE sql_stmt;
    END;
    -------------------------------------------------CODE-----------------------------------
    I'm attepting to use DBMS_SQL to perform similar instructions.
    Is it possible?

    Hi Pedro
    You need to use DBMS_SQL here because you don't know how many columns your query is going to have before runtime. There are functions in DBMS_SQL to get information about the columns in your query - all this does is get the name.
    SQL> CREATE OR REPLACE PROCEDURE get_query_cols(query_in IN VARCHAR2) AS
    2 cur PLS_INTEGER;
    3 numcols NUMBER;
    4 col_desc_table dbms_sql.desc_tab;
    5 BEGIN
    6 cur := dbms_sql.open_cursor;
    7 dbms_sql.parse(cur
    8 ,query_in
    9 ,dbms_sql.native);
    10 dbms_sql.describe_columns(cur
    11 ,numcols
    12 ,col_desc_table);
    13 FOR ix IN col_desc_table.FIRST .. col_desc_table.LAST LOOP
    14 dbms_output.put_line('Column ' || ix || ' is ' ||
    15 col_desc_table(ix).col_name);
    16 END LOOP;
    17 dbms_sql.close_cursor(cur);
    18 END;
    19 /
    Procedure created.
    SQL> exec get_query_cols('SELECT * FROM DUAL');
    Column 1 is DUMMY
    PL/SQL procedure successfully completed.
    SQL> exec get_query_cols('SELECT table_name, num_rows FROM user_tables');
    Column 1 is TABLE_NAME
    Column 2 is NUM_ROWS
    PL/SQL procedure successfully completed.
    SQL> exec get_query_cols('SELECT column_name, data_type, low_value, high_value FROM user_tab_cols');
    Column 1 is COLUMN_NAME
    Column 2 is DATA_TYPE
    Column 3 is LOW_VALUE
    Column 4 is HIGH_VALUE
    PL/SQL procedure successfully completed.I've just written this as a procedure that prints out the column names using dbms_output - I guess you're going to do something different with the result - maybe returning a collection, which you'll then parse through in Apex and print the output on the screen - this is just to illustrate the use of dbms_sql.
    best regards
    Andrew
    UK

  • Variable column name in a trigger

    I have a table with many columns, and would like to make a log table of all the updates in the first one. So my idea was to bulid a "before update" trigger which would first create a cursor to get the column names from the user_tab_columns table. In a cursor loop it would check if the :new.column_data is somehow different from :old.column_data. If this was the case, trigger would build a sql statement for inserting old and new values into the log table, and then execute this statement using the "execute immediate".
    Here i run into a problem, because i shuld pass the old and new values of a column instead of :new and :old variables, which are not bound in the execute immediate. Any suggestion besides writing a long trigger for checking each and every column name in a table?

    Or don't create it like this at all.
    This way you'll get:
    - complex trigger code
    - a hard parse each and every insert into that log table
    - a trashed shared pool, because it gets populated with all "almost the same" insert statements
    Querying a log table probably is not something you do everyday, so it likely doesn't pay to store it in a complex way to make sure the retrieval goes smoothly.
    If you want to log, you could do it in a single insert statement with all the information you could possibly need. This makes the code easy and the SQL sharable. It could look like below, and just skip the columns you don't need:
    insert into log_table
    ( action
    , action_date
    , action_user
    , column1_old_value
    , column1_new_value
    , did_column1_change
    , column2_old_value
    , column2_new_value
    , did_column2_change
    , columnN_old_value
    , columnN_new_value
    , did_columnN_change
    values
    ( case when inserting then 'I' when updating then 'U' when deleting then 'D' end
    , sysdate
    , user
    , :old.column1
    , :new.column1
    , case when updating('column1') then 'Y' else 'N' end
    , :old.column2
    , :new.column2
    , case when updating('column1') then 'Y' else 'N' end
    , :old.columnN
    , :new.columnN
    , case when updating('columnN') then 'Y' else 'N' end
    );Or you can use a flashback archive instead of a log table in 11g, but I don't have enough experience with it yet to fully recommend that one.
    Regards,
    Rob.

  • Order query depending on column names passed at runtime

    Hi
    Can any one suggest how to order by at run time depending on column name passed as parameter.
    create or replace procedure dummy_proc( p_orderby varchar2,p_refcursor out sys_refcursor)
    is
    begin
         open p_refcursor for select * from
         emp where Status='A'
              order by (select p_orderby from dual);
    end;
    --execution part for testing
    declare
         v_outcursor sys_refcursor;
         v_rec_data emp%rowtype;
         v_cnt number;
    begin
         dummy_proc ('ename,sal',v_outcursor);
         begin
              loop
                   fetch v_outcursor into v_rec_data;
                   v_cnt:=v_outcursor%rowcount;
                   exit when v_outcursor%notfound;
                   dbms_output.put_line('empno '|| to_char(v_rec_data.empno));
                   dbms_output.put_line('empno '|| v_rec_data.ename);
              end loop;
         end;
         dbms_output.put_line('Count is'|| to_char(v_cnt));
    end;
    we do not want to something like below as my actual query is very big with union statements and case expressions, (below is just an similar example)
    how i tried to order by but its not working.
    v_sql='select * from emp where empno= '|| p_empno || ' order by '|| p_orderby;
    open p_refcursor for v_sql;
    Thanks in advance
    Vishal

    we do not want to something like below as my actual
    query is very big with union statements and case
    expressions, (below is just an similar example)
    how i tried to order by but its not working.
    v_sql='select * from emp where empno= '|| p_empno ||
    ' order by '|| p_orderby;
    open p_refcursor for v_sql;I agree, you really don't want to do that, you want to use BIND VARIABLES.
    v_sql := ' select * from emp where empno = :bound_empno order by :bound_orderby';
    open p_refcursor for v_sql using p_empno, p_orderby;
    [pre]
    The size of the statement shouldn't come in to play, if the only dynamic portion of it is the order by clause then declare a constant which is the large query (you can use a LONG datatype) and then concatenate in the order by clause before you return the reference cursor.
    Unless you can give a legitimate reason for why you cannot use Dynamic SQL (not why you do not want to use it) this would be my approach.
    And please, if you don't know what a bind variable is...read about them, or your system will suffer.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Variable column names

    I'm working on a data collection application. Actual device names to be logged can change. Two tables are used: a log "header" table that contains an entry with input descriptions (one record per "run") and another table that contains logged data every 10 secondss
    Log header table:
    DT | run_num | input1_desc | input2_desc |
    xxxx 1234 inlet_temp zone_1_temp
    Data table:
    DT | run_num | input1 | input2 |
    xxxx 1234 12.234 45.675
    How can I create a view to show data with actual column names (ex: inlet_temp)? Or should db be re-designed?

    Are you using an application express report to display the results?
    If so, you could use the custom pl/sql headings for that purpose.
    This example could get you started:
    DECLARE
       l_ret   VARCHAR2 (500);
    BEGIN
       SELECT 'DT:RUN_NUM:' || input1_desc || ':' || input2_desc
         INTO l_ret
         FROM logheader
        WHERE run_num = :p1_run_num;
       RETURN l_ret;
    END;These custom headings only make sense for a single run_num.
    So create a report for the details :
    select * from data where run_num = :p1_run_num; and use the above mentioned pl/sql block on the report attributes tab for a heading type of pl/sql.
    The variable :p1_run_num refers to a variable on page 1 on which you set the current run_num value for the details.
    Regards,
    ~Dietmar.

  • How to get the alias name of an attribute of a VO from its column name?

    How can I programmatically get the alias name of an attribute of a VO given its column name?
    Often alias and column names are not same when the VO is created (and I don't require them to be the same)

    Hello John.
    I will be more precise. When the VO based on a table comes out from the wizard, it produces xml entries like the following one:
      <ViewAttribute
        Name="ColumnName"
        AliasName="COLUMN_NAME"/>There the column of the table on the DB really is COLUMN_NAME. The wizard mangles that name producing ColumnName as Name property.
    This is ok. I don't want to change this default behaviour.
    What I need is to programmatically get the value of that attribute given its AliasName property value:
    String f(ViewObject vo, String AliasName) {
    return (String)vo.getCurrentRow().getAttributeFromAliasName(aliasName); // getAttributeFromAliasName does not exist
    // instead of return (String)vo.getCurrentRow().getAttribute(Name);
    That is, usually getAttribute expects what in the xml is the Name property. However, I want a sort of getAttribute() expecting the AliasName.
    I hope it's clear.

  • Create App From Spreadsheet: "column name is an Oracle reserved word"

    I'm creating an App from a spreadsheet on apex.oracle.com (3.0.0.00.20 at time of writing) and receiving the error "The identified column name is an Oracle reserved word. Please choose another name."
    I've tried adding an underscore to the end of each column name in order to avoid having to check every column name (yup, lazy) but that didn't remove the error, nor is any column name identified by the interface.
    Thoughts?

    Hi David,
    There was a bug at one time where reserved words were not being checked properly when creating columns. A particular problem related to names beginning with "SYS".
    Try adding the underscore in front of the column name.
    Regards
    Andy

  • Query to return column name of first NULL column?

    I have a table with 40 columns but only the first n have non-null values. Is there a way to pull the name of the first non-null column? I have tried using CASE but I run into nesting too deeply problems (apparently you can only nest to 10 levels).
    Thank you.
    Kevin
    Kevin Burton

    Or, you could try something like this:
    -- This is just for testing
    DROP TABLE #test
    CREATE TABLE #Test
    (ID INTEGER
    ,n1 INTEGER
    ,n2 INTEGER
    ,n3 INTEGER
    ,n4 INTEGER
    ,n5 INTEGER
    ,n6 INTEGER
    ,n7 INTEGER
    ,n8 INTEGER
    ,n9 INTEGER
    INSERT INTO #Test
    VALUES (1,256,365,4000,0,NULL,NULL,NULL,NULL,NULL)
    SELECT *
    FROM #Test
    -- THIS IS THE IMPORTANT PIECE
    SELECT  ISNULL(LEN(LEFT(n1,1)),0)
    + ISNULL(LEN(LEFT(n2,1)),0)
    + ISNULL(LEN(LEFT(n3,1)),0)
    + ISNULL(LEN(LEFT(n4,1)),0)
    + ISNULL(LEN(LEFT(n5,1)),0)
    + ISNULL(LEN(LEFT(n6,1)),0)
    + ISNULL(LEN(LEFT(n7,1)),0)
    + ISNULL(LEN(LEFT(n8,1)),0)
    + ISNULL(LEN(LEFT(n9,1)),0)
    FROM #Test
    The LEFT(x,1) will always either give you a LEN of 1, or a NULL. Add 'em up. Try it.
    Then use the Ordinal_Position from the Information Schema to get the name of the column (if that is what you need)
    Duncan Davenport

  • Unpivot taking the last letter from the column name

    Hi guys, having
    DATE               Period1 Period2 Period3 Period4
    01/01/2014       1.02       1.06      1.02      1.03
    02/01/2014       1.06       1.05      1.04      1.06
    I would like an unptivot as
    01/01/2014    1        1.02
    01/01/2014    2        1.06
    01/01/2014    3        1.02
    01/01/2014    4        1.03
    02/01/2014    1        1.06
    02/01/2014    2        1.05
    02/01/2014    3        1.04
    02/01/2014    4        1.06
    But I'm wondering how can I take the last letter of the column. Maybe I should use a select case...
    Any advices? Thank you   

    DECLARE @Table TABLE
    dt DATE,
    P1 INT NULL,
    P2 INT NULL,
    P3 INT NULL,
    P4 INt NULL
    INSERT INTO @Table(dt, P1, P2, P3, P4)
    VALUES('20140101',10,null,20,3);
    INSERT INTO @Table(dt, P1, P2, P3, P4)
    VALUES('20140102',50,25,15,5);
    SELECT dt, row_number() over (partition by dt order by dt) rn,per AS DayMax FROM @Table
    UNPIVOT (per FOR DayNumber IN (P1, P2, P3, P4)) AS c
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Data load from variable file names

    I have multiple files that I want to load into a cube, each starting with the same 5 characters but ending differently. EG GM1010104 GM1010204 What's the best option for MAXL script to automate this data load ? Can you use a wildcard name in the script to pick up anything starting with GM101**** ?

    No - you need to specify the file name as it appears properly (I've never tried it but I am pretty sure it wouldn't work). One solution to this problem though is to have a shell script (or DOS commands) auto-generate an ESSCMD/MaxL script based on the files that exist in a directory.Most scripting environments should allow you to loop through a list of files that match some pattern - you can then create a script with the results and execute it.Another option is to build a MaxL script that accepts a parameter (file name) and have a shell script call it as it loops through the file list.Hope that helps.Regards,Jade----------------------------------Jade ColeSenior BI ConsultantClarity [email protected]

  • Passing column names in as a variable

    I know in SQL server there is a way you can pass a variable in to the procedure and put that variable as a column name, Oracle doesn't seem to pick the variable up as a column name. Can anyone show me how with a simple select statement

    bgulcu wrote:
    I'm having a similar problem. I didn't want to open up another thread since it's related.
    Problem:
    I have 107 columns on a table. The number of columns increases almost every month.
    I have an array of columns, which I have gathered from the db. I need to pivot the whole table, but due to indefinite number of columns, it had to be dynamic sql.
    Premature Solution:
    Right now, the solution that we have runs through the array of columns and uses dynamic sql to query for every single cell to get the value. Considering that we have 1000+ rows on this table, in order to do the transformation, we send 107000+ queries which is just ugly. It works, but I don't feel comfortable about it.
    Solution:
    Since we are able to get a single row of 107 columns, why don't we gather the whole row, and get the information out from it instead of tiring up the server? The indefinite number of columns is a problem, but we have the whole list in an array, lets say feature_array. So what I want to do is to get the date from the row, ie myRow.feature_array(1), myRow.feature_array(2), ..., myRow.feature_array(i).
    I just learned that it's not possible to do it (from this thread).You just misunderstood the contents of this thread. What we said is that you can't do such things with static SQL, so you need to use dynamic sql.
    What has also been told was that using dynamic sql for such a purpose is just the result of a bad design. Use a relational table as a bi-dimensional array is not right, it is possible but it's not right for the simple reason that you need a procedural language to process the dynamic SQL that is needed to retrieve data.
    Probably on database programming there's only a rule of thumb and it says: "Maximize SQL minimize PL/SQL" (or any procedural language like java). The only exceptions to keep code in procedural language must depend on a complexity reduction determined by its use. In your case there is no complexity reduction determined by the use of a procedural language.
    In the thread on this link(Schema integrity I discussed about how to implement a solution you can use as alternative for submitting queries with variable column names.
    If you introduce parameter management in your model probably you could have your problem solved with the use of only a single SQL statement. And that may be a good designed model.
    Bye Alessandro

  • Querying MSAccess with # in column name

    What is the proper syntax for a JDBC sql statement to query a MSAccess database with "#' (the pound or number sign) in a column name?
    Thanks.
    -John

    Thanks all for the speedy replies. This forum should be extremely helpful in the future.
    The double quotes did the job. I thought I had tried using quotes, but I must have used single quotes instead.
    I do not have a say in the database design, and therefore, am stuck using whatever is thrown at me. Otherwise, I agree that staying away from using column names that may not conform to accepted standards is a good idea.
    Thanks again.
    -John

  • Using variable coulmn name in sql function

    Hi there,
    I am not an expert with PL/SQL and I can not figure out how to use variable column names in my function.
    My function is:
    CREATE OR REPLACE FUNCTION RESET_TRIGGERS(aTrigger VARCHAR2) RETURN NUMBER IS
    TEMP_ID NUMBER;
    TEMP_USER_ID NUMBER;
    BEGIN
    SELECT 'LIMS.'||'$aTrigger'||'.NEXTVAL' INTO TEMP_ID FROM DUAL;
    SELECT 'LIMS.'||'$aTrigger'||'_USER.NEXTVAL' INTO TEMP_USER_ID FROM DUAL;
    IF TEMP_ID > TEMP_USER_ID THEN
    LOOP
    SELECT LIMS.SQ_U_FINALRESULT_USER.NEXTVAL INTO TEMP_USER_ID FROM DUAL;
    EXIT WHEN TEMP_USER_ID = TEMP_ID;
    END LOOP;
    ELSE
    WHILE TEMP_ID < TEMP_USER_ID LOOP
    SELECT LIMS.SQ_U_FINALRESULT.NEXTVAL INTO TEMP_ID FROM DUAL;
    END LOOP;
    END IF;
    COMMIT;
    RETURN (TEMP_ID);
    END;
    What I want is that I pass a seqencename with aTrigger and that two triggers will be equal if not.
    eg ifaTrigger = 'SQ_U_FINALRESULT'
    than I want the triggers LIMS.SQ_U_FINALRESULT and LIMS.SQ_U_FINALRESULT_USER to be set equal.
    The above function will not work, but what will?????
    I hope you can help me out!
    Cheers

    A very strange function indeed.
    But here is what I think he meant to do:
    SQL> create procedure reset_sequences
      2  ( p_sequence_name in  varchar2
      3  , p_nextval          out number
      4  )
      5  is
      6    l_nextval1 number;
      7    l_nextval2 number
      8    ;
      9    procedure reset_sequence_value
    10    ( p_sequence_name in varchar2
    11    , p_current_value in number
    12    , p_new_value     in number
    13    )
    14    is
    15      l_dummy number;
    16    begin
    17      execute immediate 'alter sequence ' || p_sequence_name || ' increment by ' || to_char(p_new_value-p_current_value);
    18      execute immediate 'select ' || p_sequence_name || '.nextval from dual' into l_dummy;
    19      execute immediate 'alter sequence ' || p_sequence_name || ' increment by 1';
    20    end reset_sequence_value
    21    ;
    22  begin
    23    execute immediate
    24      'select ' || p_sequence_name || '.nextval,' || p_sequence_name || '_user.nextval from dual'
    25    into l_nextval1, l_nextval2
    26    ;
    27    if l_nextval1 < l_nextval2
    28    then
    29      reset_sequence_value(p_sequence_name,l_nextval1,l_nextval2);
    30    end if
    31    ;
    32    if l_nextval1 > l_nextval2
    33    then
    34      reset_sequence_value(p_sequence_name || '_user',l_nextval2,l_nextval1);
    35    end if
    36    ;
    37    p_nextval := greatest(l_nextval1,l_nextval2)
    38    ;
    39  end reset_sequences;
    40  /
    Procedure is aangemaakt.
    SQL> show err
    Er zijn geen fouten.
    SQL> create sequence testseq start with 5 increment by 1
      2  /
    Reeks is aangemaakt.
    SQL> create sequence testseq_user start with 2 increment by 1
      2  /
    Reeks is aangemaakt.
    SQL> declare
      2    l_new_value number;
      3  begin
      4    reset_sequences('testseq',l_new_value);
      5    dbms_output.put_line(l_new_value);
      6  end;
      7  /
    5
    PL/SQL-procedure is geslaagd.
    SQL> select testseq.currval from dual
      2  /
                                   CURRVAL
                                         5
    1 rij is geselecteerd.
    SQL> select testseq_user.currval from dual
      2  /
                                   CURRVAL
                                         5
    1 rij is geselecteerd.Regards,
    Rob.

  • Invalid Column Name message in the subquery

    Hi All, I am receiving the invalid column name message in the subquery. Please help me if there is any work around or change in the query:
    Sample query:
    update table1 set table1.column1 =
    (Select column1 from
    (Select column1 from table2 where
    table1.columnX = table2.columnX
    order by table2.columnM desc,table2.ColumnN desc,
    where rownum =1)
    When i run the above query i am receiving the following error message:
    ORA-00904:invalid column name at table1.columnx.
    This column is already existing in table1 and looks like this table is not recoginzed inside of the subquery.
    I am trying to update table1.column1 using the first value from table2 after ordering by table2.columnM desc, table2.columnN desc. (ColumnM and ColumnN are the Date columns which i need to perform the sorting). I am new to sql/Plsql. Thanks in Advance for help....

    The problem is that you can not refer to columns from the outer table from inside a second subquery inside your subquery. Only one level of subquery can be used to transport the column name,.
    A solution can be to use groups and aggregation functions instead of rownum = 1.
    The following might work.
    untested
    update table1
    set table1.column1 =
      (Select max(column1) keep (dense_rank first over table2.columnM desc,table2.ColumnN desc)
       from table2
       where table1.columnX = table2.columnX
       ) Another way can be to to make a UNCORRELATED subquery first and then filter on that uncorrelated query with the column name from the outer statement.
    This time I use a analytic function.
    untested
    update table1 u
    set u.column1 = (select v1.column1
       from
         (Select t2.column1, t2.columnX, row_number over (partition by t2.column1, t2.columnX order by t2.columnM desc,t2.ColumnN desc) as rn
          from table2
          ) v1
       where v1.columnX = u.columnX
       and v1.rn = 1
    where /* where clause is missing! */

Maybe you are looking for

  • Profiling the loading and unloading of modules

    Modules appear to be the ideal solution for building complex rich internet applications but first hand experience has also shown me that they can leak memory like nothing else. I've read anything and everything I could find about modules and module l

  • Why is email disappearing from my inbox in Apple mail?

    I will open an email, read it then close Mail, or not.  Either way, when I go back to Apple Mail to re-read the message it is gone.  I've lost an extremely important message.  I've searched Junk and trash, all of my accounts and the message is gone. 

  • Dynamic add tree node and thread

    Hi, I implemented a thread by using SwingWorker class to execute the time-consuming file loading and processing task instead of the event-dispatching thread. However, I need to dynamically add node to a tree by using data returned by the file loader

  • How to launch Photoshop CS5 in either 32 bit or 64 bit mode

    Some of my plugins - (notibly Nik Viveza & Silver Effects Pro) only run in 32bit mode at present.   I would rather work in 64bit (I think - hard to tell if I'm getting any real benefit - will have to try some benchmarks)  I work with large files 100m

  • License stopped working. Error 150:30.

    Re-install of Mountain Lion from Time Machine (BIG mistake) left me with PhotoShop and InDesign CS4 unusable. "License stopped working and Error 150:30" were the messages. Went online, tried what worked for some people, i.e. deleting Flexnet from ~Li