How to use order by in stored procedure base block?

How to use order by in stored procedure base block? I need to change order by dynamically

Use SET_BLOCK_PROPERTY('BLOCK_NAME',ORDER_BY,'COLUMN_NAME1, COLUMN_NAME2');

Similar Messages

  • How to use materialized view in stored procedure

    in my stored procedure I use couple of queries (see the script below). I want to create materialized views to replace these queries. Is it possible to achieve and how to achieve it in my case? thanks in advance
    set serveroutput on
    DECLARE
      v_cur_tid NUMBER(5):=0;
      v_cur_cs_attendance NUMBER(5):=0;
      v_cur_c_tot_enrolments NUMBER(5):=0;
      v_most_enrolments NUMBER(5):=0;
      v_least_enrolments NUMBER(5):=0;
      v_most_pop_cid NUMBER(5):=0;
      v_least_pop_cid NUMBER(5):=0;
      CURSOR class_cursor IS
    select
    id,
    name,
    max_attendees
    from
    class
    where
    id in (select distinct(event_id) from trainer_schedule where event_type='c' and is_active='y')
    order by id;
    BEGIN
    DBMS_OUTPUT.PUT_LINE('==================================================================================================================================');
    --print the report header
    DBMS_OUTPUT.PUT_LINE('Summary Report No.3: Training Class Active Schedules Summary Report');
    FOR r_class IN class_cursor LOOP
    --print the header or subsection
    select sum(enrolments) into v_cur_c_tot_enrolments from class_schedule where class_id = r_class.id;
    IF v_most_enrolments < v_cur_c_tot_enrolments OR v_most_enrolments = 0
    THEN v_most_enrolments := v_cur_c_tot_enrolments; v_most_pop_cid := r_class.id;
    END IF;
    IF v_least_enrolments > v_cur_c_tot_enrolments OR v_least_enrolments = 0
    THEN v_least_enrolments := v_cur_c_tot_enrolments; v_least_pop_cid := r_class.id;
    END IF;
    DBMS_OUTPUT.PUT_LINE('******************************************************************************************');
    DBMS_OUTPUT.PUT_LINE('CLASS_ID: '  || r_class.id ||'     '|| 'CLASS_NAME: '  || r_class.name ||'     '||'CAPACITY: '  || r_class.max_attendees ||'     '||'TOTAL_ENROLMENTS: '  || v_cur_c_tot_enrolments);
    DBMS_OUTPUT.PUT_LINE(rpad('____________', 12) || lpad('____________', 12) || lpad('____________________', 20) || lpad('____________________', 20) || lpad('____________',12) || lpad('____________',12));
    DBMS_OUTPUT.PUT_LINE(rpad('SCHEDULE_ID', 12) || lpad('TRAINER_ID',12) || lpad('START_TIME', 20) || lpad('END_TIME',20) || lpad('ENROLMENTS',12) || lpad('ATTENDANCE',12));
    DBMS_OUTPUT.PUT_LINE(rpad('____________', 12) || lpad('____________',12) || lpad('____________________', 20) || lpad('____________________', 20) || lpad('____________',12) || lpad('____________',12));
    FOR r_cs IN (select id,to_char(start_time,'DD-MM-YYYY HH24:Mi') as start_time, to_char(end_time,'DD-MM-YYYY HH24:Mi') as end_time, enrolments from class_schedule where class_id = r_class.id order by id)
    LOOP
    select trainer_id into v_cur_tid from trainer_schedule where event_type='c' and event_id = r_cs.id;
    select count(training_session.id) into v_cur_cs_attendance
    from training_session, class_schedule
    where training_session.attended = 'y' and
    training_session.type='c'and
    to_char(training_session.start_time,'DD-MM-YYYY HH24:Mi') = to_char(class_schedule.start_time,'DD-MM-YYYY HH24:Mi') and
    class_schedule.id = r_cs.id;
    DBMS_OUTPUT.PUT_LINE(rpad(r_cs.id, 12) || lpad(v_cur_tid,12) || lpad(r_cs.start_time, 20) || lpad(r_cs.end_time,20) || lpad(r_cs.enrolments,12) || lpad(v_cur_cs_attendance,12));
    END LOOP;
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('******************************************************************************************');
    DBMS_OUTPUT.PUT_LINE('******************************************************************************************');
    DBMS_OUTPUT.PUT_LINE('MOST_POPULAR_CLASS:  '||v_most_pop_cid||'      TOTAL_ENROLMENTS_TO_DATE: '||v_most_enrolments);
    DBMS_OUTPUT.PUT_LINE('LEAST_POPULAR_CLASS: '||v_least_pop_cid||'      TOTAL_ENROLMENTS_TO_DATE: '||v_least_enrolments);
    DBMS_OUTPUT.PUT_LINE('==================================================================================================================================');
    END;
    /

    Hi,
    you could use Dynamic SQL /Execute immediate to run DDL from a stored procedure.
    http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96624/11_dynam.htm
    Could you please tell why do you want to create a materialized view in stored procedure ?
    How frequently you will runt this procedure . It would is better to create a MV once and use it.
    thanks

  • How to use @jws:sql call Stored Procedure from Workshop

    Is there anyone know how to use @jws tag call Sybase stored procedure within
    Workshop,
    Thanks,

    Anurag,
    Do you know is there any plan to add this feature in future release? and
    when?
    Thanks,
    David
    "Anurag Pareek" <[email protected]> wrote in message
    news:[email protected]..
    David,
    In the current release, we do not support calling stored procedures from a
    database control. You will have to write JDBC code in the JWS file to call
    stored procedures.
    Regards,
    Anurag
    Workshop Support
    "David Yuan" <[email protected]> wrote in message
    news:[email protected]..
    Anurag,
    I know how to use DB connection pool and create a db control with it. In
    fact, we have created a Web Service with the db control using plain SQL
    in
    @jws:sql. However, my question here is how to use @jws tag in Weblogic
    Workshop to create a Web Services based on Sybase stored procedure orany
    Stored Proc not plain SQL.
    Thanks,
    David
    "Anurag Pareek" <[email protected]> wrote in message
    news:[email protected]..
    David,
    You can use a database control to obtain a connection from any JDBC
    Connection Pool configured in the config.xml file. The JDBC Connectionpool
    could be connecting to any database, the database control is
    independent
    of
    that.
    Regards,
    Anurag
    Workshop Support
    "David Yuan" <[email protected]> wrote in message
    news:[email protected]..
    Is there anyone know how to use @jws tag call Sybase stored
    procedure
    within
    Workshop,
    Thanks,

  • How to use DATETIME parameters in stored procedure?

    I can not define a variable or parameters
    with data type of DATETIME
    when I define stored procedure using Developer/2000.
    Does Oracle not support DATETIME?
    null

    Chen Honghua (guest) wrote:
    : I can not define a variable or parameters
    : with data type of DATETIME
    : when I define stored procedure using Developer/2000.
    : Does Oracle not support DATETIME?
    Oracle supports DATETIME data type.
    "DATETIME" data type is stored in "DATE" data type.
    if you want to DEFINE "10-Jan-1998 10:20" :
    declare
    dummy_date date:=to_date('10-jan-1998 10:00','DD-MON-YYYY
    HH24:MI');
    BEGIN
    END;
    null

  • How to use optional prompts with stored procedure universe?

    Hi Experts,
    Iu2019m working on stored procedure universe in BO XI 3.0 SP2 FP2.5 with oracle at back end. My requirement is that I have to pass 5 optional prompts in the report and we have to pass these prompts through open document link. Please tell if this can be worked out on stored procedure universe?
    Thanks in advance.

    Hi,
    Try with OpenDoc syntax as follows.
    http://<servername>:<port>/OpenDocument/opendoc/<plat
    formSpecific>?iDocID=****&sIDType=CUID&sType=wid/rpt&lsM/lsS/lsRPROMPTNAME=[V1],[V2]&sDocName=reportname&sRefresh=Y/N
    where
    server name: cms server name
    port: portno
    <platformspecific>=: for java -> openDocument.jsp
                                      for .net -> opendocument.aspx
    idocid,sDocName & cuid -> we can get report properties ( goto info view -> select report -> right click -> properties i.e. doc id, cuid and report name)
    sType -> type of report i.e webi or deski ...
    lsS -> to pass single prompt value
    lsM -> to pass multiplle values to prompt
    lsR -> range of values ....
    Note: Here prompt name should be same as the one which we used in the report. Use + if there is blank space.
    Cheers,
    Suresh Aluri.

  • How to use SPOOL in a stored procedure

    Hi,
    I need to SPOOL the out put of a curson into a file. Please help me to do this. But this is not working.
    declare
    SET DEFINE ON;
    DEFINE SPOOL_FILE='chain.lst'
    cursor c1(var_chn_cnt number) is select owner,TABLE_NAME from dba_tables where CHAIN_CNT>var_chn_cnt order by owner;
    begin
    for c1_var in c1(0)
    loop
    DBMS_OUTPUT.ENABLE(1000000);
    SPOOL &SPOOL_FILE
    --Step 1
    DBMS_OUTPUT.PUT_LINE('set echo on;');
    DBMS_OUTPUT.put_line(chr(13));
    DBMS_OUTPUT.PUT_LINE('ANALYZE TABLE '||c1_var.owner||'.'||c1_var.table_name||' LIST CHAINED ROWS;');
    DBMS_OUTPUT.put_line(chr(13));
    --Step 2
    DBMS_OUTPUT.PUT_LINE('CREATE TABLE '||c1_var.owner||'.'||'CHNTEMP_'||c1_var.table_name||' AS SELECT * FROM '||
    c1_var.table_name||' WHERE ROWID IN (SELECT HEAD_ROWID FROM '||c1_var.owner||'.'||
    'CHAINED_ROWS WHERE TABLE_NAME='''||c1_var.table_name||''' and OWNER='''||c1_var.owner||''||');');
    DBMS_OUTPUT.put_line(chr(13));
    --Step 3
    DBMS_OUTPUT.PUT_LINE('DELETE FROM '||c1_var.owner||'.'||c1_var.table_name||' WHERE ROWID IN (SELECT HEAD_ROWID FROM '||
    c1_var.owner||'.'||'CHAINED_ROWS WHERE TABLE_NAME='''||c1_var.table_name||''' and OWNER='''||c1_var.owner||''||';');
    DBMS_OUTPUT.put_line(chr(13));
    --Step 4
    DBMS_OUTPUT.PUT_LINE('DROP TABLE '||c1_var.owner||'.'||'CHNTEMP_'||c1_var.table_name||';');
    DBMS_OUTPUT.put_line(chr(13));
    --Step 5
    DBMS_OUTPUT.put_line('TRUNCATE TABLE '||c1_var.owner||'.'||'CHAINED_ROWS;');
    DBMS_OUTPUT.put_line(chr(13));
    DBMS_OUTPUT.PUT_LINE('set echo off;');
    DBMS_OUTPUT.put_line('-------------------------------------------------------------------------------------------------');
    end loop;
    --EXCEPTION
    --WHEN OTHERS THEN
    -- raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
    end;
    Regards,
    Mat.

    Hi, Mat,
    Sorry, the answer is the same as it was in [your other thread|http://forums.oracle.com/forums/message.jspa?messageID=3610719#3610719].
    You can't start SPOOLing insided PL/SQL.
    Give the SPOOL command before you start PL/SQL, as Alex, Sundar and I showed you.
    If you really do need to do file I/O from within PL/SQL, use util_file instead of dbms_output. With utl_file you can name, open, read, write and close files from PL/SQL. You can have several output files open at once, if you want to. See the [PL/SQL Packages and Types manual|http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28419/u_file.htm#BABGGEDF] for details.

  • How to use bind variables in this procedure

    Hi Experts,
    How to use bind variables in this procedure for static queries.
    PROCEDURE DELETE_MER_PROC (M_id IN NUMBER)
    IS
    BEGIN
    V_date DATE;
    SELECT PD_DATE INTO v_date FROM PD_MAINTAIN;
        DELETE FROM MER_CLEAR
        WHERE MER_DT < v_date
        AND ID = M_ID;
    COMMIT;
    END;   
    How to use  v_date and m_id as bind variables in this procedure to avoid hard parsing.
    Please help me.
    Thanks.

    976208 wrote:
    How to use  v_date and m_id as bind variables in this procedure to avoid hard parsing.
    You cannot avoid hard parsing - as the 1st time a SQL statement (like the SELECT or DELETE statements in your code) is encountered, it does not reside in the server's Shared Pool, and needs to be added into the pool via a hard parse.
    Bind variables does not prevent hard parsing. Hard parsing happens when the SQL statement (with or without bind variables) is a brand new statement encountered by the server.
    Bind variables enables the same SQL cursor to be reused, by simply changing the bind variable value.
    Not using bind variables means that each SQL statement is unique and not shareable - as the value is hardcoded into the statement and cannot be changed via a bind value. This typically means LOTS of different SQL statements (where the only difference is the changed value in the statement) are created - with each statement being a new statement not seen before in the Shared Pool and needing to be hard parsed.
    One does not design one's code not to be hard parsed. There ALWAYS will be a hard parse in order to get a SQL statement into the Shared Pool. One designs one's code to REUSE cursors in the Shared Pool.

  • Using VIEW inside a stored procedure

    Hi,
    So I have a View designed in one file that validates someone who is authorized.
    Then I have a stored procedure to display authorized stationeries created before a given date. Its takes a parameter @CreatedOn.
    How can I use VIEW in my stored procedure so I can display all the authorized which are set 1 before a given date?
    My VIEW:
    ALTER VIEW vw_AuthorizedStationeries AS
    SELECT Authorized
    FROM dbo.Stationeries
    WHERE Authorized = 1
    And my stored procedure:
    CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)ASBEGINSELECTFROMENDGO
    Thanks!

    Try something like below, You need to replace CreatedDate column with appropriate date column in your table.
    1. Alter the view to get the required date:
    ALTER VIEW vw_AuthorizedStationeries AS
    SELECT Authorized, CreatedDate
    FROM dbo.Stationeries
    WHERE Authorized = 1
    2. Alter SP:
    CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)
    AS
    BEGIN
    SELECT Authorized
    FROM vw_AuthorizedStationeries
    WHERE CreatedDate <= @CreatedOn
    END
    GO
    OR
    You can pull required information directly from your table:
    CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)
    AS
    BEGIN
    SELECT Authorized
    FROM dbo.Stationeries
    WHERE CreatedDate <= @CreatedOn and Authorized = 1
    END
    GO
    If this post answers your query, please click "Mark As Answer" or "Vote as Helpful".

  • How to call a sql server stored procedure from oracle

    Hi all,
    Please anybody tell me how to call a sql server stored procedure from oracle.
    I've made an hsodbc connection and i can do insert, update, fetch data in sql server from oracle. But calling SP gives error. when I tried an SP at oracle that has line like
    "dbo"."CreateReceipt"@hsa
    where CreateReceipt is the SP of sql server and hsa is the DSN, it gives the error that "dbo"."CreateReceipt" should be declared.
    my database version is 10g
    Please help me how can i call it... I need to pass some parameters too to the SP
    thanking you

    hi,
    thank you for the response.
    when i call the sp using DBMS_HS_PASSTHROUGH, without parameters it works successfully, but with parameters it gives the following error
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
    [Generic Connectivity Using ODBC][Microsoft][ODBC SQL Server Driver]Invalid parameter number[Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index (SQL State: S1093; SQL Code: 0)
    my code is,
    declare
    c INTEGER;
    nr INTEGER;
    begin
    c := DBMS_HS_PASSTHROUGH.OPEN_CURSOR@hsa;
    DBMS_HS_PASSTHROUGH.PARSE@hsa(c, 'Create_Receipt(?,?)');
    DBMS_HS_PASSTHROUGH.BIND_VARIABLE@hsa(c,1,'abc');
    DBMS_HS_PASSTHROUGH.BIND_VARIABLE@hsa(c,2,'xyz');
    nr:=DBMS_HS_PASSTHROUGH.EXECUTE_NON_QUERY@hsa(c);
    DBMS_HS_PASSTHROUGH.CLOSE_CURSOR@hsa(c);
    end;
    Create_Receipt is the sp which requires two parameters.
    please give me a solution
    thanking you
    sreejith

  • Can rs.last() be used after calling the stored procedure?

    Can rs.last() be used after calling the stored procedure? If yes what should be the CURSOR types?

    Can rs.last() be used after calling the stored
    procedure? If yes what should be the CURSOR types?That would depend on the driver/database.
    And as I said in your other post it is far more efficient to count records by just returning a count rather than a complete collection regardless of how you get to the end.

  • Using Copy statement in Stored procedure

    The following statement works in sqlplus session:
    copy from comment/password@servername append amcomment_temp using
    select * from amcomment
    where commentid in(1,2,3,4)
    I want to use this in a stored procedure. There is a long datatype in this table. The
    procedure will not compile. Have tried execute immediate and compiler rejects this statement also.

    'COPY' is a SQL*Plus command, not PL/SQL. This is why the PL/SQL compiler throws it out.

  • How to use order by within Group by clause

    Hi All,
    I need a help as to how should i use the Order by clause so that the data should be in order with respect to one column, and at the same time whole data is grouped by some other column...like
    Select RaceNo,Venue,FP,BP from Race group by RaceNo
    Here I want to order by FP in ascending order for each group. When i am using it , whole order is changing.
    Can anybody suggest me how to use order by clause that would apply to each group of data.
    Thanks .

    order by clause should be used at the last in any query.......but in group by clause u can't use use that becoz u group according to column then no ordering is needed there......if u want to filter something then u can use having clause and later if u need to arrange then u can use order by clause.........
    i hope this eg.l gives u some clarification....
    e.g
    select deptno,count(empno)
    from dept
    group by deptno
    having count(empno) > 10
    order by deptno

  • How to write a PL/SQL stored procedure in Oracle to call Webservice

    Can any one pelase send me a code on how to write a PL/SQL stored procedure in Oracle database to call the Webservice ?
    Thanks,
    Rajesh

    Were you able to solve this problem

  • Using temporary tables in stored procedures

    Suppose that I have created a temporary table in a stored procedure using an "EXECUTE IMMEDIATE" statement. When I compile the procedure, that table is not created yet, so the compiler says that the table does not exist.
    What is the way of using temporary tables in stored procedures?

    It's a good practice to avoid using DDL statements being executed from stored procedures. "Truncate Table" via dynamic SQL from stored procedure is a different story and is useful in DSS environments.
    But if you insist on "creating" tables using Dynamic SQL from Stored Procedures then you must also embed your DML statements in Dynamic SQL to avoid compilation errors.
    Example:
    Create or Replace Procedure Proc_TestDynamicSQL is
    Begin
    Execute Immediate 'Create table myTable as select * from user_tables' ;
    Execute Immediate 'Update myTable set table_name = ''Test'' ' ; --two single quotes before and after the string "Test"
    End;
    In this case, Oracle wouldn't care about the table references during compilation.

  • In SQLScript, how to use EXEC to call another procedure with parameters in procedure?

    Hi experts,
    In SQLScript, How to use EXEC to call another procedure with input and output parameters in procedure?thanks very much

    Hi Sagar,
    thank you! I generate another procedure with an input parameter and an output parameter in a procedure. Then i need to call the generated procedure using EXEC. Here is my code:
    create procedure ftest1(out sum_num bigint)
    as
    begin
    declare fa_output bigint;
    declare v_sql_drop varchar(200);
    declare v_sql varchar(500);
    declare cursor c_cursor1 for select num from TABLE1;
    --v_sql_drop := 'drop procedure fe';
    --exec v_sql_drop;
    v_sql := 'create procedure fe(in i_num bigint,out o_num bigint) as begin';
    v_sql := :v_sql || ' o_num := :i_num * 2 + :i_num * :i_num;';
    v_sql := :v_sql || ' end';
    exec v_sql;
    open c_cursor1;
    for c_item as c_cursor1 do
    exec 'call fe(c_item.num,o_num=>fa_output)';
    if sum_num is null then
    sum_num := fa_output;
    else
    sum_num := :sum_num + fa_output;
    end if;
    end for;
    close c_cursor1;
    end;
    The underline code is using exec to call the generated procedure. But this method cannot work. Any suggestion? thanks again!

Maybe you are looking for

  • Sharepoint 2013 Open document in client application

    Hi, I have a sharepoint 2013 server which has word documents stored in a document library. I am able to open the documents when i click the url from sharepoint site. I have been trying to open those word documents from an angular js application using

  • Fonts are not the same color from page to page?

    I had a page with white colored font and the subsequent page had a grey version of the same font.  So I created a new page off of the page that had the correct white colored font and I copied the text from the other page to the newly created page and

  • Rouge alerts on iPhone for events created on Mountain Lion

    When I add calendar events in iCal the event shows no alerts, but when syncing the calendar with the iPhone there is an alert for 15 hours before. I can delete this alert off on the iPhone but it is a pain to have the computer show no alerts and then

  • ABAP Programm for calling Proxies

    Hi Experts, I was writing a ABAP programm für starting a ABAP proxy. *& Report  Z_XI_MAPPING REPORT  Z_XI_MAPPING. parameters: PA_WAIT type decimals default 0,             PA_LOOP type decimals default 1,             PA_EOIO type char1 default 'X',  

  • [FM12] Linking multiple books for HTML5 output

    Hi all, Here is the problem I'm facing : I've created several FM12 books. Each one has a life on its own, as the main purpose is to publish in PDF format. I would like publish in HTML5 to put all the books in an online help, that would be integrated