0

i need to create variables for my query

i have a inner join query Es

select * from ...
inner join
 etc ..
where username = 'jack'
and value 1 = 'work'

i'd like to create on top variables for easy change value in where condition.

I have used Declare and set but show me the error PLS-00103 for group having intersect minus order start union where connect

how can i do for create variables ? thanks a lot for help, sorry for my English is not my first languages.

2
  • Are you working using Stored procedure to call this select? Commented Jul 23, 2015 at 8:24
  • no a simple select with inner join Commented Jul 23, 2015 at 9:11

2 Answers 2

1

You can use Anonymus PL/SQL block for your above question. But if you are using select inside block, you should use INTO clause along with it.

E.g.--

CREATE TABLE T1 (AA VARCHAR2(20));

insert into t1 values('YYY');
commit;  -- table created with sample value.

Now, use Anonymus pl-sql block to call select -

DECLARE
USERNAME VARCHAR2(20);
VALUE1 VARCHAR(20);

BEGIN
USERNAME:='YYY';

SELECT aa into  VALUE1 FROM T1 WHERE AA=USERNAME;

dbms_output.put_line(VALUE1);

end;

Now, in your case since you are using select * you can use ROWTYPE attribute to select the row from your table. Check ROWTYPE example here. http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/fundamentals.htm#BEIBGEFH

Sign up to request clarification or add additional context in comments.

Comments

0

You have to embeded statements between begin and end.

Declare varchar2(30) vUserName := 'jack';
Declare ...
Begin
    select * from ...
    inner join
    etc ..
    where username = vUserName
          and value 1 = vValue1
End

3 Comments

You've got an extra Declare there; remove that as it's not necessary.
Report error -ORA-06550: Encountered the symbol "(" .... is on the end of varchar2
ah, the variable name needs to go before the datatype. so: vusername varchar2(30) := 'jack';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.