Set the Variable in the select statement

Hello

Can we define a variable in the select statement.

Example:

Select firstname, lastname
employees;

in this simple select statement we can define x as number?
select fname,lname
from employees
where rownum <= 30;

Tags: Database

Similar Questions

  • Assign the values of the two variables in a select statement

    I'm trying to set two variables in a select statement in my definition of the procedure. I get the error identifier not valid "ATTRIBUTE" running the following code.
    create or replace procedure tbl_auth (
    Email in varchar2,
    UserLevel out number)
    as
      v_Email varchar2(100) := lower(Email);
      v_login_chk number := 0;
    begin
     select UserLevel into p_UserLevel,
            v_login_chk into v_login_chk
     from tbl_User
     where eMail=v_Email  
    
    exception
     when no_data_found then
      UserLevel := 0;
    end tbl_auth;
    Can I not connect two different values to two different variables in the same select?

    Thank you

    Published by: jerry8989 on August 22, 2011 07:06

    Published by: jerry8989 on August 22, 2011 07:06

    change as follows:

     select UserLevel, v_login_chk into p_UserLevel,
            v_login_chk
    

    IN ONE ALONE is enough.

    BTW, don't you have "login Check" column in the "tbl_user"? If you do, your selection should be like this:

    ...
    select UserLevel, loginChk into /* check the column name in your table */
             p_UserLevel, v_login_chk
     from tbl_User
    ...
    
  • How to use the variable instead of the table name in the select statement of procedure

    I have a procedure with a select statement with dynamic from clause. How can I use instead of the name of the table variable.

    create or replace procedure scc_chemical_analysis
    is
    v_table_name varchar2 (100);
    Start

    declare
    cursor c1 is select * from v_table_name; -This is the variable name. How can I use it in the select statement.
    .
    .
    .
    .



    end;

    Hello

    something like that.

      1  declare
      2     vSQLString      VARCHAR2(32000);
      3  pTableName varchar2(1000):='EMP';
      4  BEGIN
      5     vSQLSTRING :=
      6  'SELECT ''x'' FROM ' || DBMS_ASSERT.sql_object_name(pTableName) || ' WHERE rownum<=1 ';
      7     EXECUTE IMMEDIATE vSQLSTRING;
      8* END;
    SQL> /
    
    PL/SQL procedure successfully completed.
    
  • using variable in the select statement (php)

    I have trouble using a variable in a select statement.

    The following query to manually (using a static date) works very well:

    $query_Recordset1 = "SELECT * from academyClasses WHERE the classDate > ' 2006-06-01' ';"

    However, if I use the following:

    $dateVar = date('Y-m-d');

    @mysql_select_db ($database_mw, $mw);
    $query_Recordset1 = "SELECT * from academyClasses WHERE the classDate > $dateVar";

    All records are returned, which means that the $dateVar variable is not recognized. I compared the values of $dateVar <? PHP echo $datetime;? > against the real value of my date field <? PHP echo $row_Recordset1 ["classDate"];? > in my results to the table and it seems that the values are indeed accurate regarding a date 2006-06-04 for example.

    My date field 'classDate' is of type 'date' in the mysql database. I use Dreamweaver MX 2004 with Mac OSX 10.3.9.

    I'm sure it's just a syntax problem, at least, I hope it is.

    Any help is greatly appreciated.



    It worked:

    $query_Recordset1 = "SELECT * from academyClasses WHERE the classDate > = CURRENT_DATE;

    Thank you
    MW

  • uniol all in the select statement

    Hi I have a situation where I have to return the value based on the if statement, is it possible to put union all in the select statement

    My use case is

    IN the column State

    If column01 > 0 to condtion 't'

    IF column02 > 0 that the condition of 'Y '.

    Condition IF COLUMN03 > 0 THAN 'w '.

    If COLUMN04 > 0 that the condition of "Z".

    Select 't'

    TableName

    where column01 > 0

    Union of all the

    Select "y".

    TableName

    where column02 > 0

    Union of all the

    Select 'W '.

    TABLENAME

    WHERE COLUMN03 > 0

    I have what it takes to show value as it

    EmpName, condition, empno

    Jerry, T, 0158754585

    TOM, Y, 0054789568

    Am in oracle database 11 g 2

    Yes you can put all THE UNION here

    Select empname, 't' State, empno from tablename where column01 > 0

    Union of all the

    Select empname, 't' State, empno from tablename where column02 > 0

    Union of all the

    Select empname, condition of "W", empno FROM tablename WHERE COLUMN03 > 0

    Union of all the

    Select empname, condition of "Z", empno FROM tablename WHERE COLUMN04 > 0

    and if you are looking for how to remove duplicates because your line might have satisfied all the conditions and my happen 4 times in your result set, you just need to give them an order and filter it.

    For example, you want this

    If column01 > 0 to condtion 't'

    ELSE IF column02 > 0 that the condition of 'Y '.

    Another condition of THAN > 0 IF COLUMN03 'w '.

    otherwise if COLUMN04 > 0 that the condition of "Z".

    Select empname, condition, empno, in

    (

    Select a.*, row_number() over (partition by empno arrested by myorder) rn

    Of

    (

    Select empname, 't' State, empno, 1 myorder tablename where column01 > 0

    Union of all the

    Select empname, 't' State, empno, 2 myorder tablename where column02 > 0

    Union of all the

    Select empname, condition of "W", empno 3 myorder FROM tablename WHERE COLUMN03 > 0

    Union of all the

    Select empname, empno, condition of 'Z', 4 myorder FROM tablename WHERE COLUMN04 > 0

    ) a

    ) where rn = 1

  • Call a method before the following operation to set the selected values

    Use case: I display a VO as an ADF multiple checkbox select. This VO is the detail of a master/detail. I managed to store the selection state in a bean managed on autoSubmit. Then the user navigate to the record of the master, and then goes back to the previous record. The buttons next and previous were created using operations in data controls. I want to back up the State of the selection by clicking previous or next.

    There are a lot of tutorial on how to get the selected values, but none on how to set the selected values. How would you do it?

    11 GR 1 material JDev

    What I ended up doing:

    1 redefine listener action for the navigation buttons

    {} public void nextQuestion (ActionEvent event)

    saveSelectedState();

    navigateQuestion ("Next");

    restoreSelectedState();

    }

    {} private void navigateQuestion (string operation)

    OperationBinding operationBinding = ADFUtils.findOperation (operation);

    operationBinding.execute ();

    }

    2 Save and restore the selection state using bindings

    Guava Multimap

    Private ListMultimap selectedIndices.

    private void saveSelectedState() {}

    Get id question

    DCIteratorBinding questionBinding = ADFUtils.findIterator ("QuestionsView1Iterator");

    Question of rank = questionBinding.getCurrentRow ();

    Number questionId = (Number) question.getAttribute ("Id");

    JUCtrlListBinding listBinding = (JUCtrlListBinding) ADFUtils.getBindingContainer () .get ("AnswersView2");

    int [] valueIndices = listBinding.getSelectedIndices ();

    selectedIndices.putAll (questionId, Ints.asList (valueIndices));

    }

    private void restoreSelectedState() {}

    Get id question

    DCIteratorBinding questionBinding = ADFUtils.findIterator ("QuestionsView1Iterator");

    Question of rank = questionBinding.getCurrentRow ();

    Number questionId = (Number) question.getAttribute ("Id");

    int [] valueIndices = Ints.toArray (selectedIndices.get (questionId));

    JUCtrlListBinding listBinding = (JUCtrlListBinding) ADFUtils.getBindingContainer () .get ("AnswersView2");

    listBinding.setSelectedIndices (valueIndices);

    }

  • to find the number of records retrieved in the select statement in the cursor

    Hi all
    with the cursor, I'm selecting select statement together and writing in the .txt file.
    his worksheet, but it should not open the file, if the cursor returns nothing.
    How to find the number of records returned by the select statement in the cursor.
    pls help me.

    Thank you...

    Don't understand what you're trying to say, but maybe it's...

    DECLARE
       vCounter NUMBER;
       -- Other variables...
    BEGIN
       vCounter:=0;
       FOR .. IN cursor LOOP
        IF vCounter=0 THEN
          -- Here open file...
          -- Here write one time data...
        END IF;
        -- Here write cursor data...
        vCounter:=1;
       END LOOP;
    END;
    

    -Clément

  • How to ask the user to type in the select statement

    Hello

    Can anyone tell me the syntax of the select statement where I can ask the user to enter the value.

    for example, I try to use belowthing, but it displays error

    Select * from emp where empname =: empname

    SP2-0552: Bind "empname' undeclared variable.


    2. is there a dictionary of data table to see all pl/sql procedures and corresponding code?


    Thank you
    Sri

    Try:

    select * from emp where empname='&empname';
    

    L.

  • How to use the Type of Oracle Table values in the Select statement.

    Hello

    I get the initial set of values in the Table of Type Records of the Oracle and want to use the list of values in the Select statement.

    For example, try something like the following:

    TYPE t_record () IS RENDERING
    ID TABLEA.ID%type,
    NO TABLEA.NO%type

    );
    v_record t_record;
    T_table TYPE IS the v_record TABLE % TYPE;
    v_table t_table;

    -Code to fill the values of v_table here.

    SELECT ID, NO, COLLECT in BULK IN < some other table variabes here > FROM TABLEA
    WHERE ID IN (i) v_table USER.USER;

    I want to know how to use the Type of Oracle Table values in the Select statement.

    Something like this:

    create or replace type t_record as  object (
    id number,
    no number
    )
    /
    
    CREATE or replace type t_table AS TABLE OF t_record;
    /
    
    set serveroutput on
    declare
    
      v_table t_table := t_table();
      v_t1 t_table := t_table();
    
    begin
    
      v_table.extend(1);
      v_table(1).ID := 1;
      v_table(1).No := 10;
    
      v_table.extend(1);
      v_table(2).ID := 2;
      v_table(2).ID := 20;
    
      SELEC t_record (ID,NO) BULK COLLECT INTO v_t1
      from TableA
      FROM TABLEA
      WHERE ID IN (select t.ID from table(v_Table) t);
    
      for i in 1..v_t1.count loop
        dbms_output.put_line(v_t1(i).ID);
        dbms_output.put_line(v_t1(i).No);
      end loop;
    end;
    /
    

    No test!

    P;

    Published by: bluefrog on March 5, 2010 17:08

  • Update using a function in the select statement

    Hello

    Is it possible to do the follwing.

    I tabele and a custom function, the custome service will update the column (amount) of the table based on the value of going through the function of the select statement.

    SELECT id, stock, where an id = get_update (id);

    Now


    Get_update function will return the same id I'm passing and update the column amount to a value in the
    table a.

    When I run the satament selection I have the updated data in the column amount in my first executtion, but if execute the same statement, again, I see the changes reflected. is it possible to get data updates to the first performance himself.

    the function is of type PRAGMA AUTONOMOUS_TRANSACTION

    Concerning

    Indeed a strange requirement and probably not the way to go in a production environment. But anyway is a way to achieve your goal

    SQL> create table a
    as
       select   12 id, 500 amount from dual
       union all
       select   13 id, 600 amount from dual
    /
    Table created.
    
    SQL> create or replace type a_typ as object (id number, amount number)
    /
    Type created.
    
    SQL> create or replace function get_id (pid number)
       return a_typ
    is
       pragma autonomous_transaction;
       l_a_typ   a_typ := a_typ (null, null);
    begin
          update   a
             set   amount = 800
           where   id = pid
       returning   id, amount      into   l_a_typ.id, l_a_typ.amount;
    
       commit;
    
       return l_a_typ;
    end get_id;
    /
    Function created.
    
    SQL> select   id, d.a_typ.amount amount
      from   a, (select get_id (13) a_typ from dual) d
     where   id = d.a_typ.id
    /
            ID     AMOUNT
    ---------- ----------
            13        800
    1 row selected.
    
  • How to set the initial state to hide/show buttons on opening PDF files?

    InDesign offering a wonderful object multi-state capacity which unfortunately does not work in PDF files. It took a bit of research for me to come with this information, the UI program itself gives indications that this should work. (Why not maybe another forum of discussion.)

    So, I create an interactive PDF using buttons to hide/show specific paragraphs (which are also implemented as buttons because only the buttons and forms can be hidden or shown, AFAIK).

    I've set up a PDF created via InDesign using the six control keys and seven paragraphs - one of these paragraphs is the initial state that I want to see when the document is opened. As long as the PDF file that I create is distributed, that's how it works: an initial paragraph appears, buttons can be clicked and the stuff of Heroes appears the mark.

    However, a colleague thoughtfully saved the PDF file (so it could rename something more to his liking). When he does this, he left one of the displayed subsidiary paragraphs, rather than the initial paragraph I intended... and of course, this is the version that came out to the customer.

    Question: Is there a way to set the initial state to hide/show buttons when a PDF document is opened first, regardless of the State in which he could let or saved? I guess it's sort of ON OPEN event that would allow me to define an initial state as a safety net to the way I save the original document. Obviously, the PDF AS I DELIVER IT will pave the way, I want it, but I'm trying to overcome the appearance of the Murphy's law of a document that can be re-recorded in another State. An event which OPENED on that cure.

    Thank you.

    in this case you would have been better if you had locked the PDF file in order to prevent changes ANDS record as actions...

  • mixture of column type in the select statement

    Oracle 11g r2.

    tab_test (name varchar2, blob... photo)

    (1) select general use *.

    Stored procedure: open ref_cursor to some * of table_test...

    Coast of java: call.registerOutParameter (1, OracleTypes.CURSOR);  Call.Execute ();

    It works very well.

    (2) enter the name of the column in the select such as

    Stored procedure: open ref_cursor to select name, photo table_test...

    Coast of java: call.registerOutParameter (1, OracleTypes.CURSOR);  Call.Execute ();

    ERROR: java.sql.SQLSyntaxErrorException: ORA-00932: inconsistent data types: expected - got BLOB

    My question, if I specify the column names in the select statement, including the varchar2 and blob, how can I registerOutParameter (1, OracleTypes.CURSOR);?

    Thank you

    Scott

    PS The number of returned columns, in real case schenario, is a little, so I prefer to specify column names.

    Wrong forum. This forum is for questions of sql and pl/sql.

    Enter the question ANSWER and the repost in the JDBC forum

    https://community.oracle.com/community/developer/english/java/database_connectivity/java_database_connectivity _(jdbc)

    When repost you provide the necessary information to help you:

    1. information on the full version for Oracle DB

    2 version of the JDK

    3. the name and version of the JDBC jar file

    4. real code that demonstrates the problem

    You should also review the info re REF CURSOR in the JDBC Developer's Guide

    http://docs.Oracle.com/CD/E16655_01/Java.121/e17657/oraint.htm#i1058743

  • function() nested in the select statement

    Oracle 11g. Try to nest a function within the select statement.  Goal: get the average customer rating for each of the qualified user.

    Select user_name, f_get_avg_cust_rating() "Notation.

    of u, OTHER_TABLES o TAB_USER

    where u.id = o.id and another condition matched;

    How Oracle would deal with the sql.  Is it

    (1) first of all display records based on the where clause, then call the f_get_avg_cust_rating() for each of the selected records OR

    (2) for the analysis in tables, the f_get_avg_cust_rating() will be called for each record met?

    Thank you

    Scott

    Words of Frank, I created two functions with dbms_output and used a function in where clause in select another function. See the bottom of the unit tests. Everyone says, where first clause then select...

    -Where function clause

    SQL > CREATE or REPLACE FUNCTION ret_empno

    2 RETURN NUMBER

    3 AS

    4 BEGIN

    5 DBMS_OUTPUT. Put_line (' where Clause Function');

    6 RETURN 7839;

    7 END;

    8.

    The function is created.

    -Select the function

    SQL > CREATE or REPLACE FUNCTION ret_1

    2 RETURN NUMBER

    3 AS

    4 BEGIN

    5 DBMS_OUTPUT. Put_line ('Select function');

    6 RETURN 1;

    7 END;

    8.

    The function is created.

    SQL > SELECT empno, ename,ret_1

    2 FROM emp

    3. WHERE empno = ret_empno;

    EMPNO, ENAME RET_1

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

    7839 KING 1

    Where the function Clause

    Select the function

  • Pivot will not get result in the select statement

    This is the version of oracle 11g R2 on windows details 7 OS

    CREATE TABLE OTBOOKINGDETAILS
    (EMPNO VARCHAR2 (10 BYTE),
    DATE OF OTBOOKEDDATE,
    NUMBER (5.0) DAY OF THE WEEK.
    DAYCEILINGHRS VARCHAR2 (10 BYTE));

    Here is the data

    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 MARCH 2013', 1,' 09:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 APRIL 2013', 2' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 MAY 2013', 3,' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 JUNE 2013', 4' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 JULY 2013', 5,' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 AUGUST 2013', 6,' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 SEPTEMBER 2013', 7,' 00:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 MARCH 2013', 1,' 09:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 APRIL 2013', 2' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 MAY 2013', 3,' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 JUNE 2013', 4,' 02:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 JULY 2013', 5,' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 AUGUST 2013', 6,' 04:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (102 ', 3 SEPTEMBER 2013', 7' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 OCTOBER 2013', 1,' 00:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 NOVEMBER 2013', 2' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 3 DECEMBER 2013', 3,' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 13 MARCH 2013', 4,' 04:45 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 14 MARCH 2013', 5,' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 15 MARCH 2013', 6,' 01:00 ');
    INSERT INTO OTBOOKINGDETAILS VALUES (101 ', 16 MARCH 2013', 7' 01:00 ');

    Here, I want to Dayceiling hours below the output using pivot

    EMPNO OTBOOKEDDATE DAY1_HRS DAY2_HRS DAY3_HRS DAY4_HRS DAY5_HRS DAY6_HRS DAY7_HRS
    101 03/03/2013 09:00 01:00 01:00 01:00 01:00 01:00 00:00
    102 03/03/2013 09:00 01:00 01:00 02:00 01:00 04:00 01:00
    101 03/10/2013 00:00 01:00 01:00 04:45 01:00 01:00 01:00

    ChakravarthyDBA wrote:
    I need to include the pivot query in the select statement

    Can' are you use PIVOT here since you do not know from the start what values OTBOOKEDDATE. So use:

    select  empno,
            otbookeddate - weekday + 1 otbookeddate,
            max(
                case weekday
                  when 1 then dayceilinghrs
                end
               ) day1_hrs,
            max(
                case weekday
                  when 2 then dayceilinghrs
                end
               ) day2_hrs,
            max(
                case weekday
                  when 3 then dayceilinghrs
                end
               ) day3_hrs,
            max(
                case weekday
                  when 4 then dayceilinghrs
                end
               ) day4_hrs,
            max(
                case weekday
                  when 5 then dayceilinghrs
                end
               ) day5_hrs,
            max(
                case weekday
                  when 6 then dayceilinghrs
                end
               ) day6_hrs,
            max(
                case weekday
                  when 7 then dayceilinghrs
                end
               ) day7_hrs
      from  otbookingdetails
      group by empno,
               otbookeddate - weekday + 1
      order by otbookeddate,
               empno
    /
    
    EMPNO      OTBOOKEDDA DAY1_HRS   DAY2_HRS   DAY3_HRS   DAY4_HRS   DAY5_HRS   DAY6_HRS   DAY7_HRS
    ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
    101        03-03-2013 09:00      01:00      01:00      01:00      01:00      01:00      00:00
    102        03-03-2013 09:00      01:00      01:00      02:00      01:00      04:00      01:00
    101        10-03-2013 00:00      01:00      01:00      04:45      01:00      01:00      01:00
    
    SQL> 
    

    SY.

  • validation for each 1,000 records to be inserted in the select statement

    Hi, I have the following INSERTION in the SELECT statement.
    The SELECT statement (who joined) data fo about 6 crores. I need to insert this data into another table.

    Please suggest me the best way to do it.
    I use the INSERT in the SELECT statement, but I want to use the statement commit for each 1,000 records.

    How can I do this...
    insert into emp_dept_master 
     select e.ename ,d.dname ,e.empno ,e.empno ,e.sal 
       from emp e , dept d
      where e.deptno = d.deptno       ------ how to use commit for every 1000 records .
    Thank you

    Method 4 is the best

    You could combine method 3 and 1 (without dynamic SQL)

    Method 2 is the less optimal solution from the list.

Maybe you are looking for

  • Satellite C660 freezes when WLan connection to WPA encrypted networks

    Hello everyone I have a toshiba satellite C660-A259 (Middle East version).The laptop is great, but it has a major problem.Whenever I try to connect to WPA / WPA2 networks, laptop computer freezes completely during the connection, dragging me to hard

  • Acer aspire slim form factor X PY.22009.009 220W EUP PFC 3990 part number

    I am looking for some time for a power supply for my X 3990, I have a part number, but I can't find anyone who sells them, can someone help me please? I am desperate thanks.

  • He said "no file found" but I see here.

    I have this file on my desktop named "001.", he says the file type is just 'file', and when I try to move or rename or something it says 'Could not find point' but it's right there. I tried to release, I tried a file shredder, I restarted the compute

  • Return to the previous view on Android

    I use Reader for Windows and Android. However, on Android, I miss the Alt-left that would take me after that I hit a link. Consider a more complex document, in my case a textbook of mathematics, would be much easier with it. I was hoping that the lef

  • Analytics of obiee connection cannot get invalid user name and password

    Hi people,I am unable Loing analytical Obiee, get the valid user name and password when check the server log file do the sub questions.Authentication failed: invalid user/password.[2015 02-03 T 12: 13:52.000 - 05:00] [OracleBIServerComponent] [ERROR]