0

I've created an anonymous PLSQL block to test and I'm running into an issue with the formatting.

set serveroutput ON

BEGIN
  FOR I IN (SELECT DISTINCT do.SUBOBJECT_NAME from dba_objects do WHERE do.object_name='MY_TABLE' AND do.OBJECT_TYPE='TABLE PARTITION') LOOP
    dbms_output.put_line(I.subobject_name);

    SELECT
      t.field
    INTO
        some_var
    FROM
      MY_TABLE PARTITION(I.subobject_name) t;

  END LOOP;
END;

However I get several compilation errors, which I believe are related to the fact that I.subobject_name is a string. I believe the PARTITION function wants an actual partition symbol(proper term for this?), but I can't give it in this loop.

Is there any kind of casting function that can perform what I'm looking for?

1
  • Maybe use an execute immediate statement instead? Jun 21, 2014 at 18:55

1 Answer 1

2
  1. Partition IS NOT A FUNCTION. Partition is keyword
  2. In your context your whole statement is static , thus you CANNOT pass partition name into it; partition name must be specified at compile time.
  3. You can re-create your statement dynamically and then pass partition name in the loop - a-la you are doing it. Just make sure you will concatenate string and not use bind variables, or your statement at run time won't be parsed and won't run.

Name for the symbol is table partition

1
  • Thanks for the lessons. Sorry, my PL/SQL is rusty on the naming. I ended up just doing a dynamic string and executing it via EXECUTE IMMEDIATE.
    – Nicholas
    Jun 21, 2014 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.