Dynamic SQL in Form Builder 6.0

Hai,
I would like to know how to create Dynamic SQL in Form Builder 6.0. I'am using oracle 9i database...Please help me.....

I studied the EXEC_SQL and i wrote these syntax(below), but it gives me error...Could you help me please......:
PROCEDURE Dynamic_sql IS
connection_id EXEC_SQL.CONNTYPE;
cursorID EXEC_SQL.CURSTYPE;
sql_string VARCHAR2(1000);
v_pc varchar2 (4);
v_pd varchar2 (30);
v_poc varchar2(4);
v_pvd DATE;
v_pid DATE;
exec_id PLS_INTEGER;
out_file TEXT_IO.FILE_TYPE;
linebuf varchar2(7000);
vchFileName VARCHAR2(100);
Vchfolder VARCHAR2(100);
AppID      PLS_INTEGER;
nmbAlert          varchar2(50);
BEGIN
SET_APPLICATION_PROPERTY(CURSOR_STYLE,'BUSY');
vchFileName := 'dynamic_sql_'||sysdate||'.txt';
Vchfolder := 'D:\KONS\Damar\';
host('mkdir '||Vchfolder,NO_SCREEN);
out_file := text_io.fopen(vchfolder||vchFileName,'w');
TEXT_IO.PUT_LINE (out_file,'PRODUCT CODE PRODUCT DESC PRODUCT OBJECT CODE PRODUCT VALID DATE PRODUCT INVALID DATE ');
connection_id := EXEC_SQL.OPEN_CONNECTION('FIFDBA/F1FDBA@REPL_DAILY');
cursorID := EXEC_SQL.OPEN_CURSOR(connection_id);
sql_string := 'SELECT PROD_CODE, PROD_DESC, PROD_OBJT_CODE, PROD_VALID_DATE, PROD_INVALID_DATE
FROM HOUS_PRODUCT_TYPE ';
EXEC_SQL.PARSE(connection_id, cursorID, sql_string, exec_sql.V7);
--EXEC_SQL.BIND_VARIABLE(connection_id, cursorID, '', input_empno);
EXEC_SQL.DEFINE_COLUMN(connection_id, cursorID, 1,v_pc, 4);
EXEC_SQL.DEFINE_COLUMN(connection_id, cursorID, 2, v_pd, 30);
EXEC_SQL.DEFINE_COLUMN(connection_id, cursorID, 3, v_poc, 4);
EXEC_SQL.DEFINE_COLUMN(connection_id, cursorID, 4, v_pvd);
EXEC_SQL.DEFINE_COLUMN(connection_id, cursorID, 5, v_pid);
exec_id := EXEC_SQL.EXECUTE(connection_id, cursorID);
WHILE (EXEC_SQL.FETCH_ROWS(connection_id, cursorID) > 0 ) LOOP
EXEC_SQL.COLUMN_VALUE(connection_id, cursorID, 1, v_pc, 4);
EXEC_SQL.COLUMN_VALUE(connection_id, cursorID, 2, v_pd);
EXEC_SQL.COLUMN_VALUE(connection_id, cursorID, 3, v_poc);
EXEC_SQL.COLUMN_VALUE(connection_id, cursorID, 4, v_pvd);
EXEC_SQL.COLUMN_VALUE(connection_id, cursorID, 5, v_pid);
TEXT_IO.PUT_LINE(out_file,v_pc || v_pd ||v_poc||v_pvd||v_pid);
--Forms_DDL('INSERT INTO TEMP VALUES('||''''||nRows||' '||v_state_id||''''||')');
--COMMIT_FORM();
END LOOP;
EXEC_SQL.CLOSE_CURSOR(connection_id, cursorID);
EXEC_SQL.CLOSE_CONNECTION(connection_id);
SET_APPLICATION_PROPERTY(CURSOR_STYLE,'DEFAULT');
TEXT_IO.FCLOSE(out_FILE);

Similar Messages

  • Dynamic SQL in Forms

    I' d like to use dynamic SQL in Form, but i'm attacking a access database(ODBC OCA).
    Is there any way to do that?
    Thanks.
    null

    SEE ALL EXAMPLES
    =============
    Example 1
    ** Built-in: FORMS_DDL
    ** Example: The expression can be a string literal.
    BEGIN
    Forms_DDL('create table temp(n NUMBER)');
    IF NOT Form_Success THEN
    Message ('Table Creation Failed');
    ELSE
    Message ('Table Created');
    END IF;
    END;
    Example 2
    ** Built-in: FORMS_DDL
    ** Example: The string can be an expression or variable.
    ** Create a table with n Number columns.
    ** TEMP(COL1, COL2, ..., COLn).
    PROCEDURE Create_N_Column_Number_Table (n NUMBER) IS
    my_stmt VARCHAR2(2000);
    BEGIN
    my_stmt := 'create table tmp(COL1 NUMBER';
    FOR I in 2..N LOOP
    my_stmt := my_stmt| |',COL'| |TO_CHAR(i)| |' NUMBER';
    END LOOP;
    my_stmt := my_stmt| |')';
    ** Now, create the table...
    Forms_DDL(my_stmt);
    IF NOT Form_Success THEN
    Message ('Table Creation Failed');
    ELSE
    Message ('Table Created');
    END IF;
    END;
    Example 3:
    ** Built-in: FORMS_DDL
    ** Example: The statement parameter can be a block
    ** of dynamically created PL/SQL code.
    DECLARE
    procname VARCHAR2(30);
    BEGIN
    IF :global.flag = 'TRUE' THEN
    procname := 'Assign_New_Employer';
    ELSE
    procname := 'Update_New_Employer';
    END IF;
    Forms_DDL('Begin '| | procname | |'; End;');
    IF NOT Form_Success THEN
    Message ('Employee Maintenance Failed');
    ELSE
    Message ('Employee Maintenance Successful');
    END IF;
    END;
    Example 4:
    ** Built-in: FORMS_DDL
    ** Example: Issue the SQL statement passed in as an argument,
    ** and return a number representing the outcome of
    ** executing the SQL statement.
    ** A result of zero represents success.
    FUNCTION Do_Sql (stmt VARCHAR2, check_for_locks BOOLEAN := TRUE)
    RETURN NUMBER
    IS
    SQL_SUCCESS CONSTANT NUMBER := 0;
    BEGIN
    IF stmt IS NULL THEN
    Message ('DO_SQL: Passed a null statement.');
    RETURN SQL_SUCCESS;
    END IF;
    IF Check_For_Locks AND :System.Form_Status = 'CHANGED' THEN
    Message ('DO_SQL: Form has outstanding locks pending.');
    RETURN SQL_SUCCESS;
    END IF;
    Forms_DDL(stmt);
    IF Form_Success THEN
    RETURN SQL_SUCCESS;
    ELSE
    RETURN Dbms_Error_Code;
    END IF;
    END;

  • Using Dynamic SQL in Forms

    Does anyone know anything about Dynamic SQL not being available in Forms v. 6.0.8.11.3? I trying to use Dynamic SQL for the first time and am having some difficulty. When I try to put my SQL in a function and run it straight into the database through SQLPlus, it works fine, but when trying to compile the code in Forms Builder (in a library), I get compiler errors. Any help would be appreciated...
    Thanks!
    Vanessa

    When I tried to compile the following code in Forms, the compiler error I got was Encountered the symbol "STMT_STR" when expecting one of the following: select. However, when I run it in SQLPlus, it creates the function without any errors.
    FUNCTION my_func
    return number
    is
    TYPE DiaryCurTyp IS REF CURSOR;
    cur DiaryCurTyp;
    stmt_str VARCHAR2(200);
    dmonth NUMBER;
    dday NUMBER;
    BEGIN
    stmt_str := 'SELECT dmonth, dday FROM p2_diary
    WHERE dmonth = :1';
    OPEN cur FOR stmt_str USING '12';
    LOOP
    FETCH cur INTO dmonth, dday;
    EXIT WHEN cur%NOTFOUND;
    -- <process data>
    END LOOP;
    CLOSE cur;
    END;

  • Using database link  with a dynamic SQL in Forms 5

    I have a Form 5 application where a database link is specified in a client version of dynamic SQL. The function that the application is designed to perform is to access data in a table in a remote database and use it to populate another table in a local database with the same structure as the source table. Dynamic SQL is used because the name of the table can only be resolved during run time.
    The problem is that it gives error with code 'ORA-03113' and text 'End-of-file on communication channel' when you try to run it.
    Is it not possible to use a database link with a dynamic SQL? What can I do to overcome the problem ?

    Try to create a local view based ao the remote table and use the view.

  • Problem with dynamic query in Forms Builder

    Hi,
    I need in forms builder cursor in procedure which parameter is a whole query. But i stuck when i wanna give some text in signs '' to procedure.
    I wanna give like test('select ' ||'test' || ' from dual');
    But this is not good beacuse it is missing ''.
    Query which procedure get is select test from dual.
    The right sql would be select 'test' from dual.
    How could i pass signs '' to procedure.
    Any ideas.
    Thanks in advance.

    test('select ''' ||'test' || ''' from dual');Francois

  • Using Native Dynamic SQL in Forms

    Can Native Dynamic SQL be used in Forms 5.0 or Forms 6.0? (Database 8.1.6.0.0)
    I have tried the following code (examples below) from the PL/SQL User's Guide and Reference Release 8.1.6 and the Metalinks Note: 62592.1 and the trigger/procedure (in Forms) will not compile. I appreciate any help given.
    Example1:
    (I have a table named temp_jane with a column named companies and a value 'Hello'. When compiling, I receive the error: 'Error 103 at line 8, column 11 Encountered the symbol ''IMMEDIATE" when expecting one of the following :=.(@%; ')
    declare
    str varchar2( 200 );
    val varchar2( 20 );
    ret temp_jane%rowtype;
    begin
    str := 'select company from temp_jane where company = :b1';
    val := 'Hello';
    execute immediate str into ret using val;
    message('Value fetched from table: '&#0124; &#0124;ret.company);
    end;
    Example2:
    (Here is the real issue, I don't know what the select statement, so I need to be able to assign a variable. When compiling, I receive the error: 'Error 103 at line 28, column 21 Encountered the symbol "VSQLSTATEMENT" when expecting one of the following: select ').
    declare
    type ItemsControlCurTyp is ref cursor;
    ItemsCur ItemsControlCurTyp;
    ItemsRec Items%rowtype;
    vSQLStatement varchar2( 5000 );
    vExecuteSQL varchar2( 5000 );
    vNumRows integer;
    vValue varchar2( 2000 );
    vFirstOne varchar2( 1 ) := 'Y';
    vRetval varchar2( 2000 );
    begin
    -- Display the column prompts with the right text.
    set_item_property( 'ITEMS_AVAILABLE.NDB_VALUE', PROMPT_TEXT, :ITEMS_CONTROL.AVAILABLE_LABEL );
    set_item_property( 'ITEMS_CHOSEN.NDB_VALUE', PROMPT_TEXT, :ITEMS_CONTROL.CHOSEN_LABEL );
    -- Save the original version of CHOSEN_STRING in case the user reverts or cancels.
    :ITEMS_CONTROL.CHOSEN_STRING_ORIG := :ITEMS_CONTROL.CHOSEN_STRING;
    vSQLStatement := :ITEMS_CONTROL.SELECT_STATEMENT;
    vExecuteSQL := vSQLStatement;
    -- Open the cursor
    open ItemsCur for vSQLStatement;

    Hi JTaylor
    You cannot use NDS in Client side (Developer). You have to use DBMS_SQL only.
    Regards
    A K Srinivasan
    Oracle.

  • Creating dynamic LOV in form builder 6i

    Hi All,
    I am new to form builder.
    I want to create dynamic lov, means
    Project type
    Client
    Work_type(thsi is also lov) ->> 1) Billable
    Reason (this is also lov) ->> 1) Billable
    Work_type(thsi is also lov) ->> 2) Non-Billable
    Reason (this is also lov) ->> 1) Fresher
    2) Project Manager
    As shown above, Suppose the project type is client then I will select either "Billable" or "Non-Billable" value.
    If I am selecting Work_type LOV as "Billable" then it should display "Billable" value in reason LOV
    or if I am selecting Non-Billable value from Work_type LOV then reason LOV will display the list of value as Fresher and Project Manager.
    Please help me, its very urgent.
    Thanks in advance.
    Regards,
    Bluetooth

    Bluetooth,
    This can be accomplished by creating two seperate record groups; one for Billable and one for Non-Billable. Then - in the WORK_TYPE When-Validate-Item (WVI)trigger - when the value is "Billable" you assign the Billable Record Group to your LOV or if the value is Non-Billable, then you assign the Non-Billable record group to your LOV. Your Record Group queries must return the same number of columns and the column names must match. If your record groups need to have a different number of columns and column names, then I would just use two seperate LOV's and assign them to the item accordingly. For example:
    /* Sample WVI trigger */
    DECLARE
      lov_id    LOV;
      item_id   ITEM;
    BEGIN
      lov_id := Find_LOV('YOUR_LOV_NAME');
      /* Option 1: Change Record Group of LOV */
      IF ( :YOUR_BLOCK.WORK_TYPE = 'BILLABLE' ) THEN
        IF ( Get_LOV_Property(lov_id, GROUP_NAME) != 'BILLABLE_RG' ) THEN
          Set_LOV_Property(lov_id, GROUP_NAME, 'BILLABLE_RG');
        END IF;
      ELSIF ( :YOUR_BLOCK.WORK_TYPE = 'NONBILLABLE' ) THEN
        IF ( Get_LOV_Property(lov_id, GROUP_NAME) != 'NONBILLABLE_RG' ) THEN
          Set_LOV_Property(lov_id, GROUP_NAME, 'NONBILLABLE_RG');
        END IF;
      END IF;
      item_id := Find_Item('YOUR_BLOCK.REASON');
      /* Option 2: Seperate LOV's */
      IF ( :YOUR_BLOCK.WORK_TYPE = 'BILLABLE' ) THEN
        IF ( Get_Item_Property(item_id, LOV_NAME) != 'BILLABLE_LOV' ) THEN
          Set_Item_Property(item_id, LOV_NAME, 'BILLABLE_LOV');
        END IF;
      ELSIF ( :YOUR_BLOCK.WORK_TYPE = 'NONBILLABLE' ) THEN
        IF ( Get_Item_Property(item_id, LOV_NAME) != 'NONBILLABLE_LOV' ) THEN
          Set_Item_Property(item_id, LOV_NAME, 'NONBILLABLE_LOV');
        END IF;
      END IF;Hope this helps,
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.

  • How to execute dynamic sql in forms 6i?

    Cursor_Handle     Integer     := DBMS_SQL.OPEN_CURSOR;
         Out_Put          Integer;
    BEGIN
         DBMS_SQL.PARSE(Cursor_Handle, Sql_Stmt , dbms_sql.v7);
         Out_Put := DBMS_SQL.EXECUTE(Cursor_Handle);
         DBMS_SQL.CLOSE_CURSOR(Cursor_Handle);
    return true;
    END;
    this is the procedure i have used. it works fine in server side but not in client side. pls help me to solve this problem.
    Advance tanx

    The reason your process won't compile is that you are using a package variable, dbms_sql.v7. (Why aren't you using dbms_sql.native?) If you change that variable to a value of 1 it will probably work.
    However, Francois is correct -- In Forms, you should be using the Exec_SQL package. It is built for Forms; Oracle does not support using DBMS_SQL from Forms. In fact, if you use Forms Builder 10g connected to Oracle 9i and try to compile, the compiler fails with internal errors. They say it works again if you connect to Oracle 10.
    Exec_SQL is identical to DBMS_SQL, except for exception handling. You have to make an additional call to catch the error if an exception occurs: Exec_SQL.Last_Error_Code

  • Dynamic SQL an Form values in formatted Search

    Hi all,
    Can I create Dynamically the where clause of a query (for a Formatted Search) finding that into a UDF of another table, and then store all in a Varchar(300) variable and use that variable as parameter of an EXEC?
    Sorry for my bad explanation, it takes less time attach the query ...
    so here it is:
    declare  @pol as varchar(8)
    set @pol = $[ORDR.U_PolProj]
    declare @internal_q NVARCHAR(300)
    select  @internal_q = T0.U_CondPol
    from [@PRG_CEN_POL_PROJ] T0
    where Code = @pol
    declare  @itcode as varchar(100)
    set @itcode = $[RDR1.ItemCode]
    declare @sql NVARCHAR(300)
    select @sql = 'select  result =  count(ItemCode)
    from OITM T0
    where T0.ItemCode = ''' + @itcode +
    ''' and ' + @internal_q
    exec(@sql)
    Could someone tell me what's wrong with this formatted search?

    resolved!!! It works

  • Help w/ dynamic sql in form based on proc.

    First, I'm not the most brilliant at this so I might be missing something basic.
    I have a form based off a stored procedure. In that procedure, I have an update statement that is built dynamically from session variables. It won't work because I am putting the update statement together from variables. How can I get around this?
    example:
    Here is the problematic code in my procedure:
    update my_schema.my_table_synonym
    set
    v_myfield = v_myvar
    where myid = v_myid;
    I am pulling the variables from session storage I created earlier in the application. It doesn't seem to like that the field is a variable... is there a way to do this? I would prefer to use this in my application dozens of times rather than copy it dozens of times with slight changes.

    ok, nevermind... I figured my problem out.
    All I needed was something like this:
    v_sql := 'update mytable set ' || myfield || ' = ''HELLO';
    EXECUTE IMMEDIATE v_sql;

  • Dynamic images in Form Builder?

    Any idea about including images dynamically?
    An example: how to print a form with the photo of the involved employee?
    Images could be available via http...
    Thanks a lot

    1. I've a requirement to display dynamic image in a Adobe form.
    Could you please let me know how this can be done?
    2. When I click on UPL field it says I need to create a connection to the
    http://<app server>:8005/sap/bc/fp/.
    How do I create this connection?
    3. I don't have access to any documentatuin on designing Adobe form except the on-line help from the designer. Can you please suggest where can I get documentation about designing Adobe forms?

  • Question about Find and Replace PL/SQL option in Forms Builder

    Dear All
    I have a small question .
    I am using Find and Replace PLSQ/SQL in forms Builder ( Edit - Find and Replace PLSQL) to search any code in a form.
    Let say I am searching for EMP .
    Then all the places is coming where EMP is used as well as EMPloyee , EMPloyee_Desc tables also coming .
    So is there any way to serach only the EMP part .

    If you look closely to the right of the "Find What" field, you should see a button - "Expression". This allows you to add some logic to your search. Alternatively, depending on how you code, you could just look for spaces. For example, if you are looking for EMP and not EMPLOYEE, search for EMP with a blank space before and after it (assuming you code this way) or use something like this \bEMP\b This would work for me because I code the same way I write sentences - each work is separated by spaces.
    <blockquote> EMPLOYEE := EMP || ' - ID';</blockquote>
    In this example, seaching for EMP with a blank space after would find what I wanted. However, if you only search for a trailing blank, you may end up also finding words like tEMP. This is where have a blank space before each word is helpful.
    Other, more valuable expressions could be written to accomplish your task. Refer to the Forms Builder Online help for more information about using Expressions in the Find and Replace search window.

  • How can I execute Dynamic SQL statement in Forms?

    Hi All,
    I have to execute dynamic SQL statement from Forms
    Below statement I have to execute
    "EXECUTE IMMEDIATE v_stmt INTO v_return;".
    Googled for the same got results saying, Better use Database function or procedures to execute these Dynamic Statements but We want to execute in forms only.
    Can any one help me..
    Thanks,
    Madhu

    So in short you are trading code obfuscation for maintainability and the ability to share code between tools? If from somewhere else you need a procedure already implemented in database PL/SQL (and now ported to forms) this would mean you'd need to implement it in every other tool. In times where you might want to integrate your forms with $other_technology and putting stuff on the database is the first step to share functionality you just go the opposite way? And all that because someone is afraid that somebody might steal your source code? I am sorry to be blunt, but this is just plain stupid.
    Leaving aside that some things like Analytic Functions, Bulk processing or execute immediate are not even available in forms your software consists of how many LOC? How long does it take to bring a new developer up to speed with your source code? Imagine how long that would take for a developer who doesn't have coleagues who know their way around.
    And just so you know: I work for a ISV selling a closed-source product as well. We have 200+ customers all over the planet. We are well aware that wrapped packages can be reverse engineered. The premise is: stored procedures can be reused in every tool we have, if it makes sense to put stuff on the database by all means do it. If someone would want to reverse engineer our software I'd wish him good luck as some parts are implemented in such a hilarious complicated way I have troubles understanding them (and quite frankly I refuse to understand certain parts, but that's another story). I do work for almost 10 years for that ISV.
    In any case the possible solutions have already been mentioned: you have exec_sql, create_group_from_query and forms_ddl to execute dynamic SQL in forms whereas forms_ddl is a one way street and most certainly not the thing you need or want. Take a look at the documentation for the other 2 things.
    cheers

  • PL/SQL & Form Builder

    Hey
    I used Oracle 8i when i was at uni to develop databases using PL/SQL and Form Builder. I was able to purchase Oracle 9i a few years so that i could practice my developing skills. Now i do not know what has happened to the Oracle 9i i bought, probably got misplaced when i moved house.
    Does anyone know where i can purchase it from or download it from?
    I need PL/SQL to program and create my tables and Form Builder to have the front end to link to my tables.
    Any help would be most appreciated.
    Kind Regards
    Zak

    You can download them free for your own non-commercial purposes.
    Forms & Reports Developer 10g:
    http://www.oracle.com/technology/software/products/ids/index.html
    Oracle Database 10g:
    http://www.oracle.com/technology/software/products/database/oracle10g/index.html
    Express Edition will probably do fine (this is also free for commercial use), though you could use Enterprise Edition if you prefer ($$ for a commercial licence but free to mess around with at home).

  • Solve this Dynamic sql problem

    hi i am sending the table and the contents in the table and what i want from the table.
    SQL> descr sswms_rule_components;
    Name Null? Type
    RULE_COMPONENT_ID NOT NULL NUMBER
    RULE_COMPONENT_CODE NOT NULL VARCHAR2(30)
    RULE_COMPONENT_NAME NOT NULL VARCHAR2(100)
    ENABLED_FLAG NOT NULL VARCHAR2(1)
    DB_TABLE VARCHAR2 (100)
    DB_COLUMN VARCHAR2 (100)
    DB_FUNCTION VARCHAR2(100)
    WHERE_CLAUSE VARCHAR2 (2000)
    FROM_CLAUSE VARCHAR2 (2000)
    The table contains the following data
    db_table
    sswms_shipment_lines
    wsh_carrier_ship_method --- the data inside the db_table column is a table
    db_column
    Ship to
    Carrier_id
    Where_clause
    Oe_order_headers_all.header_id = sswms_shipment_lines.order_header_id
    From_clause
    Oe_order_headers_all, sswms_shipment_lines -- the data inside the From_clause is a table
    Now my requirement is to build a dynamic sql in forms 6i.when I click the build sql it should update the sql
    So --- I have to write a procedure --
    Select db_table || . || db_column || ‘’ || group_key
    ---group_key is an alias
    From db_table, From_clause
    --- Here the logic should be
    1. I should remove the commas from the “FROM_CLAUSE” column and check for duplicate values
    2. i should check for duplicate values for the “DB_TABLE “ column
    3. I should compare both the FROM_CLAUSE and DB_TABLE column for DUPLICATE VALUES
    4. After doing this I should add the result to the “FROM” in the select statement
    5.The table name should not be repeated from the "FROM"
    I am expecting the code and a positive reply from you.

    I'm waiting for the code the last 10 minutes and none arrived. What's happening? Developers, do my work, please! (ironic sentence)

Maybe you are looking for