using the dynamic SQL syntax

I am trying to create a dynamic sql to execute the following statement:

create the table mytbl_20100901 in select * from matbl double;

When I try the following error I
ORA-06550: line 6, column 10:
PLS-00103: encountered the symbol "SELECT" at the expected in the following way:

;;;;;;;;;;;;;;;;;;;;;;;;;;;
declare
sql_cmd varchar2 (1000);

Start

sql_cmd: = select "create table mytbl_ | To_char (sysdate, 'YYYYMMDD') | ' in select * from matbl ' double.

immediately run sql_cmd;

end;
;;;;;;;;;;;;;;;;;;;;;;;;;

How to fix the sql_cmd assignment statement?

Thank you.

Hello

user1035690 wrote:
I am trying to create a dynamic sql to execute the following statement:

create the table mytbl_20100901 in select * from matbl double;

When I try the following error I
ORA-06550: line 6, column 10:
PLS-00103: encountered the symbol "SELECT" at the expected in the following way:

;;;;;;;;;;;;;;;;;;;;;;;;;;;
declare
sql_cmd varchar2 (1000);

Start

sql_cmd: = select "create table mytbl_ | To_char (sysdate, 'YYYYMMDD') | ' in select * from matbl ' double.

immediately run sql_cmd;

end;
;;;;;;;;;;;;;;;;;;;;;;;;;

How to fix the sql_cmd assignment statement?

Thank you.

The dual table is not necessary a lot in PL/SQL.
You can simply say:

sql_cmd := 'create table mytbl_' || TO_CHAR(sysdate, 'YYYYMMDD') || ' as select * from mytbl';
dbms_output.put_line (sql_cmd || ' <= sql_cmd');
-- EXECUTE IMMEDIATE sql_cmd;

During the development of the dynamic SQL statements, I suggest that you post the command rather than run it first.
When it seems correct, then a comment instructions EXECUTE IMMEDIATE.
Before the Production code, remove or comment the call to out_line.

Tags: Database

Similar Questions

  • Retrieve and display a result set using the dynamic sql?

    Hi all

    How would display a result set in Oracle using the dynamic SQL? Reason being, the table where I'd retrieve and display the result set is a GLOBAL TEMP TABLE created in a stored procedure. If I try to use the loop as usual, the compiler complains that the table does not exist. This makes sense because the compiler does not recognize the table because it is created dynamically. Here is an example:

    create or replace PROCEDURE maketemptab IS
    sql_stmt VARCHAR2 (500);
    OutputString VARCHAR2 (50);

    BEGIN
    -create temporary table
    sql_stmt: = ' CREATE of TABLE TEMPORARY GLOBAL globtemptab (id NUMBER, col1 VARCHAR2 (50))';
    EXECUTE IMMEDIATE sql_stmt;
    dbms_output.put_line ('... created table ');

    -Insert a row into the temporary table
    sql_stmt: = "INSERT INTO globtemptab values (1, 'some data of a test')';"
    EXECUTE IMMEDIATE sql_stmt;
    dbms_output.put_line ('... inserted row ');

    -Insert a row into the temporary table
    sql_stmt: = ' INSERT INTO globtemptab values (2, "some more test data");
    EXECUTE IMMEDIATE sql_stmt;
    dbms_output.put_line ('... inserted row ');

    -Select the row on temporary table
    sql_stmt: = 'SELECT col1 FROM globtemptab WHERE id = 1';
    EXECUTE IMMEDIATE sql_stmt INTO outputstring;
    dbms_output.put_line ('... selected line: ' | outputstring);

    -drop temporary table
    sql_stmt: = 'DROP TABLE globtemptab;
    EXECUTE IMMEDIATE sql_stmt;
    dbms_output.put_line ('... moved table ');

    -display the result set
    for tabdata loop (select col1 from globtemptab)
    dbms_output.put_line ('... test of recovered data are' | tabdata.col1)
    end loop;
    end;


    In short, how to rewrite the SQL below the comment "to display the result set" using the dynamic sql?

    Thank you
    Amedeo.

    Hello

    Try this:

    CREATE OR REPLACE PROCEDURE maketemptab IS
       sql_stmt     VARCHAR2(500);
       outputstring VARCHAR2(50);
       v_cursor     SYS_REFCURSOR;
       v_col1       VARCHAR2(30);
    BEGIN
       -- create temp table
       sql_stmt := 'CREATE GLOBAL TEMPORARY TABLE globtemptab(id NUMBER, col1 VARCHAR2(50))';
       EXECUTE IMMEDIATE sql_stmt;
       dbms_output.put_line('...table created');
    
       -- insert row into temp table
       sql_stmt := 'INSERT INTO globtemptab values (1, ''some test data'')';
       EXECUTE IMMEDIATE sql_stmt;
       dbms_output.put_line('...row inserted');
    
       -- insert row into temp table
       sql_stmt := 'INSERT INTO globtemptab values (2, ''some more test data'')';
       EXECUTE IMMEDIATE sql_stmt;
       dbms_output.put_line('...row inserted');
    
       -- select row from temp table
       sql_stmt := 'SELECT col1 FROM globtemptab WHERE id=1';
       EXECUTE IMMEDIATE sql_stmt
          INTO outputstring;
       dbms_output.put_line('...row selected: ' || outputstring);
    
       OPEN v_cursor FOR 'SELECT col1 FROM globtemptab';
    
       LOOP
          FETCH v_cursor
             INTO v_col1;
          EXIT WHEN v_cursor%NOTFOUND;
          dbms_output.put_line('...test data retrieved is' || v_col1);
       END LOOP;
       CLOSE v_cursor;
    
       -- drop temp table
       sql_stmt := 'DROP TABLE globtemptab';
       EXECUTE IMMEDIATE sql_stmt;
       dbms_output.put_line('...table dropped');
    END;
    /
    

    Kind regards

  • Tables created in a stored procedure cannot be used with dynamic SQL? The impact?

    There is a thread on the forum which explains how to create tables within a stored procedure (How to create a table in a stored procedure , however, it does create a table as such, but not how to use it (insert, select, update, etc.) the table in the stored procedure.) Looking around and in the light of the tests, it seems that you need to use dynamic SQL statements to execute ddl in a stored procedure in Oracle DB. In addition, it also seems that you cannot use dynamic SQL statements for reuse (insert, select, update, etc.) the table that was created in the stored procedure? Is this really the case?

    If this is the case, I am afraid that if tables cannot be 'created and used"in a stored procedure using the dynamic SQL, as is the case with most of the servers of DB dynamic SQL is not a part of the implementation plan and, therefore, is quite expensive (slow). This is the case with Oracle, and if yes what is the performance impact? (Apparently, with Informix, yield loss is about 3 - 4 times, MS SQL - 4 - 5 times and so on).

    In summary, tables created within a stored procedure cannot be 'used' with dynamic SQL, and if so, what is the impact of performance as such?

    Thank you and best regards,
    Amedeo.

    Published by: AGF on March 17, 2009 10:51

    AGF says:
    Hi, Frank.

    Thank you for your response. I understand that the dynamic SQL is required in this context.

    Unfortunately, I am yet to discover "that seeks to" using temporary tables inside stored procedures. I'm helping a migration from MySQL to Oracle DB, and this was one of the dilemmas encountered. I'll post what is the attempt, when more.

    In Oracle, we use [global temporary Tables | http://www.psoug.org/reference/OLD/gtt.html?PHPSESSID=67b3adaeaf970906c5e037b23ed380c2] aka TWG these tables need only be created once everything like a normal table, but they act differently when they are used. The data inserted in TWG will be visible at the session that inserted data, allowing you to use the table for their own temporary needs while not collide with them of all sessions. The data of the TWG will be automatically deleted (if not deleted programmatically) when a) a commit is issued or b) the session ends according to the parameter that is used during the creation of the TWG. There is no real need in Oracle to create tables dynamically in code.

    I noticed that many people say that the "Creation of the tables within a stored procedure" is not a good idea, but nobody seems necessarily explain why? Think you could elaborate a little bit? Would be appreciated.

    The main reason is that when you come to compile PL/SQL code on the database, all explicit references to tables in the code must correspond to an existing table, otherwise a djab error will occur. This is necessary so that Oracle can validate the columns that are referenced, the data types of those columns etc.. These compilation controls are an important element to ensure that the compiled code is as error free as possible (there is no accounting for the logic of programmers though ;)).

    If you start to create tables dynamically in your PL/SQL code, so any time you want to reference this table you must ensure that you write your SQL queries dynamically too. Once you start doing this, then Oracle will not be able to validate your SQL syntax, check the types of data or SQL logic. This makes your code more difficult to write and harder to debug, because inevitably it contains errors. It also means that for example if you want to write a simple query to get that one out in a variable value (which would take a single line of SQL with static tables), you end up writing a dynamic slider all for her. Very heavy and very messy. You also get the situation in which, if you create tables dynamically in the code, you are also likely to drop tables dynamically in code. If it is a fixed table name, then in an environment multi-user, you get in a mess well when different user sessions are trying to determine if the table exists already or is the last one to use so they can drop etc. What headache! If you create tables with table names, then variable Dynamics not only make you a lot end up creating (and falling) of objects on the database, which can cause an overload on the update of the data dictionary, but how can ensure you that you clean the tables, if your code has an exception any. Indeed, you'll find yourself with redundant tables lying around on your database, may contain sensitive data that should be removed.

    With the TWG, you have none of these issues.

    Also, what is the impact on the performance of the dynamic SQL statements in Oracle? I read some contrasting opinions, some indicating that it is not a lot of difference between static SQL and SQL dynamic in more recent versions of Oracle DB (Re: why dynamic sql is slower than static sql is this true?)

    When the query runs on the database, there will be no difference in performance because it is just a request for enforcement in the SQL engine. Performance problems may occur if your dynamic query is not binding variable in the query correctly (because this would cause difficult analysis of the query rather than sweet), and also the extra time, to dynamically write the query running.

    Another risk of dynamic query is SQL injection which may result in a security risk on the database.

    Good programming will have little need for the tables of dynamically created dynamically or SQL.

  • Is it possible to use the dynamic link twice? (from creation to AE)

    I made my edit in Premiere Pro (SC6). During my work I had to use the dynamic effects as a stabilizer of the chain link. Now, I'm finished with the work on the creation and would like to redo the calibration color effects. But now, when I import the entire Premiere Pro project in AE, all videos I have already related before, don't work/game more in AE. I also tried to use dynamic linking again rather than the import option. But it's the same problem.

    Is there a workflow to publish excerpts from the first sequence in after effects by dynamic links, and then when I got there also change the whole first sequence in After Effects?

    Maybe I should do in a sense the next time? What would you suggest to do in this case?

    Thank you

    Philippe

    You cannot create cyclic connections. The clips using DL already should be rendered correctly before being able to use the DL on the entire sequence.

    Mylenium

  • The USE of dynamic SQL clause

    Hi all
    I'm moving a table as a variable in dynamic SQl but with no result. Suppose that I it running on HR diagram example:
    declare
    sql_state varchar(100);
    hire_date date;
    temp_table varchar(9):='employees';
    
    begin
    sql_state:= 'select hire_date from :1 where employee_id=206';
    
    execute immediate sql_state into hire_date using temp_table;
    dbms_output.put_line('hire_date is '||hire_date);
    end; 
    
    declare
    *
    ERROR at line 1:
    ORA-00903: invalid table name
    ORA-06512: at line 9
    I get this error of invalid table name without knowing what was read for the variable. Any advice?

    Best regards
    Val

    Hi Valerie,

    To add to what Peter, said

    "Binding" values in a query is done for a specific purpose, and this purpose is so that the optimizer can use the same query as the previous execution plan runs the query, which prevent it from having to analyze the hard the query each time. A query execution plan is based on the tables and columns are presented in the query, but with respect to the actual "values" of these columns, they are unlikely to change the execution plan. So, to keep the same execution plan, the query must seem identical (in terms of a query string) like the previous series, so if you want the same query, but just with different values, they can be replaced with bind variables (these things have a ': ' character) and then the values passed in the query, when it is run.

    Now, if Oracle were to allow you to link in the names of objects, such as tables, this means that it could not use the previous execution plans, because he doesn't know until run time what tables will be consulted. Therefore, it would be useless link in the values of the query and it would be just as quick to implement your query string by concatenating all the values inside rather than link them. Considering that a query is parsed first and then the values in it, then it cannot be analyzed if the tables are not known everything first. (Take a look at how queries are formed and variables when you use the DBMS_SQL package).

    So the key thing to remember is that, when it comes to bind variables, you can bind only the 'values', not 'objects '.

  • Error when using native dynamic SQL

    Please can someone help me understand what's wrong with my code.

    Code:

    create or replace procedure p1 (name varchar2)

    as

    Start

    run immediately "select * from ' |" name;

    end;

    /

    Goal: Just to test the native dynamic SQL code using a placeholder.

    COmpliation:

    SQL > create or replace procedure p1 (name varchar2)

    2 as

    3

    4 start

    5 run immediately "select * from ' |" name;

    6 end;

    7.

    Created procedure.

    Error:

    SQL > exec p1 ('employees');

    BEGIN p1 ('employees'); END;

    *

    ERROR on line 1:

    ORA-00923: THE KEYWORD not found where expected

    ORA-06512: at "HR. "P1", line 5

    ORA-06512: at line 1

    SQL >

    You need a space after the clause 'from', like this:

    run immediately "select * from ' |" name;

  • How to pass the Record of entry to the dynamic SQL Code

    Hi all

    I am trying to run under Oracle applications API on the remote database using DB Link. I try to run using dynamic SQL. Part of the code is given below.

    DECLARE

    l_batch_info_rec wsh_picking_batches_pub.batch_info_rec;

    l_rule_id NUMBER;

    l_rule_name VARCHAR2 (240);

    l_batch_prefix VARCHAR2 (240);

    BEGIN

    l_batch_info_rec.document_set_id: = v_document_set_id;

    l_batch_info_rec.order_type_id: = v_order_type_id;

    l_batch_info_rec. Default_Stage_Subinventory: = v_default_stage_subinventory;

    l_batch_info_rec.pick_grouping_rule_id: = v_pick_grouping_rule_id;

    l_batch_info_rec.pick_sequence_rule_id: = v_pick_sequence_rule_id;

    l_batch_info_rec.autopack_level: = v_autopack_level;

    l_batch_info_rec.autopack_flag: = v_autopack_flag;

    l_batch_info_rec.ac_delivery_criteria: = v_ac_delivery_criteria;

    l_batch_info_rec.backorders_only_flag: = v_backorders_only_flag;

    l_batch_info_rec.existing_rsvs_only_flag: = v_existing_rsvs_only_flag;

    l_batch_info_rec.customer_id: = v_customer_id;

    l_batch_info_rec.order_header_id: = v_header_id;

    l_batch_info_rec.from_scheduled_ship_date: = NULL;

    l_batch_info_rec.organization_id: = v_organization_id;

    l_batch_info_rec.include_planned_lines: = v_include_planned_lines;

    l_batch_info_rec.autocreate_delivery_flag: = v_autocreate_deliveries_flag;

    l_batch_info_rec.autodetail_pr_flag: = v_autodetail_pr_flag;

    l_batch_info_rec.allocation_method: = 'I ';

    l_batch_info_rec.pick_from_locator_id: = NULL;

    l_batch_info_rec.auto_pick_confirm_flag: = 'n';         -The value manually to run Transact order

    l_batch_info_rec.autopack_flag: = 'n';         -Manually configure to perform the manual packaging

    l_rule_id: = NULL;

    l_rule_name: = NULL;

    l_batch_prefix: = NULL;

    v_sqlstmt1: = ' START

    wsh_picking_batches_pub.create_batch' | g_db_link | "(1.0,

    fnd_api.g_true,

    fnd_api.g_true,

    : l_return_status,.

    : l_msg_count,.

    : l_msg_data,.

    : l_rule_id,.

    : l_rule_name,.

    : l_batch_info_rec,.

    : l_batch_prefix,.

    : p_new_batch_id

    );

    END;';

    --

    EXECUTE IMMEDIATE V_sqlstmt1

    With the HELP OF THE l_return_status,.

    ON l_msg_count,.

    ON l_msg_data,.

    BY l_rule_id,

    BY l_rule_name,

    BY l_batch_info_rec,

    BY l_batch_prefix,

    OUT p_new_batch_id;

    --

    END;

    After you run this script, I get below error "PLS-00457: expressions must be SQL types ' for variable l_batch_info_rec which is of type record. can someone please guide me how can I pass variable type dynamic SQL record.

    Thank you

    Priyanka

    Food for thought:

    On remote db:

    SQL > create or replace
    package 2 pkg
    3 is
    4 type r_type is (record
    Number 5,
    6 name varchar2 (10)
    7                            );
    (p) 8 procedure
    9 p_rec in r_type,
    10 p_out out varchar2
    11                  );
    12 end;
    13.

    Package created.

    SQL > create or replace
    package 2 body pkg
    3 is
    4 procedure p)
    5 p_rec in r_type,
    6 p_out out varchar2
    7                  )
    8 is
    9 start
    10 p_out: = "ID = ' |" p_rec.ID | 'Name =' | p_rec. Name;
    11 end;
    12 end;
    13.

    Package body created.

    SQL >

    On local db:

    SQL > set serveroutput on
    SQL > declare
    v_rec 2 pkg.r_type@pdb1sol12;
    3 v_out varchar2 (50);
    4 start
    v_rec.ID 5: = 1;
    6 v_rec.name: = 'XXX ';
    7 immediate execution"
    8                        begin
    9 pkg.p@pdb1sol12 (: 1,: 2);
    10                        end;'
    11 using v_rec,
    12 v_out;
    13 dbms_output.put_line (v_out);
    14 end;
    15.
    using v_rec;
    *
    ERROR on line 11:
    ORA-06550: line 11, column 20:
    PLS-00457: expressions must be SQL types
    ORA-06550: line 7, column 5:
    PL/SQL: Statement ignored

    SQL > declare
    2 number of v_id: = 1;
    3 v_name varchar2 (10): = 'XXX ';
    4 v_out varchar2 (50);
    5. start
    6 immediate execution"
    7 report
    8 v_rec pkg.r_type@pdb1sol12.
    9                        begin
    10                            v_rec.id  := :1;
    11 v_rec.name: =: 2;
    12 pkg.p@pdb1sol12 (v_rec,: 3);
    13                        end;'
    14 using v_id,
    15 in v_name,
    16 v_out;
    17 dbms_output.put_line (v_out);
    18 end;
    19.
    ID = 1 name = XXX

    PL/SQL procedure successfully completed.

    SQL >

    SY.

  • Need to check delays in update of 1000 lines using the PL/SQL procedure.

    Hi all

    I'm new to PL/SQL. I need your help to build a procedure that executes the following statement and follows the time of update of 1000 rows. This is to check the performance of the database. I need to print the timestamp of start before the update and end timestamp after update. I need to do for the 1000 lines. The statement that will be used in the procedure is:

    SELECT

    'UPDATE XXAFL_MON_FACTS_F SET TASK_WID =' | NVL (TO_CHAR (TASK_WID), 'NULL') |', EXECUTION_PLAN_WID =' | NVL (TO_CHAR (EXECUTION_PLAN_WID), 'NULL').

    ', DETAILS_WID =' | NVL (TO_CHAR (DETAILS_WID), 'NULL') |', SOURCE_WID =' | NVL (TO_CHAR (SOURCE_WID), 'NULL') |', TARGET_WID = ' | NVL (TO_CHAR (TARGET_WID), 'NULL').

    ', RUN_STATUS_WID =' | NVL (TO_CHAR (RUN_STATUS_WID), 'NULL') |', SEQ_NUM =' | NVL (TO_CHAR (SEQ_NUM), 'NULL') |', NAME = "' | NVL (TO_CHAR (NAME), 'NULL').

    "', NO_POSITION =" ' | NVL (TO_CHAR (INSTANCE_NUM), e ') | " ', INSTANCE_NAME = "' | NVL (TO_CHAR (INSTANCE_NAME), 'NULL').

    "', TYPE_CD =" ' | NVL (TO_CHAR (TYPE_CD), e ') | " ', STATUS_CD = "' | NVL (TO_CHAR (STATUS_CD), e ') | " ', START_TS =' | NVL (TO_CHAR (START_TS), 'NULL').

    ', END_TS =' | NVL (TO_CHAR (END_TS), 'NULL') |', DURATION = ' | NVL (TO_CHAR (DURATION), 'NULL') |', STATUS_DESC = "' | NVL (TO_CHAR (STATUS_DESC), 'NULL').

    "', DBCONN_NAME =" ' | NVL (TO_CHAR (DBCONN_NAME), e ') | " ', SUCESS_ROWS =' | NVL (TO_CHAR (SUCESS_ROWS), 'NULL').

    ', FAILED_ROWS =' | NVL (TO_CHAR (FAILED_ROWS), 'NULL') |', ERROR_CODE = ' | NVL (TO_CHAR (ERROR_CODE), 'NULL') |', NUM_RETRIES =' | NVL (TO_CHAR (NUM_RETRIES), 'NULL').

    ', READ_THRUPUT =' | NVL (TO_CHAR (READ_THRUPUT), 'NULL') |', LAST_UPD = ' | NVL (TO_CHAR (LAST_UPD), 'NULL') |', RUN_STEP_WID = "' | NVL (TO_CHAR (RUN_STEP_WID), 'NULL').

    "', W_INSERT_DT = ' | NVL (TO_CHAR (W_INSERT_DT), 'NULL') |', W_UPDATE_DT = ' | NVL (TO_CHAR (W_UPDATE_DT), 'NULL').

    ', START_DATE_WID =' | NVL (TO_CHAR (START_DATE_WID), 'NULL') |', END_DATE_WID = ' | NVL (TO_CHAR (END_DATE_WID), 'NULL') |', START_TIME =' |

    NVL (TO_CHAR (START_TIME), 'NULL') |', END_TIME =' | NVL (TO_CHAR (END_TIME), 'NULL'). "WHERE INTEGRATION_ID ="' | INTEGRATION_ID | " « ; »  OF XXAFL_MON_FACTS_F;

    The above query creates instructions of update that must be executed 1000 times and the time required to update the 1000 lines should be followed.

    Thanks in advance!

    Code horribly wrong!

    Why this approach?

    Dynamic SQL is almost NEVER needed in PL/SQL. And if you think it's necessary and taking into account what is displayed as being problems here, you have a 99% chance of being wrong.

    This 1% where dynamic SQL is necessary, he will WITH bind variables to create shareable SQL, decrease memory requests, decrease the likelihood of a fragmented shared reel and decrease the burning CPU cycles on hard analysis.

    An example below. Your approach is the 1st. One that is slower than the correct approach to 37 (x_!) ...

    SQL> create table t ( n number );
    
    Table created.
    
    SQL>
    SQL> var ITERATIONS number;
    SQL> exec :ITERATIONS := 100000;
    
    PL/SQL procedure successfully completed.
    
    SQL>
    SQL>
    SQL> TIMING START "INSERTs using Hard Parsing"
    SQL> declare
      2          i      integer;
      3  begin
      4          for i in 1..:ITERATIONS
      5          loop
      6                  execute immediate 'insert into t values ('||i||')';
      7          end loop;
      8          commit;
      9  end;
    10  /
    
    PL/SQL procedure successfully completed.
    
    SQL> TIMING SHOW
    timing for: INSERTs using Hard Parsing
    Elapsed: 00:02:00.33
    SQL>
    SQL> TIMING START "INSERTs using Soft Parsing"
    SQL> declare
      2          i      integer;
      3  begin
      4          for i in 1..:ITERATIONS
      5          loop
      6                  execute immediate 'insert into t values ( :1 )' using i;
      7          end loop;
      8          commit;
      9  end;
    10  /
    
    PL/SQL procedure successfully completed.
    
    SQL> TIMING SHOW
    timing for: INSERTs using Soft Parsing
    Elapsed: 00:00:06.06
    SQL> drop table t;
    
    Table dropped.
    
    SQL> create table t( n number );
    
    Table created.
    
    SQL>
    SQL>
    SQL> TIMING START "INSERTs using a single parse and repeatable statement handle "
    SQL> declare
      2          i      integer;
      3  begin
      4          for i in 1..:ITERATIONS
      5          loop
      6                  insert into t values ( i );
      7          end loop;
      8          commit;
      9  end;
    10  /
    
    PL/SQL procedure successfully completed.
    
    SQL> TIMING SHOW
    timing for: INSERTs using a single parse and repeatable statement handle
    Elapsed: 00:00:04.81
    SQL>
    
  • Separate values for the pre-treatment and results of the comprehensive review (without using the PL/SQL)

    Hi people,
    This year was difficult because it does not clearly justify what I want to achieve. The main reason for me to try this approach is to reduce the time of the performance. I have my program works very well, but since it accesses a view for each student, slows down the performance.

    Purpose of this report: Show all Dates of examination for students, but only to display the results pre and review of the overall assessment on the first line for students.

    Table scripts and INSERT statements:
    create table STUDENT_TB(student_id varchar2(4), last_name varchar2(20), first_name varchar2(20), evaluation_date date);
    create table EXAM_TB(student_id varchar2(4), exam_date date, result number);
    create table EVALUATION_TB(student_id varchar2(4), eval_flag varchar2(1), sampling_date date);
    
    insert into STUDENT_TB values('1001', 'Poppins', 'Mary', to_date('27-SEP-2012', 'DD-MON-YYYY'));
     
    insert into EXAM_TB values('1001', to_date('20-APR-2011', 'DD-MON-YYYY'), 30);
    insert into EXAM_TB values('1001', to_date('20-MAY-2012', 'DD-MON-YYYY'), 39);
    insert into EXAM_TB values('1001', to_date('10-JUL-2012', 'DD-MON-YYYY'), 34);
    insert into EXAM_TB values('1001', to_date('10-SEP-2012', 'DD-MON-YYYY'), 39);
    insert into EXAM_TB values('1001', to_date('01-DEC-2012', 'DD-MON-YYYY'), 82);
     
    insert into evaluation_tb values('1001', null, to_date('22-APR-2011', 'DD-MON-YYYY'));
    insert into evaluation_tb values('1001', 'N', to_date('20-JUL-2012', 'DD-MON-YYYY'));
    insert into EVALUATION_TB values('1001', 'Y', to_date('10-DEC-2012', 'DD-MON-YYYY'));
    Desired output:
    SID     Last Name   First Name   Evaluation Date    Exam Date   Results   Order   Pre Evaluation   Overall Evaluation   Accept?
    ===============================================================================================================================
    1001     Poppins         Mary      27-SEP-12         20-APR-11     30       1           N                       Y            Y
    1001     Poppins         Mary      27-SEP-12         20-MAY-12     39       2
    1001     Poppins         Mary      27-SEP-12         10-JUL-12     34       3
    1001     Poppins         Mary      27-SEP-12         10-SEP-12     39       4
    1001     Poppins         Mary      27-SEP-12         01-DEC-12     82       5
    Business rules:
    The Pre, global assessment and accept it? fields are derived. The area of the pre assessment is derived from the EVALUATION_TBtable. Its the value of eval_flag where sampling_date < = evaluation_date.
    In our example, the pre assessment should be an "n" while the overall assessment must be a 'Y '. The priority is Y-> N-> Null. The Accept flag is set to a 'Y' If a meadow at overall results past of N to Y or a NULL of Y value.

    I have to return all the lines for the student that show the results of the reviews SQL is the following:
    I need to join the view EVALUATION_TB. Simply join them of course would be a resulting vector product in 15 files that I don't want. I tried online (subqueries) but I failed again. Any help would be great!
    I created the column ord_num to maybe help using only this folder to display the results of the assessment.
    select x.student_id, x.last_name, x.first_name, x.evaluation_date,
           m.exam_date, m.result,
           dense_rank() over (partition by x.student_id order by m.exam_date) ord_num
    from
    (
      select  s.student_id, s.last_name, s.first_name, s.evaluation_date
      from    student_tb s
    ) x, exam_tb m
    where x.student_id = m.student_id (+);
    
    SID     Last Name   First Name   Evaluation Date    Exam Date   Results   Order
    ===============================================================================
    
    1001     Poppins     Mary     27-SEP-12     20-APR-11     30     1
    1001     Poppins     Mary     27-SEP-12     20-MAY-12     39     2
    1001     Poppins     Mary     27-SEP-12     10-JUL-12     34     3
    1001     Poppins     Mary     27-SEP-12     10-SEP-12     39     4
    1001     Poppins     Mary     27-SEP-12     01-DEC-12     82     5
    Thank you!

    Published by: Roxyrollers on March 14, 2013 11:37

    Published by: Roxyrollers on March 14, 2013 11:38

    Published by: Roxyrollers on March 14, 2013 12:27

    Published by: Roxyrollers on March 15, 2013 13:43

    Hi Roxyrollers,

    Please check your insert statements before posting. They have syntax errors.

    The following query is to give you the desired result:

    with pre_eval as
    (
       select e.student_id
            , max(e.eval_flag) keep(dense_rank last order by e.sampling_date) eval_flag
         from evaluation_tb e join student_tb s
              on e.student_id=s.student_id
                 and e.sampling_date <= s.evaluation_date
       group by e.student_id
    )
    ,all_eval as
    (
       select e.student_id
            , max(e.eval_flag) keep(dense_rank last order by e.sampling_date) eval_flag
         from evaluation_tb e join student_tb s
              on e.student_id=s.student_id
       group by e.student_id
    )
    , data_with_rank AS
    (
       select s.student_id, s.last_name, s.first_name, s.evaluation_date
            , m.exam_date, m.result
            , dense_rank() over (partition by s.student_id order by m.exam_date) ord_num
         from student_tb s
              left outer join exam_tb m
              on (s.student_id = m.student_id)
    )
    select s.student_id, s.last_name, s.first_name, s.evaluation_date
         , s.exam_date, s.result
         , e.eval_flag as pre_eval
         , a.eval_flag as overall_eval
         , case when a.eval_flag='Y' and e.eval_flag!='Y' then 'Y' end accept
      from data_with_rank s
           left outer join pre_eval e
              on (s.student_id = e.student_id and s.ord_num=1)
           left outer join all_eval a
              on (s.student_id = a.student_id and s.ord_num=1)
    order by s.student_id, s.exam_date;
    
    STUDENT_ID LAST_NAME            FIRST_NAME           EVALUATION_DATE EXAM_DATE     RESULT PRE_EVAL OVERALL_EVAL ACCEPT
    ---------- -------------------- -------------------- --------------- --------- ---------- -------- ------------ ------
    1001       Poppins              Mary                 27-SEP-12       20-APR-11         30 N        Y            Y
    1001       Poppins              Mary                 27-SEP-12       20-MAY-12         39
    1001       Poppins              Mary                 27-SEP-12       10-JUL-12         34
    1001       Poppins              Mary                 27-SEP-12       10-SEP-12         39
    1001       Poppins              Mary                 27-SEP-12       01-DEC-12         82                                                                          
    

    However, is not clear to me why the assessment are related only to the first line in the query.
    The evaluation_tb table is in fact related to student_id and I expect to be connected all lines.

    I've actually linked subqueries pre_eval and all_eval only in line with rank = 1 but I don't understand if that's correct according to business requirements.

    Kind regards.
    Al

    Published by: Alberto Faenza on 14 March 2013 20:29
    ORDER BY added, deleted ord_num output

  • Use the dynamic report with BI Publisher parameters

    Are there tips for reports in BI Publisher? For example, I would use the same report for one person or many people. This would mean that where clause should be added when it is for the individual and is not necessary for the entire population. I don't see a way to dynamically build the report using "Report queries" in the shared components.
    It is easy to build a sql query based on various selection criteria in the Source to a pagethat of the region then gets displayedd on the page but I don't see a lot of flexibility in creating a report with BI Publisher at the Apex.

    How about from the collections?

    Denes Kubicek
    -------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Apress.com/9781430235125
    http://Apex.Oracle.com/pls/OTN/f?p=31517:1
    http://www.Amazon.de/Oracle-Apex-XE-Praxis/DP/3826655494
    -------------------------------------------------------------------

  • How to use the dynamic Action?

    Dear all,

    I use Apex 4.1 worm.

    I need returns the value in the text box item when I select a value in the select list.

    I have a select list item: p1_template_id and a text box to point P1_template_description.
    Code of the selection list
    SELECT TEMPLATE_NAME D, TEMPLATE_ID R FROM TEMPLATE_MAS  ORDER BY TEMPLATE_NAME
    
    Table Name
    
    
    CREATE TABLE  "CRM_CAM_TEMPLATE_MAS" 
       (     "TEMPLATE_ID" VARCHAR2(50) NOT NULL ENABLE, 
         "TEMPLATE_NAME" VARCHAR2(500) NOT NULL ENABLE, 
         "DESCRIPTION" CLOB
          CONSTRAINT "CRM_CAM_TEMPLATE_MAS_PK" PRIMARY KEY ("TEMPLATE_ID") ENABLE
       )
    /
    I want to the DESCRIPTION of the column value for the text box item when I select the select list template ID.

    How can I do this with dynamic Action or in any other way?

    How can I do this?



    Thank you
    CORINE

    Hi Maxence,

    create a dynamic action of the advance,
    Follow the instructions below

    event = change
    selection type = item (s)
    product (s) = p1_template_id
    condition = no requirement

    Action: Execute the PL/SQL Code

    declare

    CLOB v_description;

    Start
    Select v_description from CRM_CAM_TEMPLATE_MAS where category = DESCRIPTION: p1_template_id;
    : P1_template_description: = v_description;
    end;

    Page to Submit elements - p1_template_id
    Page items to return - P1_template_description

    hope you help

    Kind regards
    Jitendra

  • Dynamic recovery for the dynamic sql query

    Hi all

    I want to create a query dynamically and to fetch it in a dynamic cursor record... The structure of the record should be the same as that of the query...
    Can you suggest any method to do this.

    for example

    OPEN < dynamic news > TO < dynamic stmt >;
    LOOP
    FETCH < dynamic news > < DYNAMIC rec >;
    ---
    END LOOP;
    CLOSE < dynamic news >;

    How to declare the rec here dynamic? I wouldn't have the columns in the query in advance either.

    Thank you
    Merz

    Published by: merz Sep 12, 2011 17:02

    Published by: merz Sep 12, 2011 17:03

    Merz says:

    How to declare the rec here dynamic? I wouldn't have the columns in the query in advance either.

    Is not possible. What you describe is called four dynamic sql type. For this type of synamic SQL, you use the DBMS_SQL package.

    SY.

  • Creation of XML report using the PL/SQL stored procedure

    Hi friends,

    I'm working on a report xml with the xml source as a PL/SQL stored procedure.

    I mean the fiscal year indicated in the following link to understand the process:

    http://orclapp.blogspot.com/2012/02/developing-xml-publisher-report-using.html

    In the example shown in the link above, I did not understand the following:

    (1) in the following procedure, setting out "retcode" is not used at all.

    What is the importance of this parameter.

    REPORT PROCEDURE (errbuf OUT VARCHAR2, retcode OUT VARCHAR2, p_product_id in NUMBERS)

    (2) after the xml data are prepared and updates 'l_result' variable Clob, what follows

    Loop is executed. I am not able to understand why the following loop is required.

    LOOP

    EXIT WHEN l_length = l_retrieved;

    IF (l_length - l_retrieved) < 32000

    THEN

    SELECT SUBSTR (l_result, l_retrieved + 1) IN l_xmlstr FROM DUAL;

    l_retrieved: = l_length;

    fnd_file.put_line (fnd_file.output, l_xmlstr);

    ON THE OTHER

    SELECT SUBSTR (l_result, l_retrieved + 1, l_offset)

    IN l_xmlstr

    FROM DUAL;

    l_retrieved: = l_retrieved + l_offset.

    fnd_file.put_line (fnd_file.output, l_xmlstr);

    END IF;

    END LOOP;

    (3) in the example it is not explained how the concurrent program gets the xml data?

    I guess that it is written to a file by using the following line of code:

    fnd_file.put_line (fnd_file.output, l_xmlstr);

    I would be grateful if someone can shed some light in my questions above so that I can well understand the process.

    Thanks and greetings

    Hawker

    Hi 32000 in the code is a 'safe' than 32767 available max mesh, loops is intended to get around the entire thing into pieces that can be managed within the limits of the data type.

    BTW; If you are in the following Oracle e-business, you can also use the Oracle reports very simply to create the XML output.

    If you have reports developer all you need to do is put raw sql (create XML without any "Fireworks") in the SQL report and then set reporting in XML format in the definition of program in Oracle e-business.

    Best regards

    Robert.

  • How to use the pl/sql procedure

    Hi all,

    How to use pl/sql packages and especially in what situations we are pl/sql, which is the cause of the procedure. Please explain with precision using small example.

    Thanks and greetings

    RAM

    I could tell this at a very high level.

    PL/SQL's procedural extension to SQL. SQL (structured query language) has no procedural capacity. They are executed as a stand-alone statement. When you want to generate a process flow with several SQL statement that you need to have a procedural language that could accommodate your SQL. PL/SQL is something similar to Java and Dot Net in this aspect. Said that PL/SQL is Oracle DB. This has some advantages. The most important thing is that when you have your SQL in PL/SQL oracle maintains its reliance on the object. Any database oracle related so you want to build, then you can consider to PL/SQL as the best way to use process flows.

    PL/SQL provides various methods such as the PROCEDURE, FUNCTION and the PACKAGE. The only thing that race stands is in its ability to modularize your code. So, using the package you can create process workflows that is modular and easy to understand.

  • use the ansi join syntax

    From what I've been reading is preferable to use the new syntax (don't know how is it news)

    The ANSI join syntax was new to Oracle in Oracle 8i in 1998 - that is 15 years old.

    It can produce more readable code and is also much more readable and less human-source of errors for outer joins.

    The ANSI format allows an outer join between several tables in a way the old (+) syntax specific to oracle does not and introduced the JOIN FULL OUTER you should use very rarely.

    You should not use NATURAL JOIN in code - add columns not related to the tables involved can give very different results.

    There have not been important bugs for ANSI joins in Oracle from Oracle 10.2 set up about 8 years ago.

    As Paul says, the part on should be the criteria to join between the tables. Did clause should be the filtering of the joined tables.

    So assuming start_date and end_date in_property_id are variable

    SELECT resv_num, unit_date

    OF p_resv_unit ru

    INNER JOIN p_pm_unit_night pun

    ON pun.resv_unit_id = ru.resv_unit_id

    WHERE pun.property_id = in_property_id

    AND pun.unit_date BETWEEN start_date AND end_date

    AND pun.pm_unit_num = cvUnitNum;

    If start_date and end_date are the columns of p_resv_unit the query would be:

    SELECT resv_num, unit_date

    OF p_resv_unit ru

    INNER JOIN p_pm_unit_night pun

    ON pun.resv_unit_id = ru.resv_unit_id AND pun.unit_date BETWEEN ru.start_date AND ru.end_date

    WHERE pun.property_id = in_property_id

    AND pun.pm_unit_num = cvUnitNum;

    Inner join queries work with criteria in the wrong place, but they are harder to read. Outer joins do not work unless you put the criteria in the right place.

Maybe you are looking for