Help on running immediate dynamic Sql

Hi all

When I run the following Pl/SQL, nothing happens

I want to pass the array as a result of procedure
DECLARE
SQL_STMT      VARCHAR2(1000);
BEGIN
SQL_STMT  := 'Select '|| '''populate_table_test(''' || '|| chr(39)||id_name||chr(39)||' ||''','''||'|| chr(39)||attribute1||chr(39)||' ||''','''||'|| chr(39)||attribute2||chr(39)||' ||''');'''||' from table_test1';
dbms_output.put_line(sql_stmt);
execute immediate sql_stmt;
Exception when others then
dbms_output.put_line(sqlerrm);

end;
/
SQL> ed
Wrote file afiedt.buf

  1  Select 'populate_table_test('|| chr(39)||id_name||chr(39)||','||
  2  chr(39)||attribute1||chr(39)||','|| chr(39)||attribute2||chr(39)||');' from
  3* table_test
SQL> /

'POPULATE_TABLE_TEST('||CHR(39)||ID_NAME||CHR(39)||','||CHR(
------------------------------------------------------------
populate_table_test('AAA','AA','AA');
populate_table_test('AAA','AA','AA');
CREATE
  TABLE TABLE_TEST1
  (
    "ID_NO"      NUMBER(10,0)     ,
    "ID_NAME"    VARCHAR2(10 BYTE),
    "ATTRIBUTE1" VARCHAR2(10 BYTE),
    "ATTRIBUTE2" VARCHAR2(10 BYTE)
  );


Insert into TABLE_TEST1 (ID_NO,ID_NAME,ATTRIBUTE1,ATTRIBUTE2) values (null,'AAA','AA','AA');
Insert into TABLE_TEST1 (ID_NO,ID_NAME,ATTRIBUTE1,ATTRIBUTE2) values (null,'AAA','AA','AA');
commit;
CREATE TABLE TABLE_TEST
(ID_NO NUMBER(10) , 
id_NAME VARCHAR2(10) , 
ATTRIBUTE1 VARCHAR2(10), 
ATTRIBUTE2 VARCHAR2(10)
);

select * from "TABLE_TEST"; 


CREATE OR REPLACE TYPE T_TYPE IS OBJECT ( 
id_NAME VARCHAR2(10), 
ATTRIBUTE1 VARCHAR2(10), 
ATTRIBUTE2 VARCHAR2(10) 
) ;

Create or replace  type TB_T_TYPE as varray(200) of  T_TYPE ;


CREATE OR REPLACE
PROCEDURE POPULATE_TABLE_TEST (EXAMPLE IN TB_T_TYPE) AS 

begin 

FOR I IN 1..EXAMPLE.COUNT LOOP
DBMS_OUTPUT.PUT_LINE(TREAT(EXAMPLE(I) AS T_TYPE).ID_NAME);
DBMS_OUTPUT.PUT_LINE(TREAT(EXAMPLE(I) AS T_TYPE).ATTRIBUTE1);
DBMS_OUtPUT.PUT_LINE(TREAT(EXAMPLE(I) AS T_TYPE).ATTRIBUTE2);
insert into TABLE_TEST(id_name,attribute1,attribute2) 
values (treat(example(i) as T_TYPE).id_NAME, 
treat(example(i) as T_TYPE).ATTRIBUTE1, 
treat(example(i) as T_TYPE).ATTRIBUTE2 
);
end loop;
end; 
Select ' populate_table_test ('| chr (39) |) AMXX% | Chr (39) | «, » ||
Chr (39) | attribute1 | Chr (39) | «, » || Chr (39) | attribut2 | Chr (39) |') ;' Of
table_test

Published by: user1849 on November 30, 2011 12:40

Published by: user1849 on November 30, 2011 13:18

user1849 wrote:
Justin Merci for your comments

Can you let me know why this isn't the Insert for 2 folders

any help is appreciate

I think that I did in my first answer about 40 minutes ago. If something in this answer would have been absurd, I'd be happy to try to clarify if you can let me know what the parties are and are not clear.

Justin

Tags: Database

Similar Questions

  • Need urgent help to run the PL/SQL function when executing is having IN OUT type of table.

    Created under object types.

    (1) CREATE OR REPLACE TYPE INVENTORY_ITEM_ID_TAB IN THE TABLE OF THE NUMBER;

    --

    (2) CREATE OR REPLACE TYPE ITEM_TYPE_REC AS OBJECT (ITEM_ID ISSUE

    , ITEM_VALUE VARCHAR2 (4000)

    );

    --

    (3) CREATE OR REPLACE ITEM_TYPE_TAB AS TABLE ITEM_TYPE_REC;

    The function code

    FUNCTION XXqp_get_pts_model)

    p_item_id_tab IN INVENTORY_ITEM_ID_TAB)

    RETURN ITEM_TYPE_TAB

    IS

    l_ITEM_TYPE_TAB ITEM_TYPE_TAB: = ITEM_TYPE_TAB();

    ln_org_id NUMBER;

    BEGIN

    L_ITEM_TYPE_TAB. DELETE;

    l_ITEM_TYPE_TAB. EXTEND;

    LN_ORG_ID: = FND_PROFILE. VALUE ("QP_ORGANIZATION_ID");

    SELECT ITEM_TYPE_REC (EGO. INVENTORY_ITEM_ID,

    C_EXT_ATTR10)

    LOOSE COLLECTION l_ITEM_TYPE_TAB

    To ego_mtl_sy_items_ext_b ego.

    ego_fnd_dsc_flx_ctx_ext ag,

    fnd_descr_flex_column_usages atr

    WHERE ego.attr_group_id = ag.attr_group_id

    AND ag.descriptive_flex_context_code = atr.descriptive_flex_context_code

    AND ag.application_id = atr.application_id

    AND ag.descriptive_flex_context_code = 'XXEGO_PRICE_INFO. '

    AND atr.end_user_column_name = 'XXEGO_PLAN_TO_SELL. '

    AND IN ego.inventory_item_id

    (SELECT

    (SELECT inventory_item_id

    OF MTL_SYSTEM_ITEMS_B

    WHERE segment1 = A.item_name

    AND organization_id = ln_org_id

    ) inventory_item_id

    OF geqp_apl_pricelist_sku_tbl A

    )

    AND ego.organization_id = ln_org_id;

    RETURN l_ITEM_TYPE_TAB;

    end XXqp_get_pts_mode;

    Below the code works fine BUT when calling function in pl/sql dynamic mode it does not underneath.

    ---------------------------

    Labour Code

    ---------------------------

    DECLARE

    CURSOR c1 IS SELECT (SELECT inventory_item_id

    OF mtl_system_items_b

    WHERE segment1 = A.item_name

    AND organization_id = 83

    ) INVENTORY_ITEM_ID

    of XXqp_apl_pricelist_sku_tbl;

    L_INVENTORY_ITEM_ID_TAB INVENTORY_ITEM_ID_TAB: = INVENTORY_ITEM_ID_TAB();

    L_ITEM_TYPE_TAB ITEM_TYPE_TAB: = ITEM_TYPE_TAB();

    LV_CHAR VARCHAR2 (1000);

    LV_QRY VARCHAR2 (1000);

    BEGIN

    --

    l_inventory_item_id_tab. DELETE;

    OPEN c1;

    LOOP

    C1 FETCH BULK COLLECT INTO L_INVENTORY_ITEM_ID_TAB;

    OUTPUT WHEN c1% NOTFOUND;

    END LOOP;

    CLOSE C1;

    SELECT XXQP_APL_ELIG_TCA_DEV_PKG. XXQP_GET_PTS_MODEL (L_INVENTORY_ITEM_ID_TAB)

    IN L_ITEM_TYPE_TAB

    FROM DUAL;

    --

    FOR j IN 1.l_ITEM_TYPE_TAB. COUNTY

    LOOP

    DBMS_OUTPUT. PUT_LINE (L_ITEM_TYPE_TAB (J). ITEM_VALUE);

    END LOOP;

    END;

    ---------------------------

    Code does not

    ---------------------------

    DECLARE

    CURSOR c1 IS SELECT (SELECT inventory_item_id

    OF mtl_system_items_b

    WHERE segment1 = A.item_name

    AND organization_id = 83

    ) INVENTORY_ITEM_ID

    of GEqp_apl_pricelist_sku_tbl;

    LV_QRY VARCHAR2 (1500);

    L_INVENTORY_ITEM_ID_TAB INVENTORY_ITEM_ID_TAB: = INVENTORY_ITEM_ID_TAB();

    l_ITEM_TYPE_TAB ITEM_TYPE_TAB: = ITEM_TYPE_TAB();

    BEGIN

    l_inventory_item_id_tab. DELETE;

    OPEN c1;

    LOOP

    C1 FETCH BULK COLLECT INTO L_INVENTORY_ITEM_ID_TAB;

    OUTPUT WHEN c1% NOTFOUND;

    END LOOP;

    CLOSE C1;

    LV_QRY: = ' START: 1: = XXQP_APL_ELIG_TCA_DEV_PKG. XXQP_GET_PTS_MODEL(:2); END;';

    DBMS_OUTPUT. Put_line ('-> lv_qry' |) LV_QRY);

    IMMEDIATE EXECUTION in USING LV_QRY IN l_INVENTORY_ITEM_ID_TAB, OUT l_ITEM_TYPE_TAB;

    END;

    Kindly help me out here in the execution of the function from PL/SQL runtime which is having IN OUT type of table.

    Kind regards

    Devendra

    Wrong code

    IMMEDIATE EXECUTION in USING LV_QRY IN l_INVENTORY_ITEM_ID_TAB, OUT l_ITEM_TYPE_TAB ;

    When I use the code below, able to perform the function without any error.

    EXECUTE LV_QRY IMMEDIATELY WITH THE HELP OF THE L_ITEM_TYPE_TAB, IN L_INVENTORY_ITEM_ID_TAB;

    Thank you all for your help in fixing the code.

  • 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.

  • Dynamic SQL problem

    Hello

    I'm trying to run the dynamic SQL string. It generates an error
    ORA-00932: inconsistent data types: expected - was -.

    Here is the code:

    CREATE OR REPLACE PROCEDURE test_prc (d_output on sys_refcursor)
    IS
    l_sql VARCHAR2 (1000);
    l_deptid NUMBER (10): = 30;
    BEGIN
    l_sql: = ' select empno, ename from emp where ename = "DISTRICT" and deptno =: l_deptid';
    EXECUTE IMMEDIATE l_sql IN d_output USING l_deptid;
    EXCEPTION
    WHILE OTHERS THEN
    dbms_output.put_line ('Err > ' |) SQLERRM);
    END;
    /


    Set serveroutput on

    declare
    t sys_refcursor;
    Start
    test_prc (t);
    end;
    /

    ERR > ORA-00932: inconsistent data types: expected - was -.

    can you please tell me where I have to fix the code?

    Thank you and best regards,
    RSD

    Hello

    I think the output you get you want to switch to a ref cursor You can try this.

    -not tested

    EXECUTE IMMEDIATE l_sql IN d_output USING l_deptid;

    BEGIN
    Ref_cur OPEN FOR l_sql using l_deptid;

    -I hope this is your test program that you use no parameter for the SQL code.

    Thank you

  • REF cursor in sql dynamic help to run immediately

    Hello

    How can we get the Ref cursor out a dynamic sql statement by executing immediate proceedings
    for example, immediately run ' open CROR for select * from dynamicTable'

    in this area, CROR is a dynamic cursor and table name is dynamic (known at run time), and we can't write static sql statement.

    Thank you

    I don't know what exactly you are after but here is a sample of what can be done.

    SQL> VAR r REFCURSOR;
    SQL> BEGIN
      2          OPEN :r FOR 'SELECT * FROM DUAL';
      3  END;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SQL> PRINT r
    
    D
    -
    X
    

    You can use the OPEN... FOR education with a dynamic string.

  • Helps the function 'Running background PL/SQL'

    Hello everyone.

    I come here for assistance with the service running background PL/SQL within the APEX. Here's a background of what I have to do.

    Background:

    Currently, I have just a page with a button above and some display boxes. The button calls a process flow Oracle Warehouse Builder (OWB) named RUN_ADJ_VAR and does what he must do. That works fine if my button simply calls the PL/SQL code of

    BEGIN

    ETQUEW. RUN_ADJ_VAR;

    END;

    Now that I know that the process flow and the button are working fine, I need to make the page "intelligently" by limiting multiple submissions until the process ends.

    What I need:

    I need assistance with running background PL/SQL function. My work has been running for a while and I need to run in the background and provide a status of the user, while restricting another presentation by the user. From what I've read here:

    Advanced programming techniques

    According to me, that this DBMS wrapper function, it's what I use.

    What I have so far:

    Using the API and example, I made my own attempt at this and it does not work. Here's what I have so far:

    [code]

    DECLARE

    v_sql VARCHAR2 (32767).

    BEGIN

    v_sql: = '

    BEGIN

    ETQUEW. RUN_ADJ_VAR;

    APEX_PLSQL_JOB. () UPDATE_JOB_STATUS

    P_JOB = >: APP_JOB,.

    P_STATUS = > "done");

    END IF;

    END;

    ';

    : P1_JOB: = APEX_PLSQL_JOB. () SUBMIT_PROCESS

    p_sql = > v_sql,

    p_when = > sysdate,.

    p_status = > 'Submit');

    : P1_POST_DONE: = 'Y ';

    END;

    [/ code]

    What the code so far:

    The code seems to ignore the first part and does work through the underlined only section. The work never appears to run and the button can be clicked several times.

    Other Options:

    I don't know if the function from PL/SQL background running is the only way to do that. The work is performed for about 15 minutes so I can't use a javascript script wait indicator since that will expire because of the hours of work. I searched all over the internet and forums and I feel I have exhausted all my options. I am very new to the APEX and PL/SQL in general, so your help is very appreciated.

    Thank you!!!

    Hello Konrad B.!

    Try to rewrite the code as shown below:

    DECLARE

    v_sql VARCHAR2 (32767).

    BEGIN

    v_sql: = '

    BEGIN

    ETQUEW. RUN_ADJ_VAR;

    END;

    ';

    : P1_JOB: = apex_plsql_job.submit_process (v_sql);

    END;

    Assume that P1_JOB - question on the page. After submitting the job, this point will be containing number of jobs. The job number,
    username (can get APP_USER) and workspace id (can get WORKSPACE_ID) you can check the status
    view of working level (field SYSTEM_STATUS) APEX_PLSQL_JOBS:

    SELECT SYSTEM_STATUS
    FROM APEX_PLSQL_JOBS
    WHERE JOB = :P1_JOB
    AND ANDUSER = :APP_USER
    AND SECURITY_GROUP_ID = :WORKSPACE_ID
    

    So you can make conditional button, selected example condition "NOT Exists (SQL query returns no rows)" and in the expression type:

    Select 1 from apex_plsql_jobs

    where employment =: P1_JOB

    and end user =: APP_USER

    and security_group_id =: WORKSPACE_ID

    and system_status in ("in PROGRESS", "SUBMITTED")

    If you must run the job for the user, then button will not be returned.

  • Help with dynamic SQL

    Hello

    I have the following function that works well:

    FUNCTION to CREATE or REPLACE Get_Partition_Name (sTable VARCHAR2, iImportIndex INTEGER)
    RETURN VARCHAR2 IS

    cursor c is select A.partition_name from (select table_name, nom_partition,
    ExtractValue)
    dbms_xmlgen.
    () getxmltype
    "Select high_value of all_tab_partitions where table_name =" '. "
    || table-name
    || ' ' and table_owner = "'
    || TABLE_OWNER
    || ' ' and nom_partition = "'
    || nom_partition
    || ''''),
    import_value of all_tab_partitions) where table_name sTable = and A.import_value = iImportIndex;
    sPartitionName varchar (20);
    err_num NUMBER;

    BEGIN
    Open c;
    extract the c in sPartitionName;

    IF c % ISOPEN THEN
    C CLOSE;
    END IF;

    RETURN sPartitionName;

    EXCEPTION
    WHILE OTHERS THEN
    err_num: = SQLCODE;
    -Save the error in the log table
    NEWSPAPER. SAVELINE (SQLCODE, SQLERRM);
    END Get_Partition_Name;

    I am trying to replace the dynamic SQL, something like cursor statement (see below), but it's broken. According to me, Miss me some quotes.

    FUNCTION to CREATE or REPLACE Get_Partition_Name (sTable VARCHAR2, iImportIndex INTEGER)
    RETURN VARCHAR2 IS
    TYPE t1 IS REF CURSOR;
    c t1;
    sSql VARCHAR2 (500);
    sPartitionName varchar (20);
    err_num NUMBER;

    BEGIN
    sSql: = ' select A.partition_name from (select table_name, nom_partition,
    ExtractValue)
    dbms_xmlgen.
    () getxmltype
    'select high_value of all_tab_partitions where table_name ="'
    || table-name
    || ' ' and table_owner = "'
    || TABLE_OWNER
    || ' ' and nom_partition = "'
    || nom_partition
    || ''''''),
    text() ") import_value of all_tab_partitions) where table_name =: a and A.import_value =: b';

    C OPEN sSql USING sTable, iImportIndex;
    extract the c in sPartitionName;

    IF c % ISOPEN THEN
    C CLOSE;
    END IF;

    RETURN sPartitionName;

    EXCEPTION
    WHILE OTHERS THEN
    err_num: = SQLCODE;
    -Save the error in the log table
    NEWSPAPER. SAVELINE (SQLCODE, SQLERRM);
    END Get_Partition_Name;
    /

    Please advise,

    Kind regards
    M.R.

    Assuming that the requirement is to find the partition in the table provided with the provided high value and the problem is that dba/all_tab_partitions.high_value is of type long, an alternative solution in the same sense that you already made is as follows. (I just used a slider instead of a function for the simplicity of the demo).

    SQL> var r refcursor
    SQL> set autoprint on
    SQL> declare
      2   ctx dbms_xmlgen.ctxhandle;
      3   v_table_name VARCHAR2(40) := 'LOGMNR_USER$';
      4   v_value      NUMBER       := 100;
      5  begin
      6   ctx := DBMS_XMLGEN.NEWCONTEXT
      7          ('select table_name
      8            ,      partition_name
      9            ,      high_value  hi_val
     10            from   dba_tab_partitions
     11            where  table_name     = :table_name');
     12   dbms_xmlgen.setbindvalue(ctx,'TABLE_NAME',v_table_name);
     13   open:r for
     14   with x as
     15   (select xmltype(dbms_xmlgen.getxml(ctx)) myxml
     16    from   dual)
     17   select extractvalue(x.object_value,'/ROW/TABLE_NAME') table_name
     18   ,      extractvalue(x.object_value,'/ROW/PARTITION_NAME') partition_name
     19   ,      extractvalue(x.object_value,'/ROW/HI_VAL') hi_val
     20   from   x
     21   ,      TABLE(XMLSEQUENCE(EXTRACT(x.myxml,'/ROWSET/ROW'))) x
     22   where  extractvalue(x.object_value,'/ROW/HI_VAL') = v_value;
     23  end;
     24  /
    
    PL/SQL procedure successfully completed.
    
    TABLE_NAME
    -------------------------------------------------------------------------------
    PARTITION_NAME
    -------------------------------------------------------------------------------
    HI_VAL
    -------------------------------------------------------------------------------
    LOGMNR_USER$
    P_LESSTHAN100
    100
    
    SQL> 
    

    I don't know that there are other ways as well. Especially with the XML features, there are normally several ways to skin a cat.

  • How the date can be filled with timestamp in dynamic sql

    Hi all

    Below we have sql

    v_stmt: = ' MERGE IN MTH_EQUIPMENTS_EXT_B ED

    WITH THE HELP OF)

    SELECT TAG_DATA,

    EQUIPMENT_FK_KEY,

    WORKORDER_FK_KEY,

    SEGMENT_FK_KEY,

    SHIFT_WORKDAY_FK_KEY,

    HOUR_FK_KEY,

    ITEM_FK_KEY,

    READ_TIME,

    ATTR_GROUP_ID,

    RECIPE_NUM,

    RECIPE_VERSION,

    NVL (FND_GLOBAL. User_Id,-1) l_updated_by,.

    NVL (FND_GLOBAL. Login_Id,-1) l_last_update_login

    OF MTH_TAG_READINGS_T_STG

    WHERE DB_COL = ' | " ' || v_colname | " ' ||') TS

    WE (';)

    v_stmt: = v_stmt | "ED. EQUIPMENT_PK_KEY = TS. EQUIPMENT_FK_KEY AND

    ED. READ_TIME = TS. READ_TIME AND

    ED. ATTR_GROUP_ID = TS. ATTR_GROUP_ID)

    WHEN MATCHED THEN

    UPDATE

    GAME ED.'. v_colname |' = TS. TAG_DATA,

    ED. LAST_UPDATED_BY = 1, ";

    v_stmt: = v_stmt | "ED. LAST_UPDATE_LOGIN = TS.l_last_update_login

    WHEN NOT MATCHED THEN

    INSERT ('| v_colname |', EXTENSION_ID, EQUIPMENT_PK_KEY, WORKORDER_FK_KEY, SEGMENT_FK_KEY, SHIFT_WORKDAY_FK_KEY, HOUR_FK_KEY, ITEM_FK_KEY, READ_TIME, ATTR_GROUP_ID, LAST_UPDATE_DATE, LAST_UPDATED_BY,';)

    v_stmt: =.

    v_stmt | ("LAST_UPDATE_LOGIN, CREATED_BY, CREATION_DATE, RECIPE_NUM, RECIPE_VERSION)

    VALUES (TS. TAG_DATA, EGO_EXTFWK_S.NEXTVAL, TS. EQUIPMENT_FK_KEY, TS. WORKORDER_FK_KEY, TS. SEGMENT_FK_KEY, TS. SHIFT_WORKDAY_FK_KEY, TS. HOUR_FK_KEY, TS. ITEM_FK_KEY, TS. READ_TIME,';

    v_stmt: = v_stmt | "TS. ATTR_GROUP_ID,' | '''|| SYSDATE | "'| ', 1, TS.l_last_update_login, TS.l_updated_by,'|"' | SYSDATE | " ' ||', TS. RECIPE_NUM, TS. RECIPE_VERSION)';

    EXECUTE IMMEDIATE v_stmt;

    After you run the above SQL last date of update in MTH_EQUIPMENST_EXT_B is filled with sysdate but timestamp is not its always 00:00:00. Can we have timestamp also populated through dynamic sql in the last update date

    Kind regards

    Amrit

    Values to hardcode in the dynamic SQL - never use bind variables:

    v_stmt: = ' MERGE IN MTH_EQUIPMENTS_EXT_B ED

    WITH THE HELP OF)

    SELECT TAG_DATA,

    EQUIPMENT_FK_KEY,

    WORKORDER_FK_KEY,

    SEGMENT_FK_KEY,

    SHIFT_WORKDAY_FK_KEY,

    HOUR_FK_KEY,

    ITEM_FK_KEY,

    READ_TIME,

    ATTR_GROUP_ID,

    RECIPE_NUM,

    RECIPE_VERSION,

    NVL (FND_GLOBAL. User_Id,-1) l_updated_by,.

    NVL (FND_GLOBAL. Login_Id,-1) l_last_update_login

    OF MTH_TAG_READINGS_T_STG

    WHERE DB_COL =: 1) TS

    WE (';)

    v_stmt: = v_stmt | "ED. EQUIPMENT_PK_KEY = TS. EQUIPMENT_FK_KEY AND

    ED. READ_TIME = TS. READ_TIME AND

    ED. ATTR_GROUP_ID = TS. ATTR_GROUP_ID)

    WHEN MATCHED THEN

    UPDATE

    GAME ED.'. v_colname |' = TS. TAG_DATA,

    ED. LAST_UPDATED_BY = 1, ";

    v_stmt: = v_stmt | "ED. LAST_UPDATE_LOGIN = TS.l_last_update_login

    WHEN NOT MATCHED THEN

    INSERT ('| v_colname |', EXTENSION_ID, EQUIPMENT_PK_KEY, WORKORDER_FK_KEY, SEGMENT_FK_KEY, SHIFT_WORKDAY_FK_KEY, HOUR_FK_KEY, ITEM_FK_KEY, READ_TIME, ATTR_GROUP_ID, LAST_UPDATE_DATE, LAST_UPDATED_BY,';)

    v_stmt: =.

    v_stmt | ("LAST_UPDATE_LOGIN, CREATED_BY, CREATION_DATE, RECIPE_NUM, RECIPE_VERSION)

    VALUES (TS. TAG_DATA, EGO_EXTFWK_S.NEXTVAL, TS. EQUIPMENT_FK_KEY, TS. WORKORDER_FK_KEY, TS. SEGMENT_FK_KEY, TS. SHIFT_WORKDAY_FK_KEY, TS. HOUR_FK_KEY, TS. ITEM_FK_KEY, TS. READ_TIME,';

    v_stmt: = v_stmt | "TS. ATTR_GROUP_ID,: 2, 1, TS.l_last_update_login, TS.l_updated_by,: 3, TS. RECIPE_NUM, TS. RECIPE_VERSION)';

    V_stmt EXECUTE IMMEDIATE

    With the HELP of v_colname,.

    SYSDATE,

    SYSDATE;

    SY.

  • How to get sql % number of dynamic sql code lines

    Hello

    In this procedure I'm inserting and updating using dynamic sql. Now I want to go back two more PARAMETERS, the parameter should be back the number of lines inserted and how updated by stmtas of UPDATE as well as an INSERT. I'm not able to do can help you on that?

    CREATE OR REPLACE PROCEDURE Sp_Array_Test( PV_TGT_NAME   IN  VARCHAR2,
                                               PV_SRC_NAME   IN  VARCHAR2,
                                               PV_PK_COLS    IN  VARCHAR2,
                                               PN_ERR_CD     OUT NUMBER,
                                               PN_ERR_MSG    OUT VARCHAR2)
    AS
    
    
    TYPE ARR_TAB IS TABLE OF VARCHAR2(4000) INDEX BY BINARY_INTEGER;
    
    
    --UTL_FP        UTL_FILE.FILE_TYPE;
    LV_AN_
    
    
    
    BLOCK   VARCHAR2(32767);
    LN_CUR        BINARY_INTEGER := DBMS_SQL.OPEN_CURSOR;
    LN_DESC       DBMS_SQL.DESC_TAB;
    LN_COL_CNT    PLS_INTEGER := 0;
    LV_SEL_UPD_STMT   VARCHAR2(4000);
    LV_SEL_INS_STMT   VARCHAR2(4000);
    ARR_INDX      NUMBER := 1;
    LV_DATA_TYPE  VARCHAR2(8);
    LN_FIND_FLAG  NUMBER := 0;
    LN_TAB        ARR_TAB;
    LV_COLS_ARR   ARR_TAB;
    LV_ERR_MSG    VARCHAR2(500);
    
    
    
    
    --PROCEDURE FILE_WRITE ( FH_IN     IN UTL_FILE.FILE_TYPE,
    --                STRING_IN IN VARCHAR2 ) IS
    --BEGIN
    --   UTL_FILE.PUT_LINE(FH_IN,STRING_IN);
    --   LV_AN_BLOCK := LV_AN_BLOCK||STRING_IN;
    --EXCEPTION
    --   WHEN OTHERS THEN
    --      RAISE;
    --END FILE_WRITE;
    
    
    
    
    BEGIN
    
    
    --   UTL_FP := UTL_FILE.FOPEN('TEST_DIR', 'TEST.sql', 'W');
    
    
        LV_SEL_UPD_STMT := 'SELECT A.'||REPLACE(PV_PK_COLS,',','||A.')||' PK_COLS , A.* , B.ROWID FROM '||PV_SRC_NAME||' A, '||PV_TGT_NAME||' B WHERE ';
    
    
        LV_SEL_INS_STMT := 'SELECT A.* FROM '||PV_SRC_NAME||' A WHERE NOT EXISTS (SELECT ''1'' FROM '||PV_TGT_NAME||' B WHERE ';
    
    
        LN_TAB(ARR_INDX) := 'DECLARE ';
        ARR_INDX := ARR_INDX + 1;
    
    
        LN_TAB(ARR_INDX) := 'CURSOR CUR_VIEW_UPD IS '||LV_SEL_UPD_STMT ;
        ARR_INDX := ARR_INDX + 1;
    
    
    
    
        SELECT SUBSTR(COLS,DECODE(RN,1,1,INSTR(COLS,',',1,RN-1)+1),DECODE(RN,1,INSTR(COLS,',',1,RN)-1,INSTR(COLS,',',1,RN)-INSTR(COLS,',',1,RN-1)-1))
    BULK COLLECT INTO LV_COLS_ARR
          FROM ( SELECT RN, PV_PK_COLS||',' COLS
                   FROM (SELECT ROWNUM RN
                           FROM ALL_OBJECTS
                          WHERE ROWNUM <= LENGTH(PV_PK_COLS)- LENGTH(REPLACE(PV_PK_COLS,','))+1)) ;
        FOR K IN 1 .. LV_COLS_ARR.COUNT LOOP
            LV_SEL_UPD_STMT     := LV_SEL_UPD_STMT||' A.'||LV_COLS_ARR(K)||' = ';
            LN_TAB(ARR_INDX) := ' A.'||LV_COLS_ARR(K)||' = ';
            LV_SEL_UPD_STMT     := LV_SEL_UPD_STMT||' B.'||LV_COLS_ARR(K) ||CASE WHEN K = LV_COLS_ARR.COUNT THEN NULL ELSE ' AND ' END;
            LN_TAB(ARR_INDX) := LN_TAB(ARR_INDX)||' B.'||LV_COLS_ARR(K) ||CASE WHEN K = LV_COLS_ARR.COUNT THEN ' ;' ELSE ' AND ' END;
            ARR_INDX := ARR_INDX + 1;
        END LOOP;
    
    
        LN_TAB(ARR_INDX) := 'CURSOR CUR_VIEW_INS IS '||LV_SEL_INS_STMT ;
        ARR_INDX := ARR_INDX + 1;
    
    
        FOR K IN 1 .. LV_COLS_ARR.COUNT LOOP
            LV_SEL_INS_STMT     := LV_SEL_INS_STMT||' A.'||LV_COLS_ARR(K)||' = ';
            LN_TAB(ARR_INDX) := ' A.'||LV_COLS_ARR(K)||' = ';
            LV_SEL_INS_STMT     := LV_SEL_INS_STMT||' B.'||LV_COLS_ARR(K) ||CASE WHEN K = LV_COLS_ARR.COUNT THEN NULL ELSE ' AND ' END;
            LN_TAB(ARR_INDX) := LN_TAB(ARR_INDX)||' B.'||LV_COLS_ARR(K) ||CASE WHEN K = LV_COLS_ARR.COUNT THEN ' );' ELSE ' AND ' END;
            ARR_INDX := ARR_INDX + 1;
        END LOOP;
    
    
    
    
        LV_ERR_MSG := 'WHILE PARSING SELECT STATEMENT -- '||LV_SEL_UPD_STMT;
        DBMS_SQL.PARSE(LN_CUR, LV_SEL_UPD_STMT, DBMS_SQL.NATIVE);
    
    
        LV_ERR_MSG := 'WHILE DESCRIBING SELECT STATEMENT -- '||LV_SEL_UPD_STMT;
        DBMS_SQL.DESCRIBE_COLUMNS(LN_CUR, LN_COL_CNT, LN_DESC);
    
    
    
    
    
    
       FOR i IN LN_DESC.FIRST .. LN_DESC.LAST LOOP
          IF LN_DESC(i).col_type = 2 THEN
             LV_DATA_TYPE := 'NUMBER';
          ELSIF LN_DESC(i).col_type = 12 THEN
             LV_DATA_TYPE := 'DATE';
          ELSE
             LV_DATA_TYPE := 'VARCHAR2';
          END IF;
           LN_TAB(ARR_INDX) := '   T_'||LN_DESC(i).col_name||' DBMS_SQL.'||LV_DATA_TYPE||'_TABLE;';
           ARR_INDX := ARR_INDX + 1;
       END LOOP;
    
    
    
    
    
    
        LN_TAB(ARR_INDX) := 'BEGIN ';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '   EXECUTE IMMEDIATE ''ALTER SESSION SET NLS_DATE_FORMAT = ''''DD-MON-YYYY HH24:MI:SS'''''';';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '   OPEN CUR_VIEW_UPD;';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '   LOOP';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '      FETCH CUR_VIEW_UPD BULK COLLECT INTO T_'||LN_DESC(LN_DESC.FIRST).col_name||',';
        ARR_INDX := ARR_INDX + 1;
        FOR i IN LN_DESC.FIRST + 1 .. LN_DESC.LAST - 1 LOOP
          LN_TAB(ARR_INDX) := '                        T_'||LN_DESC(i).col_name||',';
          ARR_INDX := ARR_INDX + 1;
        END LOOP;
       LN_TAB(ARR_INDX) := '                        T_'||LN_DESC(LN_DESC.LAST).col_name||' LIMIT 500 ;';
       ARR_INDX := ARR_INDX + 1;
       LN_TAB(ARR_INDX) := '     FORALL I IN 1 .. '||'T_'||LN_DESC(LN_DESC.LAST).col_name||'.COUNT ';
       ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '      UPDATE '||PV_TGT_NAME||' SET  ';
        ARR_INDX := ARR_INDX + 1;
        LN_FIND_FLAG := 0;
        FOR I IN LN_DESC.FIRST + 1 .. LN_DESC.LAST-1 LOOP
          FOR K IN 1 .. LV_COLS_ARR.COUNT LOOP
             LN_FIND_FLAG := 0;
             IF LN_DESC(I).COL_NAME = LV_COLS_ARR(K) THEN
                LN_FIND_FLAG := 1;
                EXIT;
             END IF;
          END LOOP;
          IF LN_FIND_FLAG = 0 THEN
            LN_TAB(ARR_INDX) := '                        '||LN_DESC(i).col_name||' = '||'T_'||LN_DESC(i).col_name||'(I)'||CASE WHEN I = LN_DESC.LAST-1 THEN ' WHERE ' ELSE ',' END;
            ARR_INDX := ARR_INDX + 1;
          END IF ;
        END LOOP;
    
    
       LN_TAB(ARR_INDX) := '                        ROWID = '||'T_'||LN_DESC(LN_DESC.LAST).col_name||'(I) ;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '      COMMIT;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '      EXIT WHEN CUR_VIEW_UPD%NOTFOUND;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '   END LOOP;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '   CLOSE CUR_VIEW_UPD;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '      COMMIT;';
       ARR_INDX := ARR_INDX + 1;
    
    
    
    
        LN_TAB(ARR_INDX) := '   OPEN CUR_VIEW_INS;';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '   LOOP';
        ARR_INDX := ARR_INDX + 1;
        LN_TAB(ARR_INDX) := '      FETCH CUR_VIEW_INS BULK COLLECT INTO T_'||LN_DESC(LN_DESC.FIRST+1).col_name||',';
        ARR_INDX := ARR_INDX + 1;
        FOR i IN LN_DESC.FIRST + 2 .. LN_DESC.LAST - 2 LOOP
          LN_TAB(ARR_INDX) := '                        T_'||LN_DESC(i).col_name||',';
          ARR_INDX := ARR_INDX + 1;
        END LOOP;
       LN_TAB(ARR_INDX) := '                        T_'||LN_DESC(LN_DESC.LAST-1).col_name||' LIMIT 500 ;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '     FORALL J IN 1 .. '||'T_'||LN_DESC(LN_DESC.FIRST + 1).col_name||'.COUNT ';
       ARR_INDX := ARR_INDX + 1;
       LN_TAB(ARR_INDX) := '     INSERT INTO '||PV_TGT_NAME||' (';
       ARR_INDX := ARR_INDX + 1;
        FOR i IN LN_DESC.FIRST + 1 .. LN_DESC.LAST - 1 LOOP
          LN_TAB(ARR_INDX) := '                        '||LN_DESC(i).col_name||CASE WHEN I = LN_DESC.LAST - 1  THEN ' )' ELSE ',' END ;
          ARR_INDX := ARR_INDX + 1;
        END LOOP;
        FOR i IN LN_DESC.FIRST + 1 .. LN_DESC.LAST - 1 LOOP
          LN_TAB(ARR_INDX) := CASE WHEN I = LN_DESC.FIRST + 1 THEN 'VALUES (' ELSE NULL END ||'                        T_'||LN_DESC(i).col_name||'(J)'||CASE WHEN I = LN_DESC.LAST - 1  THEN ' ) ;' ELSE ',' END ;
          ARR_INDX := ARR_INDX + 1;
        END LOOP;
    
    
       LN_TAB(ARR_INDX) := '      COMMIT;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '      EXIT WHEN CUR_VIEW_INS%NOTFOUND;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '   END LOOP;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '   CLOSE CUR_VIEW_INS;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := '      COMMIT;';
       ARR_INDX := ARR_INDX + 1;
    
    
       LN_TAB(ARR_INDX) := 'END ;';
       ARR_INDX := ARR_INDX + 1;
    
    
    
    
       FOR J IN 1 .. LN_TAB.COUNT LOOP
    --     DBMS_OUTPUT.PUT_LINE( LN_TAB(J));
    --     FILE_WRITE(UTL_FP,LN_TAB(J));
         LV_AN_BLOCK := LV_AN_BLOCK||LN_TAB(J);
       END LOOP;
    
    
    --   UTL_FILE.FCLOSE(UTL_FP);
    
    
       EXECUTE IMMEDIATE LV_AN_BLOCK;
    
    
    PN_ERR_CD    := 0;
    PN_ERR_MSG   := 'Successful Completion';
    
    
    EXCEPTION
    WHEN OTHERS THEN
    PN_ERR_CD    := SQLCODE;
    PN_ERR_MSG   := LV_ERR_MSG||' -- '||SQLERRM ;
    END;
    /
    

    Thank you all for your answers. I agree with you all. I have manged this time by adding variable bind, then run it immediately ON aid. I don't know how it's going to be training.

    From now on my side no problem I don't thank you.

  • Create table form another table in different schema throwing error when dynamic sql

    Hello

    With the help of 11.2.0.3 and was following the issue.

    To create a table in a schema (b) using data from another schema (b)

    If independent run in sqlplus create works OK but same sql in dynamic sql block saying the table or view does not exist.

    SQL even in dynamic sql

    {code}

    v_sql: =' create table new_table in select * from schemab.table_name where...';

    run immediately (v_sql);

    [code}

    Other tables work fine.

    Any ideas - don't want to grant all the schemaa.table schema b if can avoid.

    Thank you

    You run the immediate execution in an anonymous block or a stored procedure?  If it is a stored procedure, then as others have said, the owner of the procedure must have select privileges on granted directly schemab.table_name.

    Another possibility, which would be the case for a stored procedure, or an anonymous block is that your code is something like:

    v_sql: =' create table new_table in select * from schemab.table_name where...';

    immediately run v_sql;

    Select count (*) in the l_count new_table;

    who will fail at compile time because new_table does not exist.

    When you create objects using dynamic sqly you dynamic sql user to reference them in the block of code.

    John

  • Dynamic SQL in APEX

    Hey everyone, I'm trying to understand how to use dynamic sql statements in Application Express. Specifically, I'm trying to write a query using substitution/bind variables. I don't know if you need a description of the application or not, but here's the query that will run in sqlplus:
    ACCEPT     file_id     PROMPT     "Enter the file_id (a number, e.g. 3): "
     
    -- Preliminary Query, to set table_name
     
    COLUMN     reference_id_col     NEW_VALUE     reference_id
    COLUMN     table_name_col     NEW_VALUE     table_name
     
    SELECT  f.reference_id          AS reference_id_col
    ,           t.reference_table       AS table_name_col
    FROM      aa_files     f
    JOIN     aa_type     t     ON     f.file_type     = t.type_id
    WHERE     f.file_id     = &file_id
    ;
     
    --     Main Query
     
    SELECT  * 
    FROM     &table_name
    WHERE      reference_id     = &reference_id
    ;
    There are three substitution variables, reference_id & file_id and & table_name. My basic setup is that I have a table full of table names, so I ask her to get a table name in a variable, then query this table for my data.

    I work inside the window of SQL commands to try to find the proper syntax to make this work in the APEX. I'm pretty sure that APEX does not allow the use of substitution variables, because they are one thing on the side of client SQL more right?

    I'm still a student, so I'm not known and Oracle Application Express, but reading the documentation of the APEX and the Googling, I tell myself that bind variable should be able to do this for me, but I don't know how. I searched for some examples or documentation on the use of dynamic SQL statements in the APEX, but I could not find anything. I'm sure I could do this using a PL/SQL block, but I'd rather do it in pure SQL if possible.

    So if someone could help me or giving me an example of syntax I would have to use to write a query that is running in Application Express, or could direct me to the literature on the use of dynamic sql statements in Application Express, it would be greatly appreciated!

    If you need more information on my application, I can post my create table statements and some inserts sample data, if that would be helpful.

    Thank you!

    Published by: username, June 21, 2010 07:34

    OK, so one of the great things about SQL is your ability to choose what columns you want to include in your result set. You don't have to use all of them. You can do this in two ways: with dynamic SQL or individual areas for each type of file. This will depend on your use as to how many types different files will be added each day on which you want to go with.

    If you go with dynamic SQL (and because you don't know until run time what columns you want to use, it is an appropriate use), you will need to build your query based on the file type. Something like this:

    declare
      qry_type  VARCHAR2(10);
      sql_qry    VARCHAR2(4000);
      qry_select  VARCHAR2(500);
      qry_from   VARCHAR2(100);
      qry_where  VARCHAR2(400);
      qry_order   VARCHAR2(100);
    begin
      qry_type  :=  :PX_QRY_TYPE;
      --Build the SELECT clause
      qry_select   := 'select a.FILE_NAME, a.FILE_NAME, a.FILE_TYPE, a.LOCATION';
      CASE qry_type
         WHEN 'PDF' THEN qry_select   := qry_select || ', pdf.DATE_MODIFIED, pdf.SUMMARY, pdf.AUTHOR';
         WHEN 'XLS' THEN qry_select   := qry_select || ', xls.DATE_MODIFIED, xls.SUMMARY, xls.TOTAL_VALUE';
         ...
      END CASE;
      --Build the FROM clause
      qry_from    := ' from AA_FILE a, AA_FILETYPE_PDF pdf, AA_FILETYPE_XLS xls, AA_FILETYPE_PHOTO p';
      --Build the WHERE clause
      qry_where  := ' where a.FILE_ID = pdf.FILE_ID (+)';
      qry_where  := qry_where || ' and a.FILE_ID = xls.FILE_ID (+)';
      qry_where  := qry_where || ' and a.FILE_ID = p.FILE_ID (+)';
      --Build the ORDER BY clause
      qry_order  := '';
      --Put it all together
      sql_qry   := qry_select || qry_from || qry_where || qry_order;
      EXECUTE IMMEDIATE sql_qry;
      ...
    end;
    

    Now this does not cover the addition of new file types. I still think you're going to be better off planning for as much as you can and handle manually creating additional tables, but this is going to be to you. I know you are trying to generate code to do everything for you, but when it comes to databases, I found that the creation of objects can quickly become uncontrolled if you're not very careful. These are going to be permanent, not temporary memory built database objects. Just a word of warning.

    If you decide to go with a region and by file type, it does not require nearly as much work. Simply create a report region based on the view and set the conditional display based on your file type.

      select * from V_FILES_PHOTO
       where FILE_ID = :PX_FILE_ID;
    
    condition:  FILE_TYPE = 'PDF'
    

    While you will need to add a region again every time that you add a new file type, once again, the question that arises is: file types how are you really going to have to worry? If you're talking about a dozen, I would like to do things manually. If you're talking about a hundred, it's maybe worth trying to find a method of programming. It is your call to make.

  • Dynamic SQL in PL/SQL process

    Hi all

    I just found out THAT dynamic SQL does not work in the process of PL/SQL.

    example of work using SQL:
    declare
    number of retval;
    Start
    Select count (*) retval emp;
    : P1_EMP_COUNT: = retval;
    end;

    Example usage of SQL dynamic works DO NOT:
    declare
    number of retval;
    l_sql varchar2 (4000);
    Start
    l_sql: = ' select count (*) in retval from emp;
    immediately run l_sql;
    : P1_EMP_COUNT: = retval;
    end;

    What have I done wrong? Could someone please help? :)

    Chris

    Try this modified code

    ....
    begin
    l_sql := 'select count(*)  from emp';
    execute immediate l_sql into :P1_EMP_COUNT ;
    end;
    ...
    

    CITY

  • problem using dynamic sql

    Hi all

    I have to insert the record in a table in one database to another database which requires db_link.so to do this I use run immediately, but when I try to insert by using the procedure below it will directly itno exception block.
    Help, please



    declare
    p_study_to NUMBER: = 1;
    p_study_from NUMBER: = 3;
    P_db_link VARCHAR2 (30): = 'abc ';
    BEGIN

    RUN IMMEDIATELY ' INSERT INTO RRRRR
    (study_to, db_link, dt_created, dt_modified, modified_by)'
    ||' SELECT study_to, db_link, dt_created,
    dt_modified, modified_by
    OF UUUU@:2'
    using p_study_to, p_db_link;
    EXCEPTION
    WHILE OTHERS
    THEN
    dbms_output.put_line ('error when inserting in RRRRR');
    END;
    /


    Thanks in advance!

    Hello

    You can tell only AID like this to give values for expressions, not table names (or their qualifications, as in this case).
    Try:

    declare
         p_study_to     NUMBER := 1;
         p_study_from      NUMBER := 3;
         P_db_link      VARCHAR2(30) := 'abc';
         sql_txt          VARCHAR2 (2000);
    BEGIN
    
         sql_txt := 'INSERT INTO     RRRRR (study_to, db_link, dt_created, dt_modified, modified_by)'
              ||           ' SELECT  study_to, db_link, dt_created, dt_modified, modified_by'
              ||          ' FROM    UUUU@' || p_db_link ;
         dbms_output.put_line (sql_txt);
    
            -- EXECUTE IMMEDIATE  sql_txt;
    END;
    

    Whenever you write dynamic sql code, it displays first.
    Only when it shows something that looks right should you UN-comment the EXECUTE IMMEDIATE statement.
    Before you go into Production, comment out code (or delete) the call to put_line.

    Use an EXCEPTION handler only when you can improve on what is the mechanism of error by default, for example, you plan a particular error, and you have something specail do when this error occurs.

    Using dynamic SQL just to have the same code running on different databases, where each database needs a different connection name? If so, use synonyms instead of dynamic SQL.

  • 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;

  • Works with dynamic sql and list of numbers as return value

    Hello.

    Problems:

    1. How can I insert the USERNAME variable in the string so it will be replaced over time.
    2. I intend to return a list of IDS as 1,4,6,7,2 I want to use later in an IN clause.

    How to complete the return function with the dynamic sql output variable?
    I have no preference to dynamic sql but it was just something that came into my mind
    When I thought that the implementation of the obligation to choose a list of offices for specific user groups.
    (select statements from the sample are cut short, they're actually really big and I want to reuse this function in my)
    BI Publisher data model for multiple modells).


    CREATE or REPLACE FUNCTION F_OFFICES (-input parameters)
    USERNAME IN VARCHAR2
    USERGROUP IN VARCHAR2,
    )
    -Output parameter
    RETURN VARCHAR2 AS
    dynSQL VARCHAR2 (1000);
    BEGIN

    IF USERGROUP = "local" THEN

    dynSQL: = 'xxx SELECT FROM CO_B WHERE Userid = username';

    ELSIF USERGROUP = "regional" THEN

    dynSQL: = "SELECT...". » ;

    ELSIF USERGROUP 'federal' = THEN
    dynSQL: = "SELECT...". » ;

    END IF;

    EXECUTE IMMEDIATE dynSQL;

    -RETURN?;

    END F_OFFICES;


    Thanks for any help.

    As you have presented essentially pseudo-code we can only give you a Pseudo-solution :)

    But the principle is:

    ...
    --Output parameter
    RETURN VARCHAR2 AS
        dynSQL VARCHAR2(1000);
        return_value varchar2(30):
    BEGIN
    
      IF USERGROUP = 'local' THEN
        dynSQL:= 'SELECT xxx FROM CO_B WHERE userid = :1'; -- placeholder for parameter
    
       ...
      END IF;
    
      EXECUTE IMMEDIATE dynSQL
         using USERNAME -- pass parameters in placeholder order
         into return_value;   -- obviously this must match the projection of the dynamic query 
    
      RETURN return_value; 
    
    END F_OFFICES ;
    

    This approach is not good if you want to vary the dynamic query projection. In this case, you can use a REF CURSOR or maybe DBMS_SQL.

    Cheers, APC

Maybe you are looking for

  • Load on the C50-A538 Satellite control

    Hello I have laptop Satellite C50-A538 and I search far stop angrrr when he charged 100% and when he is 20% start automatic load THX

  • Crash on startup Satellite L500-128

    Hello Sometimes, when I start my Satellite L500, I experience a blue screen that says that the laptop restarts automatically to avoid damaging the material. It's coming fast, so I can't read all the text in the message. After auto restarts, the start

  • Question about my audio

    Hello I suddenly had a problem with my audio. I don't get anything. I hope that I've not deleted a file is somehow, I've been tempting to listen to a desperate football the other night. The volume is on and I have real player installed. Now I have un

  • Satellite Pro L100 PSLA4: ATI graphics card crashing in half-life 2, Team Fortress 2

    Hello I have a satellite Pro L100 (PSLA4) with ATI Radeon Xpress 200 M graphics card. During the game Team Fortress 2 and Half Life 2 Episode 2, the system breaks down frequently (screen goes black, then blue, then the computer automatically resets).

  • How to enable Intel Pro Wireless 2200 satellite A30-514

    I recently sent my laptop away for repair and they put a card Intell Pro Wireless 2200 in my laptop but I don't know how to turn it on. I flicked the switch on the side, but no light appearing and FN + F8 it does not turn on either.He made his appear