ITPub博客

首页 > Linux操作系统 > Linux操作系统 > record

record

原创 Linux操作系统 作者:wuxidba 时间:2010-11-01 19:57:00 0 删除 编辑
Records

a record is composed of one or more fields. There are three different ways to define a record:

1. Table-based record

CREATE TABLE books (
      book_id         INTEGER,
      isbn            VARCHAR2(13),
      title           VARCHAR2(200),
      summary         VARCHAR2(2000),
      author          VARCHAR2(200),
      date_published  DATE,
      page_count      NUMBER
    );



I can then easily create a record based on this table, populate it with a query from the database, and then access the

individual columns through the record's fields:

    DECLARE
       my_book   books%ROWTYPE; -- RECORD definition
    BEGIN
       SELECT *
         INTO my_book
         FROM books
        WHERE title = 'Oracle PL/SQL Programming, 4th Edition';
     
       IF my_book.author LIKE '%Feuerstein%'
       THEN
          DBMS_OUTPUT.put_line ('Our newest ISBN is ' || my_book.isbn);
       END IF;
    END;

2. Cursor-based record

    DECLARE
       CURSOR my_books_cur IS
          SELECT * FROM books
           WHERE author LIKE '%FEUERSTEIN%';

       one_SF_book my_books_cur%ROWTYPE;
3. programmer defined
--select into record directly
    DECLARE
       TYPE customer_sales_rectype IS RECORD
          (customer_id   NUMBER (5),
           customer_name customer.name%TYPE,
           total_sales   NUMBER (15,2)
           );
       top_customer_rec  customer_sales_rectype;
    BEGIN
       /* Move values directly into the record: */
       SELECT customer_id, name, SUM (total_sales)
         INTO top_customer_rec
         FROM cust_sales_roundup
        WHERE sold_on < ADD_MONTHS (SYSDATE, -3)
         GROUP BY customer_id, name;

 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23895263/viewspace-677180/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: string
下一篇: 动态表名
请登录后发表评论 登录
全部评论

注册时间:2010-05-12

  • 博文量
    64
  • 访问量
    73601