Oracle with alias as (select * from *)

Source: Internet
Author: User

With alias as (select * from *) select * from alias; equivalent to creating a temporary table syntax is with tempname as (select ....) select... example: with t as (select * from emp where depno = 10) select * from t where empno = xxx another simple example is with a as (select * from test) select * from a; in fact, it is to put a lot of repeated SQL statements in with as, get an alias, the subsequent query can be used to optimize a large number of SQL statements, and it is clear that it is a temporary storage, it is generally used in the stored procedure to connect multiple tables. Connection queries of result sets, such as querying an emp, dept, and work table, are used to store work information, eid, did, salary, and other requirements to query information about employees with higher salaries than their respective departments. At this time, a lot of connections are required, you can use with as to clearly connect several tables Assembly code with wd as (select did, arg (salary) average salary from work), em as (select emp. *, w. salary from emp left join work w on emp. eid = w. eid) select * from wd, em where wd. did = em. did and wd. average salary> em. salary; create table temp_zcy (content varchar2 (200); alter table temp_zcy add sid number; select * from temp_zcy order by sid; declare v_str varchar2 (200 ); v_ SQL varchar2 (200); begin for v_counter in 5 .. 1000 loop if mod (v_counter, 5) = 0 then -- dbms_output.put_line (v_counter + 5); -- v_str: = 'sum (case when. allamt> = '| v_counter; -- v_str: = 'sum (case when. allamt> = '| v_counter |' and. allamt <'| (v_counter + 5); v_str: = 'sum (case when. allamt> = '| v_counter |' and. allamt <'| (v_counter + 5) | 'Then. allamt else 0 end) as aaa' | v_counter | 'to' | (v_counter + 5) | 'wan bbb, '; -- dbms_output.put_line (v_str); v_ SQL: = 'insert into temp_zcy (sid, content) values ('| v_counter |', ''' | v_str | ''') '; execute immediate v_ SQL; commit; end if; end loop; end; from zcywell's column

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.