Having a column name as a variable in a query, problem!

I have a problem with a simple query below


SELECT * FROM DisneyWHERE Upper (COLNAME) AS SUPERIOR ('%' |) SEARCHSTRING. '%'); SELECT * FROM Disney
WHERE Upper (COLNAME) AS SUPERIOR ('%' |) SEARCHSTRING. '%');

My problem, the variable of column name is not recognized as a column for example name
A user can select to display a set of characters from the database by user name, movies, etc (they selecting this function since a combobox), they then enter a search string (textbox)
column name = user name
SearchString = pluto

SELECT * FROM Disney
WHERE Upper (COLNAME) AS SUPERIOR ('%' |) SEARCHSTRING. '%');

The problem is orac; e does not seem to be picking up this column name is a column name and seems to be a simple comparison. To make this more clear

It "seems to match the username = pluto
instead of find pluto in the username column.

Someone at - it ideas how I can get around this. I have a strange feeling, it's something to do with pl/sql dynamic, but I am new to oracle, so I have no idea of how to write dynamic queries. Any help would be appreciated muchly

I'm using oracle 11g and visual studio .net 2005

user10372910 wrote:
But it wouldn't just look for each column I'm sorry if I seem stupid that I have only just introduced to oracle and I used to use sql

Sort of Yes and no.

If colname is 'film' and the search string 'star wars' is the place where actually takes the clause...

WHERE username as username
AND the movie like 'star wars % % '.

If username is not limited in any way and it limits just on film.

Conversely if the column name is "username" and the search string is 'Bob Smith' then where clause evaluates actually to...

WHERE username like ' %% of Bob Smith.
AND the film as film

then move is not limited in any way and simply limits on the user name.

Tags: Database

Similar Questions

  • Anyway, to remove the column names in the result of the query of SQLPLUS

    Hello

    I am using sqlplus to run a script that returns results with the column names.

    Anyway is to omit the names of columns in the result of the sqlplus query?

    I would like to have only results with their column names in the output.

    Thanks in advance!

    Hello

    Maybe your LINES (IZE) is not defined?

    SCOTT>set lines 130
    SCOTT>select status, machine, module
      2    from v$session
      3   where upper(username) = 'SCOTT';
    
    STATUS   MACHINE                                                          MODULE
    -------- ---------------------------------------------------------------- ------------------------------------------------
    INACTIVE PFAE3\VPC4894-03                                                 TOAD 9.7.2.5
    ACTIVE   PFAE3\VPC4894-03                                                 SQL*Plus
    
    2 rows selected.
    
    SCOTT>
    

    As an alternative to the linesize parameter, you can format the columns:

    SCOTT>set lines 80
    SCOTT>col status for a8
    SCOTT>col machine for a30
    SCOTT>col module for a30
    SCOTT>select status, machine, module
      2    from v$session
      3   where upper(username) = 'SCOTT';
    
    STATUS   MACHINE                        MODULE
    -------- ------------------------------ ------------------------------
    INACTIVE PFAE3\VPC4894-03               TOAD 9.7.2.5
    ACTIVE   PFAE3\VPC4894-03               SQL*Plus
    
    2 rows selected.
    
    SCOTT>
    

    Concerning
    Peter

  • How to make reference to a column name in the form report

    Hello
    How can I make reference to a column name in the form report. My problem is that "I have a form report that I have the column name when using click on the column name, it must get to the next page with the corresponding values of the column".

    Here, I realized that when I click on the name of the column (in page 1) it brings me to the next page (page 2). but in the next page (P2) I want to display (display only) the corresponding values of the column (page 1) selected, but the values are not editable and shouldn't be in the text box must be in display area.

    So, how can I write a SQL to display single source field. That is to say, how can I consult report form (page 1) in name column.

    Hello

    If you use the link in the column when you click on the need of the column value, you need to navigate to the next page and all the data accordingly select value here.

    Modify the report form and see the top of the page and click on report attribute.

    So now you have the attributes of the columns is to say what are the columns are available in the reports form.

    Click on change column what you need Ie the column when you click on its passage to the next page this column, for example, as mentioned in the previous post "Empname".

    Check the link column and give perspective of values according to your need and click on apply chages.

    Thank you & best regards
    Srikkanth.M

  • The use of bind variables in dynamic query created for Ref Cursor

    Hello

    I'm in a situation where there is a Ref cursor to which the query is built execution based on a loop. This is why the number of links would be known until the program runs.
    The application is currently using literals instead of bind variables.

    code snippet of the above is
    strSql: = "select * from emp where 1 = 1 and ().

    loop cursor1
    If cond is true then
    strSql = strSql | "ename = ' |" Cursor1.ColumnName;
    end loop;

    Open cursor2 for strSql;

    How to use links in the example above.

    sb92075 wrote:

    user13019948 wrote:
    Hello

    Here is the code I have my trying to change literal-based link to the base.

    What do you mean by "based bind?

    who, what, how determines the values to be 'bound '?

    He's referring to the coding style. He is currently using concatenated literal, and the goal is to change it to use the bindings.

    If I understand this it is known as method 4 dynamic SQL and requires DBMS_SQL. There are examples autour but they vary according to the type of statement being generated - SELECT statements require column lists to be parsed, unlike the INSERT/UPDATE/DELETE.

    This came up recently on my current project and I hit a demo. Here a table of names and values accepted procedure and had to build these in a single WHERE clause along the lines of

    AND t_names(i) = t_values(i)
    

    for an undetermined number of elements in the array. For this demonstration, I used a table that we called "attribute" (don't ask) which has columns including 'attribute_id' and 'name', and I need to build a query along the lines of

    select description from attribute where attribute_id = :b1 and name = :b2
    

    by the way '1012' and 'ISIN' respectively. (I use a table better and after a CREATE statement for her but I have to rush right now, sorry).

    declare
       k_sql_base        constant varchar2(500) := 'select description from attribute';
    
       t_names           constant varchar2_t := varchar2_t('attribute_id',  'name');
       t_values          constant varchar2_t := varchar2_t('1012',          'ISIN');
    
       l_sql             varchar2(500) := k_sql_base;
       l_rows_fetched    integer := 0;
       l_value           varchar2(4000);
    
       l_cursor_handle   integer;
    
    begin
       -- Construct the SQL statement with column names and bind variables e.g.
       -- 'select description from mars.attribute where attribute_id = :b1 and name = :b2'
       for i in t_names.first .. t_names.last loop
          l_sql := l_sql ||
             case i
                when t_names.first then ' where ' else ' and '
             end ||
             t_names(i) || ' = :b' || i;
       end loop;
    
       dbms_output.put_line('SQL statment = ' || l_sql); 
    
       -- Parse the statement we built above (the remaining steps require a parsed cursor):
       l_cursor_handle := dbms_sql.open_cursor;
       dbms_sql.parse(l_cursor_handle, l_sql, dbms_sql.native);
    
       -- Associate the 1st column of output with variable l_value - required for SELECT statements:
       -- (actually the 3rd param here 'column' seems to be only used to get a datatype, in this case we want a string -
       -- dbms_sql.column_value actually extracts the value into a specified variable, which can be different.
       -- All examples in the documentation pass a local variable without further comment, so not entirely clear what this does other than set the output datatype.)
       dbms_sql.define_column(l_cursor_handle, 1, l_value, 4000);
    
       -- Now go through values array binding actual values to :bn variables in the cursor (similar to USING clause of EXECUTE IMMEDIATE)
       for i in t_values.first .. t_values.last loop
          dbms_sql.bind_variable(l_cursor_handle, ':b'||i, t_values(i));
          dbms_output.put_line('Bound :b'||i || ' as ' || t_values(i));
       end loop;
    
       -- Open the cursor and fetch the result (no loop here because we are expecting a single-row result):
       l_rows_fetched := dbms_sql.execute_and_fetch(l_cursor_handle);
    
       -- 'Returns value of the cursor element for a given position in a cursor'
       -- Copy the value of column 1 to variable l_value (has to match
       -- dbms_sql.column_value(l_cursor_handle, 1, l_value);
       dbms_sql.column_value(l_cursor_handle, 1, l_value);
    
       dbms_output.put_line('Result = ''' || l_value || '''');
    
       dbms_sql.close_cursor(l_cursor_handle);
    end;
    

    Hope that helps...

  • Columns of folder: by default, how can return the first column 'Name' without having to move it manually every time?

    Something's happened awhile and when I create a folder which appears the first column is the column 'Date modified '. By default, how can return the first column 'Name' without having to move it manually every time?

    Hello

    I suggest you to visit these links and check if it helps:

    http://Windows.Microsoft.com/en-us/Windows-Vista/working-with-files-and-folders#section_4

    http://Windows.Microsoft.com/en-us/Windows-Vista/folders-frequently-asked-questions

    It will be useful.

  • name of the variable column for a source

    Can I have a column name variable for a text box, such as this one source

    Select (: P2_column_name) of the budget where id =: P2_id;

    I get the: P2_column_name variable and not really the content of the column.
    what I am doing wrong, thank you, Doug

    Only works for reports. It sounded like you want to select in a correct form, update the value and then present at the table element?

    Thank you

    Tony Miller
    Webster, TX

    I cried because I don't have an office with a door until I met a man who had no cubicle.
    -Dilbert

    If you answer this question, please mark the thread as closed and give points where won...

  • retrieve the value column access via the variable name of the column

    I need to build a function of validation with this condition:

    The data model is like this:

    We have an array of items_general, with its id and data.

    Then we have specific tables, let's say... item_especific1, item_especific2 item_especificn. They have the same as the table of the item_general pk and fk against item_general

    Each element is in one of the tables item_specific and items_general.


    Now, the validation feature: I need to check for an element, if some special columns of the item_especificx table are null and will raise an error if this occurs.

    I got the name of especific_table and the list of names of particular column stored in another table.


    I guess I can browse this list of column table to build a clause concatening Dynamics 'and' | column_name | 'is nothing', but I'm not a big fan of the dynamic sql.


    Can you think of a better solution? Any way to access the value of the column by using the column name, as if it were a varchar2 key index?




    Nope, no filter.

    When you have a funky data like that model, you're destined to dynamic sql and other assortment of headaches.

  • Invalid column name error

    Having an interesting problem with a site I'm fixing. I don't know that I'm looking beyond the obvious, so maybe some of you can help:

    ASP pages display the results of the recordset based on a session variable (Member ID) that is created when the user login.

    Recordset looks like this:

    < %
    Dim rs__MMColParam
    rs__MMColParam = '% '.
    If (Session("memberID") <>"") then
    rs__MMColParam = Session("memberID")
    End If
    % >
    < %
    Set rs = Server.CreateObject ("ADODB. Recordset')
    RS. ActiveConnection = MM_cnConnection_STRING
    RS. Source = "SELECT id, adminusername, anotherone1, anotherone2, anotherone3 FROM dbo.basic1 WHERE adminusername = ' ' + replace (rs__MMColParam,"'"," "") + "'."
    RS. CursorType = 0
    RS. CursorLocation = 2
    RS. LockType = 3
    RS. Open()
    rs_numRows = 0
    % >

    Looks good to me, unles I forget something obvious.

    Unfortunately, I get the following error:

    Microsoft OLE DB provider for ODBC error '80040e14' drivers
    [Microsoft] [ODBC SQL Server driver] [SQL Server] Invalid column name 'SESSIONVAR.

    (Note: this error above, SESSIONVAR is the name of the variable member of session ID)

    Strange thing is, as long as the session variable is a #, everything works. If that's a Word, it won't work. It seems that the session variables are defined and passed to the next page.

    Regarding the database, this is a SQL database
    column 'adminusername' is an NVARCHAR with a limit of 4000 tank

    Thanks in advance for any help.

    Having an interesting problem with a site I'm fixing. I don't know that I'm looking beyond the obvious, so maybe some of you can help:

    ASP pages display the results of the recordset based on a session variable (Member ID) that is created when the user login.

    Recordset looks like this:

    < %="">< br="">Dim rs__MMColParam < br="" >="" rs__mmcolparam="« % »"> < br=""> if (Session("memberID") <> "") then < br=""> rs__MMColParam = Session("memberID") < br=""> End If < br=""> %>
    < %="">< br="" >="" set="" rs="Server.CreateObject" ("adodb.="" recordset »)="">< br="" >="" rs.="" activeconnection="MM_cnConnection_STRING">< br="" >="" rs.="" source="« SELECT" id,="" adminusername,="" anotherone1,="" anotherone2,="" anotherone3="" from="" dbo.basic1="" where="" adminusername=' » + remplacer (rs__MMColParam, "' ",="" "''")="" +="" « '="">< br="">RS. CursorType = 0 < br="" >="" rs.="" cursorlocation="2"> < br="" >="" rs.="" locktype="3"> < br="" >="" rs.="" open()=""> < br=""> rs_numRows = 0< br="" >="" %="">

    Looks good to me, unles I forget something obvious.

    Unfortunately, I get the following error:

    Microsoft OLE DB provider for ODBC error '80040e14' drivers
    [Microsoft] [ODBC SQL Server driver] [SQL Server] Invalid column name 'SESSIONVAR.

    (Note: this error above, SESSIONVAR is the name of the variable member of session ID)

    Strange thing is, as long as the session variable is a #, everything works. If that's a Word, it won't work. It seems that the session variables are defined and passed to the next page.

    Regarding the database, this is a SQL database
    column 'adminusername' is an NVARCHAR with a limit of 4000 tank

    Thanks in advance for any help.

  • Oracle: Nested joins/sub-requetes: odd column names and an unexplained error

    The following query works fine. It is a series of nested joins to give me a kind of main table:

    SELECT *

    FROM proj_trainer k

    JOIN

    (

      SELECT *

      FROM proj_breeder i

      JOIN

      (

      SELECT *

      FROM proj_jockey g

      JOIN

      (

      SELECT *

      FROM proj_horses e

      JOIN

      (

      SELECT *

      FROM proj_results c

      JOIN

      (

      SELECT *

      FROM proj_race_details a

      JOIN proj_meet b

      ON a.meet_id = b.meet_id

      ) d

      ON c.race_id = d.race_id

      ) f

      ON e.horse_id = f.horse_id

      ) h

      ON g.jockey_id = h.jockey_id

      )j

      ON i.breeder_id = j.breeder_id

    ) l

    ON k.trainer_id = l.trainer_id;

    It works very well with a strange feature, that is not my main problem. Some columns are back with weird codes such as "QCSJ_C000000001300001". Don't know why, or if it comes to my real problem.

    The real problem is that when I add just a subquery join more I get:

    ORA-00904: "N"."RACE_ID": invalid identifier

    Here is the same code with the additional nested block (the one on the very outside)

    SELECT *

    FROM proj_entry m

    JOIN

    (

      SELECT *

      FROM proj_trainer k

      JOIN

      (

      SELECT *

      FROM proj_breeder i

      JOIN

      (

      SELECT *

      FROM proj_jockey g

      JOIN

      (

      SELECT *

      FROM proj_horses e

      JOIN

      (

      SELECT *

      FROM proj_results c

      JOIN

      (

      SELECT *

      FROM proj_race_details a

      JOIN proj_meet b

      ON a.meet_id = b.meet_id

      ) d

      ON c.race_id = d.race_id

      ) f

      ON e.horse_id = f.horse_id

      ) h

      ON g.jockey_id = h.jockey_id

      )j

      ON i.breeder_id = j.breeder_id

      ) l

      ON k.trainer_id = l.trainer_id

    ) n

    ON n.race_id = m.race_id AND n.horse_id = m.horse_id;

    I felt as if I was on the hill with it and then the last line was wrong somehow, despite having virtually the same structure as all previous blocks. I also used the race_id and the horse_id above in the code so that they work.

    I also tried this on the last line:

    ON n.race_id = m.race_id AND n.horse_id = m.horse_id;

    and a few other variations, with supports etc...

    Hello

    I can't reproduce the problem, so I can't say with certainty. It might have to do with the same column names which occur in several tables.

    Why do you need nested views online?  Why not simply join all tables directly, like this?

    SELECT *- or display the columns that you really need

    OF proj_race_details one

    JOIN proj_meet b ON b.meet_id = a.meet_id

    JOIN proj_resuls c ON c.race_id = b.race_id - or a.race_id

    ...

    JOIN proj_trainer k WE k.trainer_id = i.trainer_id - or else

    JOIN proj_entry m ON m.race_id = k.race_id - or else

    AND m.horse_id = k.horse_id - or else

    ;

    I guess just the tables that contain columns; for example, I can't tell what you posted if proj_race_details or proj_meet contains race_id.  If I guessed wrong, use the correct table alias.  Are eligible all the column names with the correct alias.

  • display the data in the column as column name

    in this column of query names are hard coded, I need to display the column name dynamically (based on sysdate). Please help me on this?

    with test_emp as

    (select 100 empno, 1st February 2014 ' hiredate, SAL union 1000 double all the)

    Select 200 empno, February 3, 2014 ", 2000 union SAL double all the"

    Select empno 300, 4 February 2014 ", 3000 union SAL double all the"

    Select 400 empno, 5 February 2014 ", 4000 SAL double

    )

    -Select * from test_emp

    SELECT EmpNo,

    Sum (decode (HireDate, trunc (sysdate), SAL, 0)) as '4 February 2014. "

    Sum (decode (HireDate, SAL, trunc(sysdate-1), 0)) as "February 3, 2014.

    Sum (decode (HireDate, trunc (sysdate)-2, SAL, 0)) as 'February 2, 2014.

    Sum (decode (HireDate, trunc (sysdate)-3, SAL, 0)) as 'February 1st, 2014. "

    Sum (decode (HireDate, trunc (sysdate)-4, SAL, 0)) as 'January 31, 2014.

    OF test_emp

    Group by empno stopped by 1

    expected results:

    EMPNO February 4, 2014 3 February 2014 2 February 2014 February 1, 2014 January 31, 2014

    100                     0                    0                       0                   1000               0

    200                     0                   2000                    0                   0                   0

    300                 3000                    0                       0                   0                   0

    400                     0                       0                       0                 0                    0

    Hello..

    We cannot manage dynamic crossover into a sql. So what I did just create a function with refcursor and get results. It will work for your case only. Try the code below and let me know in case of any problems

    FUNCTION to CREATE or REPLACE dyn_row_colum

    RETURN SYS_REFCURSOR

    AS

    v_sqlstr VARCHAR2 (32767): = ' SELECT empno, SUM (DECODE (hiredate,'|)) '''|| Trunc (sysdate) | " ((' |', sal, 0))' | ' '||'"'|| TRUNC (SYSDATE) |' » ' || «, » ;

    v_rfcur SYS_REFCURSOR;

    BEGIN

    FOR j_rec IN (SELECT col_val FROM test_emp TRUNC(SYSDATE-ROWNUM))

    LOOP

    v_sqlstr: = v_sqlstr | » '||' SUM (DECODE (hiredate,'|)) '''|| j_rec.col_val | " ((' |', sal, 0))' | ' '||'"'|| j_rec.col_val |'"' | ',';"

    END LOOP;

    v_sqlstr: = RTRIM (v_sqlstr, ','). » '||' OF test_emp GROUP BY empno';

    V_rfcur OPEN FOR v_sqlstr;

    RETURN v_rfcur;

    EXCEPTION

    WHILE OTHERS THEN

    LIFT;

    END dyn_row_colum;

    VARIABLE v_cur REFCURSOR

    EXEC: v_cur: = dyn_row_colum;

    PRINT v_cur;

    SELECT dyn_row_colum FROM dual;

    Unit tests: -.

    ----------------

    Scott@ORCL > dyn_row_colum FUNCTION to CREATE or REPLACE

    2 SYS_REFCURSOR RETURN

    3 AS

    4 v_sqlstr VARCHAR2 (32767): = ' SELECT empno, SUM (DECODE (hiredate,'|)) '''|| Trunc (sysdate) | " ((' |', sal, 0))' | ' '||'"'|| TRUNC (SYSDATE) |' » ' || «, » ;

    5 v_rfcur SYS_REFCURSOR;

    6 BEGIN

    7 FOR j_rec IN (SELECT col_val FROM test_emp TRUNC(SYSDATE-ROWNUM))

    8 LOOP

    9 v_sqlstr: = v_sqlstr | » '||' SUM (DECODE (hiredate,'|)) '''|| j_rec.col_val | " ((' |', sal, 0))' | ' '||'"'|| j_rec.col_val |'"' | ',';"

    10 END OF LOOP;

    11 v_sqlstr: = RTRIM (v_sqlstr, ','). » '||' OF test_emp GROUP BY empno';

    12 v_rfcur OPEN FOR v_sqlstr;

    13 RETURN v_rfcur;

    14 EXCEPTION

    15 SO THAT OTHERS THEN

    16 RAISE;

    17 END dyn_row_colum;

    18.

    The function is created.

    Scott@ORCL > v_cur VARIABLE REFCURSOR

    Scott@ORCL > EXEC: v_cur: = dyn_row_colum;

    PL/SQL procedure successfully completed.

    Scott@ORCL > v_cur PRINT;

    EMPNO 5 FEBRUARY 14 FEBRUARY 4, 14 3 FEBRUARY 14 FEBRUARY 2 14 1 FEBRUARY 14

    ---------- ---------- ---------- ---------- ---------- ----------

    100          0          0          0          0       1000

    400       4000          0          0          0          0

    300          0       3000          0          0          0

    200          0          0       2000          0          0

    Scott@ORCL > dyn_row_colum SELECT FROM dual;

    DYN_ROW_COLUM

    --------------------

    CURSOR STATEMENT: 1

    CURSOR STATEMENT: 1

    EMPNO 5 FEBRUARY 14 FEBRUARY 4, 14 3 FEBRUARY 14 FEBRUARY 2 14 1 FEBRUARY 14

    ---------- ---------- ---------- ---------- ---------- ----------

    100          0          0          0          0       1000

    400       4000          0          0          0          0

    300          0       3000          0          0          0

    200          0          0       2000          0          0

  • Extraction of values based on column names

    Hello

    I have three tables. Table A table contains a column with all column_names in the table b. table B is to have an emp_id and other fields that are stored as values in the column of the TABLE.  I need to get the emp_id and value from the column of table B based on data of Table A. and store it in another table.

    Example:

    Table has -col1

    Emp_name

    Emp_sal

    Emp_dept

    Table B

    Emp_id Emp_name Emp_sal Emp_dept

    1001 ABC 1000 sales

    1002 XYZ 2000 SVC

    TABLE C

    Emp_id Emp_details value

    1001 Emp_name ABC

    1001 Emp_sal 1000

    1001 Emp_dept sales

    1002 Emp_name XYZ

    1002 Emp_sal 2000

    1002 Emp_dept SVC

    Using the list of TABLE A, I have to select each Id and corresponding to the value of TABLE B and even insert in TABLE C. I know that we can use a loop for, but I have trouble choosing the name of column based on the value of the slider. Can anyone help?


    Hello

    Looks like you want to do 2 things rather difficult:

    (1) unpivot data from several columns in the column 1 value

    (2) get the column names for the another table unpivot operator

    Let's start with how you could do just part 1, unpivoting data:

    INSERT INTO table_c (emp_id, emp_details, value)

    WITH all_varchar2 AS

    (

    SELECT emp_id

    emp_name

    TO_CHAR (emp_sal) AS emp_sal

    emp_dept

    --Include all columns, you might need

    OF table_b

    )

    SELECT emp_id, emp_details, value

    Of all_varchar2

    UNPIVOT (value

    FOR emp_details IN

    (emp_name - dynamic

    emp_sal - dynamic

    emp_dept - dynamic

    )

    )

    ;

    Value is a column, everything happens in this column must have the same (or a very similar) data type.  The subquery all_varchar2 converts all columns that you can rotate in VARCHAR2s (if they are not already VARCHAR2s) so that they are ready to rotate.  You might consider doing a permanent display for this.

    Now, instead of hard-Ghoshal the 3 line marked "Dynamics", you seek to table_a.  You will know beforehand what are these columns, and you won't even know there will be the number of columns. You need instructions SQL dynamic to write this part of the INSERT statement for you at run time.

    Here's a way to do it in SQL * more and SQL:

    -The preliminary motion

    COLUMN col_list_col by col_list new_value

    SELECT LISTAGG (col1, ',') within THE GROUP (ORDER BY col1)

    AS col_list_col
    FROM table_a;

    -Main return (dynamic):

    INSERT INTO table_c (emp_id, emp_details, value)
    WITH all_varchar2 AS
    (
    SELECT emp_id
    emp_name
    TO_CHAR (emp_sal) AS emp_sal
    emp_dept
    --Include all columns, you might need
    OF table_b
    )
    SELECT emp_id, emp_details, value
    Of all_varchar2
    UNPIVOT (value
    FOR emp_details IN
    (& col_list
    )
    )
    ;

    Dynamic SQL often works like this.  First, you make a preliminary motion to write the part that is not know before execution.  Then, you run the main statement, which has the integrated preliminary query results.

    If you do this in PL/SQL, you use a string variable ordinary for col_list, instead of a substitution variable.

  • Select the column by using Session variables

    I set a session variable to contain the name of a bound column that is the user. Is it possible to use a session variable to select a column in a database table? If so, how? Does need a statement where clause?

    Something like that? :

    < cfquery name = "rsSelectColumn" datasource = 'Test' >
    SELECT column 1, column 2, column 3 is Variable from Session
    OF tbl_data
    < / cfquery >

    Thank you
    Dave

    I think you want to do this, if the value in the session variable is the actual column name:


    SELECT column 1, column 2, #Session Variable # AS Col3
    OF tbl_data

    in this way, you can call any column stored in the session variable, and it will still be usable from the QUERY as COL3 regardless of which column you used.

    If that's what you want to do - it OF as simple as that.

    :-)

    Sometimes we have to think of things too.

  • Compare column names

    I have two tables with similar columns.
    Is there a way to check if the two tables have column same names regardless of the order of the columns?
    select  column_name
      from  user_tab_columns
      where table_name in ('table1','table2')
      group by column_name
      having count(*) = 1
    /
    

    I will give you a list of all the columns that exist only in one of the tables. If the column names are the same, it will return no data found.

    SY.

  • What's the point of having several columns in the ORDER BY clause?

    DB version: 10 gr 2

    When you use the ORDER BY clause, the lines are always sorted by the first column in the ORDER BY clause. So, what's the point of having several columns in the ORDER BY clause (I always see this in production codes)?

    For the below SQLs' schema SCOTT, result sets are always classified according to the first column ename. When I added use asc and desc of employment, does not change the result set.
    SQL> select * from emp order by ename;
    
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    20
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    20
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
    
    14 rows selected.
    
    SQL> select * from emp order by ename, job;
    
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    20
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    20
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
    
    14 rows selected.
    
    SQL>  select * from emp order by ename, job desc;
    
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    20
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    20
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
    
    14 rows selected.

    Search in this example, you will see the difference

    SQL> create table test_order (name varchar2(10), surname varchar2(10), age number);
    
    Table created.
    
    SQL> insert into test_order values('Kamran','Agayev',26);
    
    1 row created.
    
    SQL> insert into test_order values('Kamran','Taghiyev',26);
    
    1 row created.
    
    SQL> insert into test_order values('John','Kevin',23);
    
    1 row created.
    
    SQL> select * from test_order;
    
    NAME       SURNAME           AGE
    ---------- ---------- ----------
    Kamran     Agayev             26
    Kamran     Taghiyev           26
    John       Kevin              23
    
    SQL> select * from test_order
      2  order by age;
    
    NAME       SURNAME           AGE
    ---------- ---------- ----------
    John       Kevin              23
    Kamran     Agayev             26
    Kamran     Taghiyev           26
    
    SQL> select * from test_order
      2  order by age asc, surname desc;
    
    NAME       SURNAME           AGE
    ---------- ---------- ----------
    John       Kevin              23
    Kamran     Taghiyev           26
    Kamran     Agayev             26
    
    SQL>
    

    When in the second query, I sorted out only for age, you saw it there two 26 years old Keita, there was first Agayev, then Taghiyev. But if I want to get the family names in descending order when there are two very old person, then I will add the second column in the order by clause

    - - - - - - - - - - - - - - - - - - - - -
    Kamran Agayev a. (10g OCP)
    http://kamranagayev.WordPress.com

  • questions to move a column name as parameter. Please advice.

    Hi all

    I have some difficulties with oracle reports. I am a novice with the beginner 2 days.
    I am not able to use the lexical settings in reports. my query is as easy as

    Select & column-name abc xyz;

    I tried to make a setting before creating the SQL but I always get the error saying that ORA-00922: lack of expression.
    also I tried with bind variables like

    Select: col_name abc xyz;

    but it gives a: inplace Column of records the data.

    some could help me with step by step procedure to create a lexical parameter.

    I am using reports 6i.

    Please let me know for details.

    Thanks in advance!

    Hello

    I suggest you create a sing an example 'Basic' of the EMP table: (see the demobld.sql script provided with Developer Suite to create this table)

    Create a new report
    Create a COLUMN name parameter:
    Name = COLNAME
    DataType = character
    Width = 20
    Initial value = ENAME

    Create a SQL query: select & emp colname

    Create a page layout manually or with the wizard

    Click on the button «Run paper Layout»

    Enter a valid value for the 'column' name (ENAME / JOB / SAL / COMM /...)

    Concerning

Maybe you are looking for

  • How to reactivate my account

    Let him expired on 01/07/12. I just want to re-enable but can't get anywhere

  • sxrstr.dll backup and restore rstrui.exe

    Windows XP PC 3 open programs-> Accessories-> system-> system restore toolsImmediately send error report and never opens 5 error in rstrui.exe to loc 5 c 029836 module sxrstr.dllHas anyone seen this?  Y at - it a fix for this problem? Tom

  • The Sbh54 speaker volume

    Bought the Sbh54 at Christmas that I've owned the sbh52 previously and wanted an upgrade for my Z5p.The problem I have is that the "speaker" is not very strong in all. I rarely hear the ringing of the thing and forget about its use for hands-free bec

  • Remnant Z10 RDIO blackBerry files

    I wonder if anyone can help with this. I installed the android version of the app RDIO. He worked most of the time. It has installed about 5 GB of files on the phone that does the memory of the nearly full Z10. Files remained even after the applicati

  • Use of the high memory on Windows 7 without reason...

    Hello, I had recently a few problems with my computer after going on vacation for a week and turn it off.  When I got home my computer has had some problems of high memory use, I have no idea why.  I looked in my processes tab and it shows that Svcho