Вопрос по sql-server – Как объявить и использовать переменные в PL / SQL, как в T-SQL?

24

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

CREATE PROC MySampleProc
    @Name   VARCHAR(20)
AS
    SELECT @Name

Error: User Rate Limit Exceeded

DECLARE @Name VARCHAR(20)
SET     @Name = 'Tom'

    SELECT @Name

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

DECLARE
   myname varchar2(20);
BEGIN
     myname := 'Tom';

     select myname from DUAL;
END;

Error: User Rate Limit Exceeded

DECLARE
   myname varchar2(20);
BEGIN
     myname := 'Tom';

     SELECT *
     FROM   Customers
     WHERE  Name = myname;
END;

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

enter image description here

Error: User Rate Limit Exceeded

enter image description here

Error: User Rate Limit Exceeded Tom Halladay
Error: User Rate Limit ExceededSELECT Name INTO Name2 FROM DUAL. Codo
Error: User Rate Limit Exceeded Codo
Error: User Rate Limit Exceeded codingbiz
Error: User Rate Limit Exceededplsql-tutorial.com/plsql-variables.htm Tom Halladay

Ваш Ответ

3   ответа
4

Error: User Rate Limit Exceeded

declare
  myname varchar2(20) := 'tom';
begin
  for result_cursor in (select * from mytable where first_name = myname) loop
    dbms_output.put_line(result_cursor.first_name);
    dbms_output.put_line(result_cursor.other_field);
  end loop;
end;

Error: User Rate Limit Exceededselect...into...Error: User Rate Limit Exceeded

declare 
  myname varchar2(20);
begin
  select first_name into myname 
    from mytable 
    where person_id = 123;
end;
1

Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded Tom Halladay
Error: User Rate Limit Exceeded Tom Halladay
19

Revised Answer

Error: User Rate Limit Exceeded

var myname varchar2(20);

exec :myname := 'Tom';

SELECT *
FROM   Customers
WHERE  Name = :myname;

Error: User Rate Limit ExceededvarError: User Rate Limit ExceededexecError: User Rate Limit Exceeded


Original Answer

Error: User Rate Limit ExceededDBMS_OUTPUTError: User Rate Limit ExceededprintError: User Rate Limit Exceeded

DECLARE
   myname varchar2(20);
BEGIN
     myname := 'Tom';

     dbms_output.print_line(myname);
END;

Error: User Rate Limit Exceeded

CREATE FUNCTION my_function (myname in varchar2)
     my_refcursor out sys_refcursor
BEGIN
     open my_refcursor for
     SELECT *
     FROM   Customers
     WHERE  Name = myname;

     return my_refcursor;
END my_function;
Error: User Rate Limit Exceeded Tom Halladay
Error: User Rate Limit Exceeded Tom Halladay
Error: User Rate Limit Exceeded Tom Halladay
Error: User Rate Limit Exceeded
Error: User Rate Limit ExceededexecError: User Rate Limit ExceededvarError: User Rate Limit ExceededexecError: User Rate Limit Exceeded

Похожие вопросы