HELP - SELECT...INTO Variable ---> More than one variable???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Reshmi Jacob
    New Member
    • Sep 2006
    • 50

    HELP - SELECT...INTO Variable ---> More than one variable???

    Hello

    Can I have more than one variable assign to a select clause in a trigger. How? My stmt creates an error

    SELECT FLD1 into VAR1, FLD2 into VAR2 FROM MYTABLE;

    ERROR shown at the second INTO.

    I tried to make it a cursor and it was successful .

    But I would like to know if its possible or any other method???

    Thanks & Regards
    Reshmi
  • milonov
    New Member
    • Oct 2006
    • 32

    #2
    Hi, Reshmi.

    You did all correct. select into is suitable for only one variable and cursor if more then one.

    Best Regards,
    Michael Milonov


    Originally posted by Reshmi Jacob
    Hello

    Can I have more than one variable assign to a select clause in a trigger. How? My stmt creates an error

    SELECT FLD1 into VAR1, FLD2 into VAR2 FROM MYTABLE;

    ERROR shown at the second INTO.

    I tried to make it a cursor and it was successful .

    But I would like to know if its possible or any other method???

    Thanks & Regards
    Reshmi

    Comment

    • suvam
      New Member
      • Nov 2006
      • 31

      #3
      U can try with it -----------
      Select field1,field2 into v1,v2 from t1 ;

      Comment

      • pragatiswain
        Recognized Expert New Member
        • Nov 2006
        • 96

        #4
        Originally posted by suvam
        U can try with it -----------
        Select field1,field2 into v1,v2 from t1 ;
        Suvam is right

        Comment

        • ltiongECT
          New Member
          • Mar 2008
          • 1

          #5
          You can also do something like (SQLServer):

          declare @variable1 varchar(75)
          declare @variable2 varchar(75)

          select @variable1 = FirstName, @variable2 = LastName from Employees
          where...

          Note: if you query returns multiple row, your variables will take on the value of the last row.

          Comment

          • amitpatel66
            Recognized Expert Top Contributor
            • Mar 2007
            • 2358

            #6
            Originally posted by ltiongECT
            You can also do something like (SQLServer):

            declare @variable1 varchar(75)
            declare @variable2 varchar(75)

            select @variable1 = FirstName, @variable2 = LastName from Employees
            where...

            Note: if you query returns multiple row, your variables will take on the value of the last row.
            This Syntax is not supported in Oracle!!

            Comment

            Working...