Some problems and solutions in the compilation of Pl/sql program

Source: Internet
Author: User
Program | solve | problem
1. In Pl/sql, the conditions in the ORDER BY clause can use the variable!

DECLARE
V_orderbystr VARCHAR2 (30);
V_userid VARCHAR2 (30);
V_username VARCHAR2 (30);
V_gender number;
V_rownum number;
TYPE Tcur is REF CURSOR;
Results tcur;
BEGIN
v_rownum:=0;
v_orderbystr:= ' username ';
OPEN results for select Userid,username,gender from
(select RowNum as Rowno, a.* from
(SELECT * from Home_user ORDER by V_orderbystr) a
where rownum<10)
where rowno>=1;
LOOP
FETCH results into V_userid,v_username,v_gender;
EXIT when Results%notfound;
Dbms_output.put_line (v_userid| | ' '|| v_username| | ' '|| V_gender);
v_rownum:=v_rownum+1;
End LOOP;
Close results;
Dbms_output.put_line (V_rownum);
End;

2, while writing dynamic SQL stored procedures, found in the use clause, found that the table name can not be used as a placeholder parameter! And can only be replaced by the method below, that is, directly linked to the table name and string, other variables can be replaced by the placeholder;
V_sqlstr:= ' SELECT * FROM (select RowNum rowno,t.* from '
||' (SELECT SequenceID msgid,themeid,id,topic,hits,replys,nickname '
||' From ' | | tablename| | ' where themeid=:a2 order By:a3) t where Rownum<:a4 '
||') WHERE Rowno>=:a5 ';
Dbms_output.put_line (V_SQLSTR);
OPEN o_results for V_sqlstr USING P_themeid,v_orderbystr,v_endrow,v_startrow;

3, in doing some paging query, the use of pseudo-column rownum, found that rownum can only be used for rownum<10 and other applications, but not rownum>10; in the example of the implementation of the same time paging function;

4, use the existing table to create a new table, and copy the table structure of the source table:
CREATE TABLE newtable as (SELECT * oldtable where 1=2)



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.