A question about input values inside PL/SQL block

Dear all,
I would appreciate if you could kindly help me with this question.
Consider the following code.
DECLARE
  myvar1 NUMBER;
  myvar2 NUMBER;
  myvar3 NUMBER;
BEGIN
  myvar1 := &1;
  myvar2 := &2;
  myvar3 := &3;
  DBMS_OUTPUT.put_line('myvar1 = ' || myvar1);
  DBMS_OUTPUT.put_line('myvar2 = ' || myvar2);
  DBMS_OUTPUT.put_line('myvar3 = ' || myvar3);
END;
/This program reads three values as input and prints them. However, I noticed that if instead of writing
myvar1 := &1;
myvar2 := &2;
myvar3 := &3;I write
myvar1 := '&1';
myvar2 := '&2';
myvar3 := '&3';The program will have very same result. I would like to know whether there is a semantic difference between both syntax,
that is, is there any difference between for example &myvar1 and 'myvar1'?
Thanks in advance,
Dariyoosh

Try this
CREATE TABLE test_sem  (x VARCHAR2(10), y NUMBER)
INSERT INTO test_sem VALUES ('A',1);
INSERT INTO test_sem VALUES ('B',1);
INSERT INTO test_sem VALUES ('C',1);
INSERT INTO test_sem VALUES ('D',1);
SELECT * FROM test_sem WHERE x='&1' --OK
SELECT * FROM test_sem WHERE x=&1 -- error not a valid number
SELECT * FROM test_sem WHERE y=&1 -- ok
SELECT * FROM test_sem WHERE y='&1' -- ok since numbers can be converted to strings'&1' is for characters &1 for numbers;
You can verify form above test case
Regards,
Bhushan

Similar Messages

  • How can i pass the Input value to the sql file in the korn shell ??

    Hi,
    How can i pass the Input value to the sql file in the korn shell ??
    I have to pass the 4 different values to the sql file and each time i pass the value it has to generate the txt file for that value like wise it has to generate the 4 files at each run.
    can any one help me out.
    Raja

    Can you please more elaberate., perhaps you should more elaberate.
    sqlplus is a program. you start it from the korn shell. when it's finished, processing control returns to the korn shell. the korn shell and sqlplus do not communicate back and forth.
    so "spool the output from .sql file to some txt file from k shell, while passing the input parameters to the sql file from korn shell" makes no sense.

  • Question about inputting data to a pivot table

    Hi,
    I have 2 questions about using the ADF pivot table component (I would like it for data input).
    1. Is it possible to paste into multiple cells (i.e. using cut in Excel for example, and then pasting the cells into the pivot table) ?
    2. What is the recommended approach for the case where there is no data values (no rows on the database table)? For example, if I have regions, products, measures and time periods and then want to be able to select some regions and some products to enter new sales figures - and then create the rows on the database with save button, is there a recommended way to do this?
    (Jdeveloper version: 11.1.2.0.0)

    Anybody able to help with this?

  • Question about changing values of a total by selecting a check box.

    OK, so what I did was create a form for my workplace that totals the value an employee's quality of work. what i want this form to do is: In one cell the total is a 100 point value. In one column i have a markable checkbox and in the column next to that there is a point value for that particular category. what i want is to be able to check a box next to category and have the corresponding point value deducted from the "100" total. for example if I check the box next a value of 40, then the 100 becomes a 60 automatically. I am new to numbers, and any spreadsheet app for that matter so any help would be greatly appreciated.

    Tommyboy29 wrote:
    Another question about my last post: numbers will only let me add 2 to 3 cells in the formula to change the "total" number of 100. is there a way to add more then 3 cells? i have 9 cells total that i want to have the ability to subtract from that same total?
    There is no such limit in Numbers. I'm guessing that you ran out of room in the formula edit line in the Formula Bar.
    Grab the double line and pull it down to expand the edit area.
    Jerry

  • DDL inside PL/SQL Block

    Is there anyone knows if DDL statement can be include inside the PL/SQL block?
    I mean, creating a table, doing DML in that table and then dropping it? I have to do this because I'm having integrity constraint errors (ORA-02291) in the tables I will use.
    I need to
    update table_1 set id = 2 where id = 1
    but it it found child records in table_2.
    when i tried:
    update table_2 set id = 2 where id = 1
    Of course I cannot as well update table_2 because it will not found parent record in table_1, as it had an error earlier and there were more records in table_1 than table_2.
    table_1 records = 374 rows
    table_2 records = 38 rows
    I did some strange logic below:
    a. Creating a temporary table,
    b. inserting there records in table_1,
    c. updating the temp table,
    d. delete the records i got in table_1,
    e. update table_2 (can now do an update since no child records in table_1 will be found after the delete),
    f. insert records from temp table to table_1
    g. drop the temp table.
    BUT, I cannot create, manipulate, and drop that temp table inside the PL/SQL table.
    Any thoughts.
    Thanks in advance!

    Another scenario is to create your constraints as deferred. I'v recently blogged about another deferred constraint usage here
    http://gplivna.blogspot.com/2007/05/deferred-constraint-real-life-scenario.html
    but your case also is appropriate.
    But the ultimate problem BTW is that you need to update your PK values and that's at least very questionable (ok to my mind bad) design.
    Gints Plivna
    http://www.gplivna.eu

  • Bind Variable in SELECT statement and get the value  in PL/SQL block

    Hi All,
    I would like  pass bind variable in SELECT statement and get the value of the column in Dynamic SQL
    Please seee below
    I want to get the below value
    Expected result:
    select  distinct empno ,pr.dept   from emp pr, dept ps where   ps.dept like '%IT'  and pr.empno =100
    100, HR
    select  distinct ename ,pr.dept   from emp pr, dept ps where   ps.dept like '%IT'  and pr.empno =100
    TEST, HR
    select  distinct loc ,pr.dept   from emp pr, dept ps where   ps.dept like '%IT'  and pr.empno =100
    NYC, HR
    Using the below block I am getting column names only not the value of the column. I need to pass that value(TEST,NYC..) into l_col_val variable
    Please suggest
    ----- TABLE LIST
    CREATE TABLE EMP(
    EMPNO NUMBER,
    ENAME VARCHAR2(255),
    DEPT VARCHAR2(255),
    LOC    VARCHAR2(255)
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (100,'TEST','HR','NYC');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (200,'TEST1','IT','NYC');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (300,'TEST2','MR','NYC');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (400,'TEST3','HR','DTR');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (500,'TEST4','HR','DAL');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (600,'TEST5','IT','ATL');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (700,'TEST6','IT','BOS');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (800,'TEST7','HR','NYC');
    COMMIT;
    CREATE TABLE COLUMNAMES(
    COLUMNAME VARCHAR2(255)
    INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('EMPNO');
    INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('ENAME');
    INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('DEPT');
    INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('LOC');
    COMMIT;
    CREATE TABLE DEPT(
    DEPT VARCHAR2(255),
    DNAME VARCHAR2(255)
    INSERT INTO DEPT(DEPT,DNAME) VALUES ('IT','INFORMATION TECH');
    INSERT INTO DEPT(DEPT,DNAME) VALUES ('HR','HUMAN RESOURCE');
    INSERT INTO DEPT(DEPT,DNAME) VALUES ('MR','MARKETING');
    INSERT INTO DEPT(DEPT,DNAME) VALUES ('IT','INFORMATION TECH');
    COMMIT;
    PL/SQL BLOCK
    DECLARE
      TYPE EMPCurTyp  IS REF CURSOR;
      v_EMP_cursor    EMPCurTyp;
      l_col_val           EMP.ENAME%type;
      l_ENAME_val       EMP.ENAME%type;
    l_col_ddl varchar2(4000);
    l_col_name varchar2(60);
    l_tab_name varchar2(60);
    l_empno number ;
    b_l_col_name VARCHAR2(255);
    b_l_empno NUMBER;
    begin
    for rec00 in (
    select EMPNO aa from  EMP
    loop
    l_empno := rec00.aa;
    for rec in (select COLUMNAME as column_name  from  columnames
    loop
    l_col_name := rec.column_name;
    begin
      l_col_val :=null;
       l_col_ddl := 'select  distinct :b_l_col_name ,pr.dept ' ||'  from emp pr, dept ps where   ps.dept like ''%IT'' '||' and pr.empno =:b_l_empno';
       dbms_output.put_line('DDL ...'||l_col_ddl);
       OPEN v_EMP_cursor FOR l_col_ddl USING l_col_name, l_empno;
    LOOP
        l_col_val :=null;
        FETCH v_EMP_cursor INTO l_col_val,l_ename_val;
        EXIT WHEN v_EMP_cursor%NOTFOUND;
          dbms_output.put_line('l_col_name='||l_col_name ||'  empno ='||l_empno);
       END LOOP;
    CLOSE v_EMP_cursor;
    END;
    END LOOP;
    END LOOP;
    END;

    user1758353 wrote:
    Thanks Billy, Would you be able to suggest any other faster method to load the data into table. Thanks,
    As Mark responded - it all depends on the actual data to load, structure and source/origin. On my busiest database, I am loading on average 30,000 rows every second from data in external files.
    However, the data structures are just that - structured. Logical.
    Having a data structure with 100's of fields (columns in a SQL table), raise all kinds of questions about how sane that structure is, and what impact it will have on a physical data model implementation.
    There is a gross misunderstanding by many when it comes to performance and scalability. The prime factor that determines performance is not how well you code, what tools/language you use, the h/w your c ode runs on, or anything like that. The prime factor that determines perform is the design of the data model - as it determines the complexity/ease to use the data model, and the amount of I/O (the slowest of all db operations) needed to effectively use the data model.

  • No Data Found: Exception in SQL inside PL/SQL block

    Hi Friends
    I am trying to execute an SQL SELECT stmt inside a PL/SQL block. But when i execute the procedure, it gives me No Data Found Exception.
    I know it is because no row is fetched in the query, but the condition of the SELECT query i have specified is being satisfied, i have checked it by running it on the SQL prompt.
    But somehow, it is not running from inside the PL/SQL procedure.Can anybody help me out on this as to why is this happening?? I am giving my code for reference and have Highlighted the Query inside it:
    CREATE OR REPLACE procedure insert_sfdc_account
    as
    --DECLARE
    CURSOR C1 IS
    SELECT customer_code, name1, name2, name3, name4, phone_number, fax, web_address, industry_sector, customer_profile, customer_type,
    address, city, postal_code, country_key, zzcust_type, vat_code
    FROM load_cust_general
    WHERE account_group = 'ZSIT';
    v_cust_cur c1%ROWTYPE;
    -- type sales_tab is table of load_cust_sales_area%rowtype;
    v_sales_area load_cust_sales_area%ROWTYPE;
    -- v_sales_area sales_tab;
         v_salesorg varchar2(10);
         v_sales_district varchar2(10);
         v_salesoff varchar2(10);
         v_custgrp varchar2(10);
         v_salesgrp varchar2(10);
    v_type varchar2(20);
    v_nature varchar2(10);
    v_partner_code varchar2(10);
    v_parent_cust varchar2(20);
    v_credit_blk varchar2(20);
    BEGIN
    open c1;
    loop
    fetch c1 into v_cust_cur;
    exit when c1%NOTFOUND;
    for i in (SELECT customer_code, salesorg from load_cust_partner
    where customer_code = v_cust_cur.customer_code ) LOOP
    dbms_output.put_line(v_cust_cur.customer_code );
                        SELECT partner_code into v_partner_code from load_cust_partner
    where customer_code = i.customer_code and salesorg = i.salesorg and partner_function = 'Z1';
    dbms_output.put_line(v_partner_code||i.customer_code);
    SELECT salesorg, sales_district, salesoff, salesgrp, custgrp INTO v_salesorg, v_sales_district, v_salesoff, v_salesgrp, v_custgrp FROM load_cust_sales_area
              WHERE customer_code = i.customer_code and salesorg = i.salesorg;
                   dbms_output.put_line(v_salesorg||i.salesorg);
                        SELECT parent_customer INTO v_parent_cust from load_cust_hierarchy
    WHERE customer_code = i.customer_code and salesorg = i.salesorg and hierarchy_type = 'G'; dbms_output.put_line(v_parent_cust);
                        SELECT credit_block INTO v_credit_blk from load_cust_company_cod
              WHERE customer_code = i.customer_code;
    dbms_output.put_line(v_credit_blk);
    for j in (SELECT account_group, customer_type from load_cust_general
    where customer_code IN (select customer_code from load_cust_partner
                                  where partner_code = i.customer_code and salesorg = i.salesorg and partner_function = 'ZS'))
                                                      LOOP
    -- exit when j%NOTFOUND;
         dbms_output.put_line(j.account_group);
    if (j.account_group = 'ZDIS') THEN
    v_type := 'DISAC';
              v_nature := '06';
         --     EXIT ;
    else
    v_type := 'SPACC';
    v_nature := '01';
    END IF;
    dbms_output.put_line(v_type||' '||v_nature);
    END LOOP;
    INSERT INTO sfdc_account
              (SAP_ACCOUNT_ID__C, NAME, TYPE, RECORDTYPEID, PARENTID, PHONE, FAX, WEBSITE, OWNERID, MARKETING_DOMAIN__C,
    INDUSTRIAL_SECTOR__C, ABC_CLASSIFICATION__C, NAME_1__C, NAME_2__C, NAME_3__C, NAME_4__C, PAYMENT_STATUS__C,
    CUSTOMER_GROUP__C, ADDRESS_STREET__C, CITY__C, POSTAL_CODE__C, COUNTRY__C, SALES_OFFICE__C, SALESORG__C,
    SALESDISTRICT__C, SALESGROUP__C, NATURE__C, VATCODE__C)
    VALUES((i.customer_code||i.salesorg), (v_cust_cur.Name1||' '||v_cust_cur.name2), ' ', v_type, v_parent_cust,
    v_cust_cur.phone_number, v_cust_cur.fax, v_cust_cur.web_address, v_partner_code, SUBSTR(v_cust_cur.industry_sector,1,2),
    v_cust_cur.industry_sector, v_cust_cur.customer_profile, v_cust_cur.name1, v_cust_cur.name2, v_cust_cur.name3,
    v_cust_cur.name4, v_credit_blk, v_custgrp, v_cust_cur.address, v_cust_cur.city, v_cust_cur.postal_code,
    v_cust_cur.country_key, v_salesoff, v_salesorg, v_sales_district,
    v_salesgrp, v_nature, v_cust_cur.vat_code);
    end loop;
    end loop;
    CLOSE c1;
    -- Delete data from Load Table
    -- EXECUTE IMMEDIATE 'TRUNCATE TABLE load_cust_general';
    /* truncate table load_cust_partner;
    truncate table load_cust_hierarhy;
    truncate table load_cust_sales_area;
    truncate table load_cust_company_cod;
    commit;
    exception
    when others then
    raise_application_error( -20001, substr( sqlerrm, 1, 150 ) );
    END;
    Kindly Help.....
    Thanks and Regards

    Create the procedure again and execute it in SQL*Plus environment and paste the output:
    CREATE OR REPLACE procedure insert_sfdc_account
    as
    --DECLARE
    CURSOR C1 IS
    SELECT customer_code, name1, name2, name3, name4, phone_number, fax, web_address, industry_sector, customer_profile, customer_type,
    address, city, postal_code, country_key, zzcust_type, vat_code
    FROM load_cust_general
    WHERE account_group = 'ZSIT';
    v_cust_cur c1%ROWTYPE;
    -- type sales_tab is table of load_cust_sales_area%rowtype;
    v_sales_area load_cust_sales_area%ROWTYPE;
    -- v_sales_area sales_tab;
    v_salesorg varchar2(10);
    v_sales_district varchar2(10);
    v_salesoff varchar2(10);
    v_custgrp varchar2(10);
    v_salesgrp varchar2(10);
    v_type varchar2(20);
    v_nature varchar2(10);
    v_partner_code varchar2(10);
    v_parent_cust varchar2(20);
    v_credit_blk varchar2(20);
    BEGIN
    open c1;
    loop
    fetch c1 into v_cust_cur;
    exit when c1%NOTFOUND;
    for i in (SELECT customer_code, salesorg from load_cust_partner
    where customer_code = v_cust_cur.customer_code ) LOOP
    SELECT partner_code into v_partner_code from load_cust_partner
    where customer_code = i.customer_code and salesorg = i.salesorg and partner_function = 'Z1';
    SELECT salesorg, sales_district, salesoff, salesgrp, custgrp INTO v_salesorg, v_sales_district, v_salesoff, v_salesgrp, v_custgrp FROM load_cust_sales_area
    WHERE customer_code = i.customer_code and salesorg = i.salesorg;
    dbms_output.put_line('Customer_Code : '|| i.customer_code);
    dbms_output.put_line('SalesOrg : '|| i.salesorg);
    SELECT parent_customer INTO v_parent_cust from load_cust_hierarchy
    WHERE customer_code = i.customer_code and salesorg = i.salesorg and hierarchy_type = 'G';
    dbms_output.put_line('Successfully Executed SQL st. Error is somewhere else');
    SELECT credit_block INTO v_credit_blk from load_cust_company_cod
    WHERE customer_code = i.customer_code;
    for j in (SELECT account_group, customer_type from load_cust_general
    where customer_code IN (select customer_code from load_cust_partner
    where partner_code = i.customer_code and salesorg = i.salesorg and partner_function = 'ZS'))
    LOOP
    -- exit when j%NOTFOUND;
    if (j.account_group = 'ZDIS') THEN
    v_type := 'DISAC';
    v_nature := '06';
    -- EXIT ;
    else
    v_type := 'SPACC';
    v_nature := '01';
    END IF;
    END LOOP;
    INSERT INTO sfdc_account
    (SAP_ACCOUNT_ID__C, NAME, TYPE, RECORDTYPEID, PARENTID, PHONE, FAX, WEBSITE, OWNERID, MARKETING_DOMAIN__C,
    INDUSTRIAL_SECTOR__C, ABC_CLASSIFICATION__C, NAME_1__C, NAME_2__C, NAME_3__C, NAME_4__C, PAYMENT_STATUS__C,
    CUSTOMER_GROUP__C, ADDRESS_STREET__C, CITY__C, POSTAL_CODE__C, COUNTRY__C, SALES_OFFICE__C, SALESORG__C,
    SALESDISTRICT__C, SALESGROUP__C, NATURE__C, VATCODE__C)
    VALUES((i.customer_code||i.salesorg), (v_cust_cur.Name1||' '||v_cust_cur.name2), ' ', v_type, v_parent_cust,
    v_cust_cur.phone_number, v_cust_cur.fax, v_cust_cur.web_address, v_partner_code, SUBSTR(v_cust_cur.industry_sector,1,2),
    v_cust_cur.industry_sector, v_cust_cur.customer_profile, v_cust_cur.name1, v_cust_cur.name2, v_cust_cur.name3,
    v_cust_cur.name4, v_credit_blk, v_custgrp, v_cust_cur.address, v_cust_cur.city, v_cust_cur.postal_code,
    v_cust_cur.country_key, v_salesoff, v_salesorg, v_sales_district,
    v_salesgrp, v_nature, v_cust_cur.vat_code);
    end loop;
    end loop;
    CLOSE c1;
    -- Delete data from Load Table
    -- EXECUTE IMMEDIATE 'TRUNCATE TABLE load_cust_general';
    /* truncate table load_cust_partner;
    truncate table load_cust_hierarhy;
    truncate table load_cust_sales_area;
    truncate table load_cust_company_cod;
    commit;
    exception
    when others then
    raise_application_error( -20001, substr( sqlerrm, 1, 150 ) );
    END;
    SQL> set serveroutput on
    SQL> exec insert_sfdc_account;

  • Select query inside PL/SQL block.

    Hello Experts,
    I am just a beginner with PL/SQL.
    If I write a select query from client like SQL dev and fire it against a database, it gives me result.
    Eg: select * from employee;
    Now when I use the same Query inside a PL/SQL block suppose:
    Declare
    begin
    select * from employee;
    end;
    This gives error on execution, mentioning that an INTO is expected etc...
    I have doubts here:
    1. Can't I use a plain select inside a PL/SQL block (if so why?)
    I know this is kind of very basic question, I tried searching this on the forum but could not find the thread, please redirect me to the link if this is already answered.

    user8578271 wrote:
    Hello Experts,
    I am just a beginner with PL/SQL.
    If I write a select query from client like SQL dev and fire it against a database, it gives me result.
    Eg: select * from employee;
    Now when I use the same Query inside a PL/SQL block suppose:
    Declare
    begin
    select * from employee;
    end;
    This gives error on execution, mentioning that an INTO is expected etc...
    I have doubts here:
    1. Can't I use a plain select inside a PL/SQL block (if so why?) Because when you run a query in a tool like SQL Developer, or SQL*Plus or TOAD etc. then it opens up a cursor and fetches the data into internal memory structures before displaying it, and that is all done automatically and hidden from you. In PL/SQL, there is no interface to display the results of SQL queries, so you have to specifically tell it what to put the data into.
    The syntax is (in basic terms)...
    SELECT column1, column2... columnX
    INTO variables or record structure
    FROM ...Though that can only select a single row of data. If your query returns more than 1 row it will give a TOO_MANY_ROWS exception. If your query returns no rows you will get a NO_DATA_FOUND exception.
    If you need to select multiple rows into variables etc., then you would need to "BULK COLLECT" into a collection/array structure, though this takes up valuable memory on the server and shouldn't be used unless necessary (and you understand the implications of doing it).

  • My First while loop inside PL/SQL block not working , please help

    Hi ,
    I am new to PL/sql and struck at PL SQL blocks , please help to solve this .
    declare
    v_A number constant :=10 ;
    j number constant := 3 ;
    BEGIN
    WHILE j < v_A
    LOOP
    DBMS_OUTPUT.PUT_LINE('Hai');
    END LOOP;
    END;
    please help as how to resolve this .
    Thanks in advance .

    btw it's a useful habit to use indentation to highlight the block structure. Also it's worth deciding what your convention will be for keywords (I use uppercase, lowercase is also fine as far as I'm concerned but I've set up my editor to uppercase them) and variables, database object names etc (I use lowercase), e.g:
    DECLARE
       v_a CONSTANT PLS_INTEGER := 10;
       j   CONSTANT PLS_INTEGER := 3;
       i PLS_INTEGER := j;
    BEGIN
       WHILE i <= v_a LOOP
          DBMS_OUTPUT.PUT_LINE(i);
          i := i +1;
       END LOOP;
    END;or perhapsdeclare
       v_a constant pls_integer := 10;
       j   constant pls_integer := 3;
       i pls_integer := j;
    begin
       while i <= v_a loop
          dbms_output.put_line(i);
          i := i +1;
       end loop;
    end;When I see "declare" and "BEGIN" in the same block of code I worry about the standard of code I'm going to see...

  • FETCHING OUTPUT  VALUE FROM PL/SQL BLOCK

    hI aLL,
    I'm working on ODP.NET. I'm executing below pl/sql command. while executing this command in pl/sql it's showing the output which is an xml.
    declare
    xmloutput xmltype;
    xmldata varchar(32767);
    teid t_id := t_en_id( 'L','L',NULL,12121,'ABC','USER','N');
    tgetinfo to_info := NULL;
    RETVAL NUMBER;
    begin
    RETVAL := GET_DTLS(teid,tgetinfo);
    dbms_output.put_line(RETVAL);
    xmldata := tgetinfo.XML_info.getclobval();
    dbms_output.put_line(xmldata);
    end;
    I passed above command in string variable for passing in code. like below
    string StrQry = "";
    StrQry += "declare \n";
    StrQry += "xmloutput xmltype; \n";
    StrQry += "xmldata varchar(32767); \n";
    StrQry += "teid t_id := t_en_id( 'L','L',NULL,12121,'ABC','USER','N'); \n";
    StrQry += "tgetinfo to_info := NULL; \n";
    StrQry += "RETVAL NUMBER; \n";
    StrQry += "begin \n";
    StrQry += "RETVAL := GET_DTLS(teid,tgetinfo); \n";
    StrQry += "dbms_output.put_line(RETVAL); \n";
    StrQry += "xmldata := tgetinfo.XML_info.getclobval(); \n";
    StrQry += "dbms_output.put_line(xmldata); \n";
    StrQry += "end; \n";
    I'm passing output parameter ":temp" for this command. I want to catch output xml in ":temp" variable
    which is varchar2 type.
    Added below line before printing xmldata;
    StrQry += ":temp := xmldata; \n";
    cn.Open();
    OracleCommand cmd = new OracleCommand(StrQry, cn);
    cmd.Parameters.Add(":temp", OracleDbType.Varchar2, 32767, ParameterDirection.Output);
    cmd.ExecuteNonQuery();
    But which executing through c# code it's showing the below error.
    Oracle.DataAccess.Client.OracleException ORA-06502: PL/SQL: numeric or value err
    or: character string buffer too small
    ORA-06512: at line 11 at Oracle.DataAccess.Client.OracleException.HandleError
    Helper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOp
    oSqlValCtx, Object src, String procedure)
    at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, Oracle
    Connection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx
    , Object src)
    at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
    at orclGetDetails.Program.DoProcess()
    How can i get the output to output variable ":temp".
    Pls help.
    Ideas are appreciated.

    Your PL/SQL block isn't returning anything. DBMS_OUTPUT is, at best, a way of debugging code, not passing data around. Assuming you configure and enable an appropriately sized buffer, I suppose your ODP.Net application could make DBMS_OUTPUT.GET_LINE calls to retrieve the XML. But that's not not a way to design an application.
    If you want a PL/SQL block that returns XML, you'll need to create a function and have the function return the XML (you could also create a procedure with an OUT parameter in which you could return the XML).
    Justin

  • Questions about 1Z0-047 Oracle Database SQL Expert

    I am planning to take this exam and I have several questions:
    1) I am using Steve O'Hearn's 'SQL Certified Expert Exam Guide' book and this states the following about SQL functions:
    "Be sure to review the Oracle Database SQL Language Reference Manual and review the lengthy description of all of the SQL functions before taking the exam"
    In trial tests it seemed that book's information was enough, but how about real exam? Is it necessary to study something in addition to this book information? You can answer regarding other exam objectives as well, if there is something that I should read from some other materials.
    2) The book states that I can add not null constraint to column that has null values, if I specify default value. I tried and cannot, I get error. So the book states it wrongly or do I misunderstand something?
    3) The book states that I cannot drop a NOT NULL constraint, but I can get the job done using: ALTER TABLE table_name MODIFY column_name NULL;
    I tried and I can execute: alter table table_name drop constraint nameofnotnullconstraint;
    4) To use external tables, is only read grant on the directory necessary or also write?
    5) I understood from the book that to flashback table (e.g to before drop) I need to have row movement enabled on the table. But I tried and I can make this flashback operation to table that does not have row movement enabled. How can this be explained!
    Big thanks in advance!

    #1) well, the manual is free; find here the SQL Language Reference - http://www.oracle.com/pls/db112/portal.all_books#index-SQL
    #2 & 3) If you proved it yourself, that settles it!
    #4) Here's a good article about external tables: http://www.oracle-developer.net/display.php?id=512
    I noted this paragraph in it, which might answer your question:
    In addition to the standard read-write Oracle directory that we need for our external table, we also need an additional executable directory object for the preprocessor. This directory defines the location of the executables used by the preprocessor (we will be using gzip below). As far as Oracle is concerned, an executable directory is one that has EXECUTE privileges granted on it (this is an 11g feature specifically to support the preprocessor).
    #5) don't know

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

  • Question about error-handling in PL/SQL

    Hi friends,
    I would like to know if there is a way for error handling for insert and update statements in PL/SQL???
    Like when for example an insert fails!
    thanxx
    Schoeib

    You should get a book about such fundamentals!
    This is not an online course...
    begin
      insert into emp values(...);
    exception
      when no_data_found then
      when others then
    end;

  • Question about setting column width in SQL*Plus using info retrieved w SQL

    Good morning,
    Is there a way to tell SQL*Plus to set the width of a column to the greatest width of the elements found in the column ? (as opposed to the default which is the width declared in the DDL)
    In other words, I'd like to do something functionally equivalent to this:
    COL <columname> format a[select max(length(<columnname>)) from <thetablethatcontainscolumname>]
    I'm doing the above manually in two steps
    1. select max(length(columnname)) from .....
    2. col columnname format a[resultofstep1]
    Is there a way of doing it in one step ?
    Thank you for your help,
    John.

    Hi Munky,
    >
    you should consider whther you are using the correct tool for the job, SQLplus isn't exactly ideal for doing presentation layer stuff
    >
    I'm not really doing presentation stuff, I asked because it would be very convenient for everyday stuff. I commonly query the tables that I am going to deal withm just to have a look at the column names and a few values, something like:
    select * from EMP where rownum <= 10; -- just to have a look at the table and some values
    when the table contains a wide column then the display gets all messed up. It would be nice to have an option or a mechanism to tell SQL*Plus to automatically use the width of the widest value, instead of having to determine the value and then manually set the column.
    thank you for your help, it's good to know that I didn't miss some trivial setting in the documentation that would do it ;)
    John.

  • Question about Table Function inside a Package

    Hi … I am new in PL/SQL, I am trying to use a table function to create depending on a value passed to it (I am using 10g). Everything works great but the moment I add a parameter everything explode, I am creating it on a package.
    SQL that work
    CREATE OR REPLACE PACKAGE BODY financial_reports AS
    FUNCTION Fund_Amount
    RETURN financial_reports.Fund_Amount_Table
    pipelined parallel_enable IS
    cur_row financial_reports.Fund_Amount_Record;
    BEGIN
    FOR cur_row IN
    SELECT
    to_number(substr(bu5.usrdata, 1, 1)) As SECTION_ID
    ,to_number(substr(bu5.usrdata, 2, 1)) As SUB_SECTION_ID
    ,to_number(substr(bu5.usrdata, 4, 2)) AS LINE_NUMBER
    ,to_number(substr(bu5.usrdata, 7, 2)) As FUND_ID
    ,sum(be.amt) AS AMOUNT
    FROM
    linc.budgetdb_usr5@stjohnsfp bu5
    JOIN linc.budgetdb_event@stjohnsfp be ON
    bu5.keyvalue = be.acctno
    WHERE
    bu5.keyvalue like '__-__-__-____-____-_____'
    AND bu5.usrdata like '__-__-__'
    AND bu5.fieldnum = 1
    AND bu5.ispecname = 'GLMST'
    AND to_number(substr(bu5.usrdata, 7, 2)) = 1
    GROUP BY
    bu5.usrdata
    ORDER BY
    bu5.usrdata
    LOOP
    PIPE ROW(cur_row);
    END LOOP;
    END Fund_Amount;
    END financial_reports;
    SQL that do not work …
    CREATE OR REPLACE PACKAGE BODY financial_reports AS
    FUNCTION Fund_Amount (Fund_Id IN NUMBER)
    RETURN financial_reports.Fund_Amount_Table
    pipelined parallel_enable IS
    cur_row financial_reports.Fund_Amount_Record;
    fund_id_int NUMBER;
    BEGIN
    fund_id_int := Fund_Id;
    FOR cur_row IN
    SELECT
    to_number(substr(bu5.usrdata, 1, 1)) As SECTION_ID
    ,to_number(substr(bu5.usrdata, 2, 1)) As SUB_SECTION_ID
    ,to_number(substr(bu5.usrdata, 4, 2)) AS LINE_NUMBER
    ,to_number(substr(bu5.usrdata, 7, 2)) As FUND_ID
    ,sum(be.amt) AS AMOUNT
    FROM
    linc.budgetdb_usr5@stjohnsfp bu5
    JOIN linc.budgetdb_event@stjohnsfp be ON
    bu5.keyvalue = be.acctno
    WHERE
    bu5.keyvalue like '__-__-__-____-____-_____'
    AND bu5.usrdata like '__-__-__'
    AND bu5.fieldnum = 1
    AND bu5.ispecname = 'GLMST'
    AND to_number(substr(bu5.usrdata, 7, 2)) = fund_id_int
    GROUP BY
    bu5.usrdata
    ORDER BY
    bu5.usrdata
    LOOP
    PIPE ROW(cur_row);
    END LOOP;
    END Fund_Amount;
    END financial_reports;
    Error … (This works without the parameter)
    Error starting at line 43 in command:
    select * from table(financial_reports.Fund_Amount(1) )
    Error at Command Line:1 Column:14
    Error report:
    SQL Error: ORA-22905: cannot access rows from a non-nested table item
    Any help would be greatly appreciated

    try renaming your parameter so as not to confuse with what you are using in your column " to_number(substr(bu5.usrdata, 7, 2)) AS FUND_ID":
    CREATE OR REPLACE PACKAGE BODY financial_reports AS
      FUNCTION Fund_Amount (pFund_Id IN NUMBER)
        RETURN financial_reports.Fund_Amount_Table
        pipelined parallel_enable IS
        cur_row financial_reports.Fund_Amount_Record;
        fund_id_int NUMBER;
      BEGIN
        fund_id_int := pFund_Id;
        FOR cur_row IN ( SELECT to_number(substr(bu5.usrdata, 1, 1)) As SECTION_ID,
                                to_number(substr(bu5.usrdata, 2, 1)) As SUB_SECTION_ID,
                                to_number(substr(bu5.usrdata, 4, 2)) AS LINE_NUMBER,
                                to_number(substr(bu5.usrdata, 7, 2)) As FUND_ID,
                                sum(be.amt) AS AMOUNT
                           FROM linc.budgetdb_usr5@stjohnsfp bu5
                                  JOIN linc.budgetdb_event@stjohnsfp be ON bu5.keyvalue = be.acctno
                          WHERE bu5.keyvalue like '__-__-__-____-____-_____'
                            AND bu5.usrdata like '__-__-__'
                            AND bu5.fieldnum = 1
                            AND bu5.ispecname = 'GLMST'
                            AND to_number(substr(bu5.usrdata, 7, 2)) = fund_id_int
                         GROUP BY bu5.usrdata
                         ORDER BY bu5.usrdata ) LOOP
          PIPE ROW(cur_row);
        END LOOP;
      END Fund_Amount;
    END financial_reports;

Maybe you are looking for